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

Specifying an endpoint in appsettings.json breaks appending suffix to endpoint path

Open Volkmire opened this issue 8 months ago • 1 comments

Package

OpenTelemetry.Exporter.OpenTelemetryProtocol

Package Version

Package Name Version
OpenTelemetry.Exporter.OpenTelemetryProtocol 1.8.1
OpenTelemetry.Extensions.Hosting 1.8.1

Runtime Version

net8.0

Description

I tried to configure an app similar to this README, but when I specify the endpoint and do Configure<OtlpExporterOptions>, the exporter uses the same URI as in options and does not append signal specific suffix to any of the calls.
I assume this is because of AppendSignalPathToEndpoint being set to false in Endpoint setter of OtlpExporterOptions.

Steps to Reproduce

// simplified example
static void ConfigureTelemetry(WebApplicationBuilder appBuilder)
{
    var logging = appBuilder.Logging;
    var services = appBuilder.Services;
    var configuration = appBuilder.Configuration;

    logging.ClearProviders();
    logging.AddConsole();

    // if I try to do this, signal exporters no longer append signal suffixes to base path
    services.Configure<OtlpExporterOptions>(configuration.GetSection("OpenTelemetry:Otlp"));

    var resourceBuilder = ResourceBuilder.CreateEmpty()
        .AddAttributes(new KeyValuePair<string, object>[]
        {
            new("service.name", $"unknown:{Process.GetCurrentProcess().ProcessName}"),
            new("service.instance.id", MachineName)
        })
        .AddEnvironmentVariableDetector();

    logging.Configure(opts => opts.ActivityTrackingOptions = ActivityTrackingOptions.Tags)
        .AddOpenTelemetry(cfg =>
        {
            cfg.SetResourceBuilder(resourceBuilder);
            cfg.AddOtlpExporter();
        });

    services.AddOpenTelemetry()
        .WithTracing(cfg =>
        {
            cfg.SetResourceBuilder(resourceBuilder);
    
            cfg.AddSource("Azure.*")
                .AddAspNetCoreInstrumentation()
                .AddHttpClientInstrumentation();
                    
            cfg.AddOtlpExporter();
        })
        .WithMetrics(cfg =>
        {
            cfg.SetResourceBuilder(resourceBuilder);
            cfg.AddOtlpExporter();
        });

Expected Result

Options behavior should be the same for environment variables (OTEL_EXPORTER_OTLP_ENDPOINT, etc) and options registration.

Actual Result

Specifying an endpoint as environment variable allows exporter to append signal suffix. Specifying an endpoint via options registration prevents exporter from appending signal suffix.

Additional Context

No response

Volkmire avatar Jun 03 '24 08:06 Volkmire