Closed
Description
Component
OpenTelemetry.Exporter.Geneva
Is your feature request related to a problem?
There is already a PR to support exporting metrics to different namespace and accounts:
https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1111/files
But it only supports when you record the metric with the tag
string _socketsConnected = "SocketTestMetric";
var _socketsConnectedMetric = meter.CreateUpDownCounter<int>(_socketsConnected, description: "Test Number of connected sockets");
var tags2 = new TagList
{
{ "_microsoft_metrics_account", "TestDifferentUpload" },
{ "_microsoft_metrics_namespace", "TestDifferentUploadNS" }
};
_socketsConnectedMetric.Add(1, tags2); // add the tag here to do the namespace override
it doesn't work when you pass the tags to meter or meter.createCounter() like below code:
{
{ "_microsoft_metrics_account", "TestDifferentUpload" },
{ "_microsoft_metrics_namespace", "TestDifferentUploadNS" }
};
var meter = _meterFactory.Create("TestMeter", "", tagList); // this will not work
string _socketsConnected = "SocketTestMetric";
var _socketsConnectedMetric = meter.CreateUpDownCounter<int>(name: _socketsConnected, unit: null, description: "Number of connected sockets test descrip",
tags: tagList); // this will not work
_socketsConnectedMetric.Add(1);```
So for current usage, we have to specify the tags with namespace everywhere we want to record the metric like _socketsConnectedMetric.Add(1, tags). This can cause duplicate code or configs. And in some conditions, if we want the metrics that are not easily controlled to send to a different namespace, that can be almost impossible. One example is if we leverage [.net extension metric like cpu metric](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/built-in-metrics-diagnostics#metric-containercpulimitutilization), then we cannot use this way to export to a different namespace or account.
Since .Net meters and metrics support [tags property](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.metrics.meterfactoryextensions.create?view=net-9.0), can we read the tags property from the creation stage and override the account and namepsace in the exporter?
In that case, we just need to call and create the meter once, then we will be able to upload the metrics to different accounts and namespace
var meter = _meterFactory.Create("TestMeter", tags);
### What is the expected behavior?
when pass tags with namespace and account to meter, geneva export should take it and override the default namespace and account, in other words, below code should be able to send metrics to TestDifferentUpload.TestDifferentUploadNS
var tagList = new TagList
{
{ "_microsoft_metrics_account", "TestDifferentUpload" },
{ "_microsoft_metrics_namespace", "TestDifferentUploadNS" }
};
var meter = _meterFactory.Create("TestMeter", "", tagList); // this will not work
string _socketsConnected = "SocketTestMetric";
var _socketsConnectedMetric = meter.CreateUpDownCounter<int>(_socketsConnected, description: "Test Number of connected sockets");
_socketsConnectedMetric.Add(1);
### Which alternative solutions or features have you considered?
no other solution
### Additional context
I would also like to know if there is any concern if we parse the MeterOption.tags to MetricPoint.tags. During metric initialization, the MetericPoint should take the tags from .net meter.
Right now seems this is the only place where tags are updated:
https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry/Metrics/AggregatorStore.cs#L155
which will be triggered by _socketsConnectedMetric.Add(1, tags);