Skip to content

Inheriting from listener started trace with distributed tracing #133

@drvn-mr

Description

@drvn-mr

Following the documentation and using Datadog::Lambda.wrap, we always seem to have a separate aws.lambda trace.

When the Lambda function is called with distributed tracing headers, the trace continues as expected.
However the first Datadog::Tracing.trace call does not become a child trace of the aws.lambda trace, instead being a direct child of the original continued trace ID.
So in Datadog we end up seeing 2 separate traces.

Is it possible to inherit from the trace started by the listener on_start ?
It doesn't seem to be the active trace.

Expected Behavior

Being able to see a single parent trace when a Lambda function is invoked.

Actual Behavior

With distributed tracing, traces started after Datadog::Lambda.wrap are always separate from the wrapping trace.

Steps to Reproduce the Problem

  1. Invoke a Lambda function with event object containing "headers" and injected Datadog headers.
    In our case we just do something like this:
Datadog::Tracing.trace(trace_name) do |_span, trace|
  headers = {}
  Datadog::Tracing::Contrib::HTTP.inject(trace.to_digest, headers)

  client = Aws::Lambda::Client.new
  client.invoke({
    ...
    payload: JSON.generate({ headers: headers, ... })
  })
end
  1. In the Lambda handler, wrap and start a trace:
Datadog::Lambda.wrap(event, context) do
  Datadog::Tracing.trace("do the thing") do
    ...
  end

  { statusCode: 200, body: 'Hello World' }
end

Specifications

  • Datadog Lambda Layer version: 3.27.0
  • Datadog Lambda extension v92
  • Ruby version: 3.4.8

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