© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
1 reply
nocgod

❔ Adding global tags with System.Diagnostics.Metrics

Hey, I might have missed it in the documentation.

I'm looking for a way to globally set some tags/labels that will be added to all metrics in my service. Motivation: I have multiple DCs and multiple environments in a single DC. I want all metrics reported with DC and ENV as a dimension. I'd prefer not to have to add those dimensions manually on each measurement, especially since the developers will probably forget to add those.

as you see in the example I have
new KeyValuePair<string, object>("dc", Environment.GetEnvironmentVariable("dc") ?? "il3"),
new KeyValuePair<string, object>("env", Environment.GetEnvironmentVariable("env") ?? "local"),
new KeyValuePair<string, object>("dc", Environment.GetEnvironmentVariable("dc") ?? "il3"),
new KeyValuePair<string, object>("env", Environment.GetEnvironmentVariable("env") ?? "local"),

they are defined on the resource. I would really like to have them reported on every metric I report without me having to add them manually
please checkout my code on dotnet fiddle
https://dotnetfiddle.net/aIRBu0
unfortunately, you wouldn't be able to run it in .net fiddle because they don't support readkey, but you'll get the gist and be able to run if you want
example metrics console .net otlp with prom | C# Online Compiler | ...
example metrics console .net otlp with prom | Test your C# code online with .NET Fiddle code editor.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

System.Diagnostics.EventLog [Answered]
C#CC# / help
4y ago
global::System.Console.WriteLine(); error
C#CC# / help
3y ago
Dealing with HTTPClient metrics
C#CC# / help
17mo ago
OpenTelemetry Metrics
C#CC# / help
5mo ago