# Update custom tag value of built-in metrics

**URL:** <https://community.temporal.io/t/update-custom-tag-value-of-built-in-metrics/4631>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [May 5, 2022, 9:06pm UTC](https://community.temporal.io/t/update-custom-tag-value-of-built-in-metrics/4631 "2022-05-05T21:06:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravikiran](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@ravikiran](https://community.temporal.io/u/ravikiran)\
**Post date:** [May 5, 2022, 9:06pm UTC](https://community.temporal.io/t/update-custom-tag-value-of-built-in-metrics/4631/1 "2022-05-05T21:06:58Z")

</div>

hi,  
I have followed the example for metrics given [here](https://github.com/temporalio/samples-java/blob/main/src/main/java/io/temporal/samples/metrics/MetricsWorker.java) and have used a custom tag with default value.  
We need to update this tag inside the workflow during runtime.  
The tag itself is of type string and value is also string which depicts the input format/type.

Appreciate if anyone can guide me on how to update the custom tag value.

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [May 5, 2022, 9:32pm UTC](https://community.temporal.io/t/update-custom-tag-value-of-built-in-metrics/4631/2 "2022-05-05T21:32:06Z")

</div>

This is not possible right now, tags and their values have to be static. The set scopes/tags that are configured via WorkflowServiceStubsOptions are not reconfigured for each workflow execution.

Can you explain your use case for this?  
You have the ability to set custom metrics

In activity code:  
`Activity.getExecutionContext().getMetricsScope()...`

In workflow code:  
`Workflow.getMetricsScope()...`

Another thing to maybe look at is using custom [Search Attributes](https://docs.temporal.io/docs/concepts/what-is-a-search-attribute/) which you can upsert during workflow execution.

---

<div class="post-metadata">

**Author:** ![ravikiran](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@ravikiran](https://community.temporal.io/u/ravikiran)\
**Post date:** [May 6, 2022, 4:50am UTC](https://community.temporal.io/t/update-custom-tag-value-of-built-in-metrics/4631/3 "2022-05-06T04:50:16Z")

</div>

We want to add a custom tag and a placeholder value during the metric registration/startup. And then during runtime, update the tag’s value based on certain criteria (here input type)

1. We want to use the default metrics provided by temporal SDK.
2. We want additional custom tags to existing metrics.
3. Update the custom tag values during runtime.

If this is not possible, is there way where I can tweak this through class extensions or custom impl.

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [May 6, 2022, 1:51pm UTC](https://community.temporal.io/t/update-custom-tag-value-of-built-in-metrics/4631/4 "2022-05-06T13:51:54Z")

</div>

1. is not currently possible. Would suggest opening issue in [Java SDK repo](https://github.com/temporalio/sdk-java/issues).

Would like to understand use case for this and why it cannot be solved via custom metrics or search attributes.

---

<div class="post-metadata">

**Author:** ![ravikiran](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@ravikiran](https://community.temporal.io/u/ravikiran)\
**Post date:** [May 6, 2022, 3:03pm UTC](https://community.temporal.io/t/update-custom-tag-value-of-built-in-metrics/4631/5 "2022-05-06T15:03:11Z")

</div>

Search attributes have to be executed on temporal server, which is access controlled and might affect other applications connecting to same server.

And for custom metrics, we don’t need to introduce one more metric and re-invent the wheel. Or are you suggesting adding custom metric with same name as the one provided in SDK like (temporal\_workflow\_endtoend\_latency\_seconds)

---

<div class="post-metadata">

**Author:** ![ravikiran](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@ravikiran](https://community.temporal.io/u/ravikiran)\
**Post date:** [May 9, 2022, 7:07pm UTC](https://community.temporal.io/t/update-custom-tag-value-of-built-in-metrics/4631/6 "2022-05-09T19:07:44Z")

</div>

@tihomir Submitted request [Support dynamic values for custom tags in metrics. · Issue #1195 · temporalio/sdk-java · GitHub](https://github.com/temporalio/sdk-java/issues/1195)

---

<div class="post-metadata">

**Author:** ![Monikongkona](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/monikongkona/32/1919_2.png) [@Monikongkona](https://community.temporal.io/u/Monikongkona)\
**Post date:** [March 30, 2023, 6:35am UTC](https://community.temporal.io/t/update-custom-tag-value-of-built-in-metrics/4631/7 "2023-03-30T06:35:36Z")

</div>

@tihomir / @maxim Is this feature still not available? I see couple of linked issues

> <https://github.com/temporalio/sdk-java/issues/1195>
>
> \*\*Is your feature request related to a problem? Please describe.\*\*
> Currently cu…stom tag values are static in nature, once set cannot be updated during the workflow execution. 
> E.g: the temporal\_workflow\_endtoend\_latency\_seconds is a very useful metric, but when we share the workflow with different inputs, we would like to add a custom tag and set its value based on the input.
> 
> \*\*Describe the solution you'd like\*\*
> Ability to modify the custom tag using Workflow.getMetricsScope().tagged() method (similarly for Activity too).
> 
> \*\*Describe alternatives you've considered\*\*
> Alternatives are to create custom metrics similar to already exposed by SDK. 
> 
> \*\*Additional context\*\*
> As per discussion here, https://community.temporal.io/t/update-custom-tag-value-of-built-in-metrics/4631/1

> <https://github.com/temporalio/sdk-java/issues/1163>
>
> We are using Temporal to handle workflows for registrations. Those registrations… are for a certain region/country. We are sending the metrics to New Relic to create a dashboard to get insights in how many workflows have started, failed, cancelled or completed. This works fine. The region is part of the input that starts the workflow. 
> 
> However we would like to split those metrics based on the region, we tried several hooks but apart from sending a custom metric on the start of a workflow we aren't able to solve this. What we want is that when a workflow starts, it contributes a tag to the metrics (in our case the region) so that we can use that as an additional dimension/facet in New Relic to group things by. 
> 
> We are using the Java SDK and haven't found a foolproof way of doing that, apart from a custom metric at the start of the workflow. 
> 
> What we currently have is we have a single \`WorkflowServiceStubs\` which we cannot use to set the region. We tried to create a \`WorkflowServiceStubs\` instance per region, but that starts to break as soon as we need to react to signals, we there loose the region and cannot use the proper one. 
> 
> We tried to create a \`WorkflowClientInterceptor\` which doesn't give us access to the correct \`MetricScope\` to add tags. 
> 
> We also tried a \`ContextPropagator\` although we can pass the region around there is no way to contribute it as a tag to the metrics. 
> 
> All in all the only thing that worked was a custom metric at the start of a workflow, but that still leaves out the cancelled, failed and completed events we need to have. 
> 
> It would be nice to have a way that when starting a workflow, we could add custom tags to the metrics and that those would be added to all events being send to New Relic. Currently it seems to hard or to be to inflexible.

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [March 30, 2023, 2:30pm UTC](https://community.temporal.io/t/update-custom-tag-value-of-built-in-metrics/4631/8 "2023-03-30T14:30:41Z")

</div>

Hi, you are correct. Not yet available, please follow issue [here](https://github.com/temporalio/sdk-java/issues/1163).
