zzz
April 1, 2021, 11:00pm
1
What is the recommended way to emit custom metrics in workflow/activity?
I can imagine it should be a side-effect, so should we use a local activity to emit metric? Or is there a better way to do that?
Asking this, because we don’t want to send duplicate metrics on recovery.
maxim
April 1, 2021, 11:52pm
2
Workflow.getMetricsScope()
returns metrics scope instance that automatically dedupes metrics on replay.
zzz
April 2, 2021, 12:05am
3
Thanks for the info! (btw, it should be Workflow.getMetrics Scope())
1 Like
zzz
April 2, 2021, 1:14am
4
I notices that the scope.timer(METRIC_NAME).start() returns a Stopwatch.
Is it safe to use this:
Stopwatch watch = metricScope.timer(METRIC_NAME).start();
operation();
watch.stop();
Or using Workflow.currentTimeMillis only:
long startTime = Workflow.currentTimeMillis();
operation();
long duration = Workflow.currentTimeMillis() - startTime;
metricScope.timer(METRIC_NAME).record(com.uber.m3.util.Duration.ofMillis(duration));
maxim
April 2, 2021, 1:20am
5
It is safe to use
Stopwatch watch = metricScope.timer(METRIC_NAME).start();
operation();
watch.stop();
Here is the code that initializes the scope to use the workflow clock if you are interested in implementation details.
1 Like