Skip to content

Conversation

@GSmithApps
Copy link
Contributor

What was changed

Added a custom metric sample

Why?

Help folks with questions about custom metrics

Checklist

  1. How was this tested:
    Checked the metric output against the existing metric

  2. Any docs updates needed?
    Updated main python samples readme

@GSmithApps
Copy link
Contributor Author

GSmithApps commented Apr 18, 2025

This is failing on the black formatter, but I formatted and sorted the imports

@GSmithApps GSmithApps requested a review from Copilot April 18, 2025 14:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a custom metric sample to demonstrate how to record the workflow type in the activity schedule-to-start latency.

  • Added a new workflow (ExecuteActivityWorkflow) and associated client code for executing activities.
  • Introduced a custom activity interceptor to record custom metrics in the activity worker.
  • Updated README files to include instructions for running the custom metric components.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
custom_metric/workflow_worker.py Introduces a simple workflow that executes an activity.
custom_metric/client.py Provides a client to start the new workflow.
custom_metric/activity_worker.py Implements an interceptor for recording custom metrics for activity timing.
custom_metric/README.md Updates sample usage instructions for the custom metric sample.
README.md Adds the custom_metric sample to the main project documentation.

@GSmithApps GSmithApps requested review from cretz and dandavison April 18, 2025 14:27
)


class SimpleWorkerInterceptor(Interceptor):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sample is not just demonstrating custom metric, which can be done inside the activity, it's demonstrating interceptors. May be a little confusing to someone just wanting to understand the custom metric part.

Copy link
Contributor Author

@GSmithApps GSmithApps Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! I implemented it because what you mentioned off-PR, I thought you suggested to do this with an interceptor

Copy link
Member

@cretz cretz Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this specific custom metric that makes sense, but people can create custom metrics without interceptors. I think it's fine to stay, may just need to clarify in README via that one/two-sentence explainer that the purpose of this sample is to demonstrate a custom schedule to start metric via interceptor, as opposed to just general custom metric.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a little blurb. I hope it's along the lines you're thinking

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test or two? (I know not all samples have tests, something we regret, but adding them helps us catch if they start breaking)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added!

@GSmithApps
Copy link
Contributor Author

@cretz thanks for the review! I think all your comments have been acknowledged and fixed

Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just minor stuff. Only thing really needed I think is to give the workflow its own file. Don't forget to poe format.

Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@cretz cretz merged commit 0fecc6e into temporalio:main Apr 21, 2025
10 checks passed
@GSmithApps GSmithApps deleted the custom_metric branch April 22, 2025 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants