How to disable OpenTelemetry #5627
-
Hi, I configure OpenTelemetry metrics with auto-start using the AddOpenTelemetry extension from OpenTelemetry.Extensions.Hosting.
Later in my controller's constructor I'm creating meter: ... and finally in one of the function I'm collecting metric
What would be the best approach to disable metrics collection? I was reading in spec about No-Op but I cannot find it in the library. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
All metrics (traces too) are explicit opt-in - i.e metrics must be enabled by using AddMeter() API. If you want to only enable metrics in one environment, but not in another, the easiest way is by controlling AddMeter() calls. For example, you can keep the list of meter names in config file (like appsettings.json), and call AddMeter() using the names from the config. By controlling the config for each environment, you can control the metrics itself. if (app.Environment.IsDevelopment()) } |
Beta Was this translation helpful? Give feedback.
All metrics (traces too) are explicit opt-in - i.e metrics must be enabled by using AddMeter() API. If you want to only enable metrics in one environment, but not in another, the easiest way is by controlling AddMeter() calls. For example, you can keep the list of meter names in config file (like appsettings.json), and call AddMeter() using the names from the config. By controlling the config for each environment, you can control the metrics itself.
if (app.Environment.IsDevelopment())
{
}
else
{
AddMeter("My-meter");
}