opentelemetry-dotnet-contrib icon indicating copy to clipboard operation
opentelemetry-dotnet-contrib copied to clipboard

Additional metrics are emitted when "dotnet-counters" tool is used for the running process

Open ajay-sainy opened this issue 10 months ago • 1 comments

Issue with OpenTelemetry.Instrumentation.EventCounters

List of all OpenTelemetry NuGet packages and version that you are using (e.g. OpenTelemetry 1.3.2):

OpenTelemetry.Exporter.Console" Version="1.6.0" OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.6.0" OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.6.0-rc.1" OpenTelemetry.Extensions.Hosting" Version="1.6.0" OpenTelemetry.Instrumentation.AspNetCore" Version="1.5.1-beta.1" OpenTelemetry.Instrumentation.EventCounters" Version="1.5.1-alpha.1" OpenTelemetry.Instrumentation.Http" Version="1.5.1-beta.1" OpenTelemetry.Instrumentation.Process" Version="1.0.0-alpha.6" OpenTelemetry.Instrumentation.Runtime" Version="1.5.1"

Runtime version net6.0

Is this a feature request or a bug?

  • [ ] Feature Request
  • [x] Bug

I am not really sure if this is a bug or intended behavior.

What is the expected behavior?

Metrics only for the sources selected via AddEventCountersInstrumentation should be emitted.

What is the actual behavior? When dotnet-counters is used separately to view dotnet counters of the netcore web app, the library starts emitting additional metrics that were not added during initialization.

The issue can be easily reproduced:

  1. Run the below web app.
  2. Check the /metrics api.
  3. While the web app is running, run dotnet-counters in a separate terminal and monitor this web app.
  4. Check the /metrics api again. You will see additional metrics.
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

builder.Services.AddOpenTelemetry().WithMetrics(opts => opts
    .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(
        serviceName: "testservice",
        serviceVersion: "1"))
    .AddAspNetCoreInstrumentation()
    .AddEventCountersInstrumentation(context =>
    {
        context.RefreshIntervalSecs = 1;
        context.AddEventSources(
            "Microsoft-AspNetCore-Server-Kestrel",
            "System.Net.Sockets",
            "System.Net.NameResolution");
    })
    .AddPrometheusExporter());


var app = builder.Build();
app.UseOpenTelemetryPrometheusScrapingEndpoint();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

Additional Context

ezgif com-gif-maker

ajay-sainy avatar Sep 29 '23 18:09 ajay-sainy

the library starts emitting additional metrics that were not added during initialization.

Can you share the names of additional metrics as a comment or edit the original issue description?

cijothomas avatar Oct 03 '23 15:10 cijothomas