Search code examples
c#amazon-web-servicesaws-lambdaopen-telemetry

AWS Lambda Open Telemetry, Missing Parent Span


I'm trying to use OpenTelemetry with AWS Lambda Function, using C#. I added AWS Otel Collector as layer, sending data to 3rd service, I use Signoz while trying, it works fine except one thing. My spans always have a parent span missing.

The application creates a span with the service name that I provided, then other spans. However, the first span also has a parent which is actually the lambda service, and it's not being sent to other services for some reason, therefore you have always missing span. The problem is actually defined in the content about Honeycomb but it doesn't target C#.

Like here and here

AWS has native XRay integration with Lambda. This means that when your function gets invoked, it has X-Ray information from the Lambda service that is passed into it. This means that when we work with OTEL, it will already have a parent span (the lambda service). The problem is that span will not go to Honeycomb, and Honeycomb will think there is a missing span. To fix this issue we just say that our first span is our root span.

When I disable XRay Tracing from Lambda Configuration, it stops publishing Lambda Service spans to Xray, but my span still has ParentId. Changing environment variables after looking through Honeycomb documentation didn't solve as well.

The way I defined OpenTelemetry in my code is like this, my first span uses the name "lambda.otel.service" and has parent coming from AWS Lambda Service.

readonly TracerProvider? _tracerProvider;
public Function()
{
    _tracerProvider = Sdk.CreateTracerProviderBuilder()
    .ConfigureResource(resource =>
        {
            resource   
                .AddService("lambda.otel.service")
                .AddAttributes(new[]
                {
                    new KeyValuePair<string, object>("service.version",
                        Assembly.GetExecutingAssembly().GetName().Version!.ToString())
                });
        })
    .AddAWSLambdaConfigurations()
    .AddAspNetCoreInstrumentation()
    .AddGrpcClientInstrumentation()
    .AddHttpClientInstrumentation()
    .AddSource(DiagnoticsConfig.SourceName)
    .AddOtlpExporter()
    .AddConsoleExporter()
    .Build();
}

enter image description here enter image description here


Solution

  • It seems like I didn't read documentation enough, when I read it, I solved the issue. I just needed to add this DisableAwsXRayContextExtraction property. If you'll disable Xray from your lambda, you gotta include this as explained here.

    .AddAWSLambdaConfigurations(options =>
    {
        options.DisableAwsXRayContextExtraction = true;
    })