Skip to content

feat(worker): Custom Metrics #1705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025
Merged

feat(worker): Custom Metrics #1705

merged 1 commit into from
May 21, 2025

Conversation

mjameswh
Copy link
Contributor

@mjameswh mjameswh commented May 6, 2025

What was changed

Example usage:

From a workflow

import * as wf from `@temporalio/workflow`;

async function myWorkflow() {
  const myHistogramMetric = wf.metricMeter.createHistogram(
    'my-custom-histogram',
    'int', // or 'float'
    'ms', // Units (optional)
    'description' // (optional)
  );

  myHistogramMetric.record(50);
  myHistogramMetric.record(50, { tag1: 'tag-value' });
}

From an activity

import * as act from `@temporalio/activity`

const myCounterMetric = metricMeter.createCounter('activity-counter');

async function myActivity() {
  const myCounterMetric.add(1);
}

@mjameswh mjameswh changed the title feat(worker): Custom Metrics [DRAFT] feat(worker): Custom Metrics May 6, 2025
@mjameswh mjameswh force-pushed the emit-metrics-from-lang branch from 33af2ea to 4eba51d Compare May 16, 2025 21:01
@mjameswh mjameswh force-pushed the emit-metrics-from-lang branch from 4eba51d to 8271248 Compare May 16, 2025 21:07
@mjameswh mjameswh marked this pull request as ready for review May 16, 2025 21:07
@mjameswh mjameswh requested a review from a team as a code owner May 16, 2025 21:07
@mjameswh mjameswh changed the title [DRAFT] feat(worker): Custom Metrics feat(worker): Custom Metrics May 16, 2025
Copy link
Member

@Sushisource Sushisource left a comment

Choose a reason for hiding this comment

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

Looks really clean & thorough. I didn't do an incredibly close analysis, but overall it looks great and the tests have excellent coverage.

*
* @param tags Tags to append to existing tags.
*/
withTags(tags: MetricTags): MetricCounter;
Copy link
Member

Choose a reason for hiding this comment

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

Why not put withTags on Metric?

Copy link
Contributor Author

@mjameswh mjameswh May 18, 2025

Choose a reason for hiding this comment

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

What would be the return type of that function if defined on the parent class? Unfortunately, TS doesn't have anything like the Self type.

@mjameswh mjameswh merged commit 1bcb339 into main May 21, 2025
25 of 27 checks passed
@mjameswh mjameswh deleted the emit-metrics-from-lang branch May 21, 2025 15:15
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.

[Feature Request] Add support for custom metrics
2 participants