grafana / grafana-opentelemetry-dotnet

Grafana's distribution of OpenTelemetry instrumentation for .NET
Apache License 2.0
37 stars 6 forks source link

Is there any way to filter metrics before sending to HostedGrafana? #122

Open chinwobble opened 2 weeks ago

chinwobble commented 2 weeks ago

Question

Is there any way to filter metrics before sending to HostedGrafana?

My apps is sending tonnes of bucketed metrics for things like connecting to keyvault.

The problem is that the adaptive metrics don't provide fine grained enough control over which label values I want to keep or drop.

metric http_client_request_duration_seconds_bucket has a label called server_address. If server_address = keyvault I want to drop those series, if not I want to keep them.

matt-hensley commented 2 weeks ago

An official way of filtering metrics is being defined in the OpenTelemetry specification: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#metricfilter

The AddView API in the OpenTelemetry .NET SDK allows for dropping metrics: https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/docs/metrics/customizing-the-sdk#drop-an-instrument

There is an overload that accepts a delegate that may allow for conditionally dropping metric points. I'm traveling currently but will take a look next week.