open-telemetry / opentelemetry-dotnet

The OpenTelemetry .NET Client
https://opentelemetry.io
Apache License 2.0
3.22k stars 765 forks source link

How to send traces to OpenTelemetry collector from .net 6 app deployed on Azure App Service #3480

Closed olivierbachard closed 1 month ago

olivierbachard commented 2 years ago

Question

Hello,

I have a .net 6 app deployed on a linux Azure App Service. The OpenTelemetry collector is installed on a VM in the same Azure resource group. The collector is then supposed to send traces to Datadog.

Everything works well when running the app on my local computer but I can't managed to get it working when the app is deployed on the Azure App Service.

Here is my opentelemetry configuration at the application startup.

   services
        .AddOpenTelemetryTracing(
            (builder) =>
            {
                builder
                    .SetResourceBuilder(ResourceBuilder.CreateDefault()
                        .AddAttributes(new[]
                        {
                            new KeyValuePair<string, object>("deployment.environment", env.EnvironmentName)
                        })
                        .AddService("MyServiceName"))
                    .AddSource("MyServiceName")
                    .AddHttpClientInstrumentation(options =>
                    {
                        options.Filter = message => message.Method != HttpMethod.Options;
                    })
                    .AddAspNetCoreInstrumentation(options =>
                    {
                        options.Filter = context => context.Request.Method != HttpMethod.Options.ToString();
                    });

            builder.AddOtlpExporter(o =>
            {
                o.Protocol = OtlpExportProtocol.Grpc;
                o.Endpoint = new Uri($"http://{OtlCollectorIp}:4317");
            });
        });

I also tried this configuration but still not working.

var otlResourceBuilder = ResourceBuilder.CreateDefault()
    .AddAttributes(new[] 
    {

        new KeyValuePair<string, object>("deployment.environment", env.EnvironmentName)
    })
    .AddService("MyServiceName");

var builder = Sdk.CreateTracerProviderBuilder()
    .SetResourceBuilder(otlResourceBuilder)
    .AddSource("MyServiceName")
    .AddHttpClientInstrumentation(options =>
    {
        options.Filter = message => message.Method != HttpMethod.Options;
    })
    .AddAspNetCoreInstrumentation(options =>
    {
        options.Filter = context => context.Request.Method != HttpMethod.Options.ToString();
    });

    builder.AddOtlpExporter(o =>
    {
        o.Protocol = OtlpExportProtocol.Grpc;
        o.Endpoint = new Uri($"http://{OtlCollectorIp}:4317");
    });

var tracerProvider = builder.Build();

services.AddSingleton(tracerProvider);

Any idea what I am missing ?

Use Github Discussions.

cijothomas commented 2 years ago

Please use https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/src/OpenTelemetry#self-diagnostics and obtain the logs from non-working scenario. It'd give us some hints about whats going wrong.

github-actions[bot] commented 1 month ago

This issue was marked stale due to lack of activity and will be closed in 7 days. Commenting will instruct the bot to automatically remove the label. This bot runs once per day.