Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Exporter.Geneva] Exporting metrics to different combinations of namespace through MeterOptions.tags #2426

Open
BowenYang666 opened this issue Dec 17, 2024 · 3 comments
Labels
comp:exporter.geneva Things related to OpenTelemetry.Exporter.Geneva enhancement New feature or request

Comments

@BowenYang666
Copy link

BowenYang666 commented Dec 17, 2024

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);

@BowenYang666 BowenYang666 added the enhancement New feature or request label Dec 17, 2024
@github-actions github-actions bot added the comp:exporter.geneva Things related to OpenTelemetry.Exporter.Geneva label Dec 17, 2024
Copy link
Contributor

Tagging component owner(s).

@cijothomas @CodeBlanch @rajkumar-rangaraj

@cijothomas
Copy link
Member

var meter = _meterFactory.Create("TestMeter", "", tagList); // this will not work

This is not expected to work. It'll work if you use https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.Exporter.Geneva#otlpprotobufencoding , which is a private preview feature. You need to work with internal support to onboard.

var _socketsConnectedMetric = meter.CreateUpDownCounter(name: _socketsConnected, unit: null, description: "Number of connected sockets test descrip",
tags: tagList); // this will not work

Instrument level tag is something .NET runtime chose to add, but there is no spec for it, and it is not supported by OTel .NET. See tracking issue: open-telemetry/opentelemetry-dotnet#5478
If OTel .NET chose to add support for it in the future, then GenevaExporter will also support it then.

@BowenYang666
Copy link
Author

Thanks a lot @cijothomas. You mentioned this is a preview feature and need internal supports. Does that mean even if I use this feature in my code, I still cannot upload the metric to gevena become geneva side has not supported this feature yet?

And my final request is to upload metrics to different combinations of namespaces, for metricA uploads to namespace A, metricB uploads to namepsaceB. Does this OtlpProtobufEncoding supports the multiple namespaces uploading?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:exporter.geneva Things related to OpenTelemetry.Exporter.Geneva enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants