nocgod
nocgod
CC#
Created by nocgod on 4/23/2023 in #help
❔ 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
2 replies