Skip to content

W3C context propagation #169

@alessandrobologna

Description

@alessandrobologna

Hi,
somehow I am not able to pass a trace context with the w3c headers (traceparent and tracestate) to a lambda function with application signals enabled and instrumented with this library.

It seems that setting OTEL_LAMBDA_DISABLE_AWS_CONTEXT_PROPAGATION has no effect (normally in the upstream libraries that prevents using the _X_AMZN_TRACE_ID environment variable to determine the parent).

Disabling x-ray on the lambda function doesn't seems to help: if application signal is enabled it seems that the env var _X_AMZN_TRACE_ID is always present.

It seems that the reason is this implementation for the customExtractor function

export const customExtractor = (event: any, _handlerContext: Context): OtelContext => {
  let parent: OtelContext | undefined = undefined;
  const lambdaTraceHeader = process.env[traceContextEnvironmentKey];
  if (lambdaTraceHeader) {
    parent = awsPropagator.extract(
      otelContext.active(),
      { [AWSXRAY_TRACE_ID_HEADER]: lambdaTraceHeader },
      headerGetter
    );
  }
  if (parent) {
    const spanContext = trace.getSpan(parent)?.spanContext();
    if (spanContext && isSpanContextValid(spanContext)) {
      return parent;
    }
  }
  const httpHeaders = event.headers || {};
  const extractedContext = propagation.extract(otelContext.active(), httpHeaders, headerGetter);
  if (trace.getSpan(extractedContext)?.spanContext()) {
    return extractedContext;
  }
  return ROOT_CONTEXT;
};

which effectively precludes extracting the trace context from the event headers (as the first condition is always true).
Is this behavior intentional? It makes it more difficult to trace requests originating from a non x-ray context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions