AutoMerge is generally available

  • 16 min read

Trace AWS Lambda durable functions with OpenTelemetry and Dash0

AWS has released an OpenTelemetry plugin for the AWS Durable Execution SDK for JavaScript. We're happy to be a launch partner for the plugin and to have helped develop and review its implementation.

AWS Lambda durable functions can suspend, resume, and continue work across multiple invocations. That changes the questions you ask when debugging them. Which invocation ran a step? What result did it checkpoint? What did the external worker receive, and what result resumed the workflow?

AWS's OpenTelemetry plugin for the Durable Execution SDK adds spans for the workflow, its invocations, and durable operations. Combined with Dash0's Lambda instrumentation, those spans sit alongside captured function inputs, outputs, and supported outgoing SDK call payloads.

We'll use a small fulfillment workflow that sends a delayed SQS message and waits for a second Lambda function to call back. The goal is to understand both the execution and the data it used, including the state restored after suspension.

One durable Lambda function across two invocations: the first saves a plan, sends it through SQS to a worker, and suspends. The worker calls back to AWS, which resumes the same function to restore the plan and return the result.

The SQS message carries the fulfillment plan and callback identifier. The worker calls SendDurableExecutionCallbackSuccess, and AWS resumes the durable function in a second invocation.

Start with a Lambda function instrumented for Dash0

If your function is not instrumented yet, follow Set up AWS Lambda auto instrumentation. Choose Traces and Logs for this walkthrough. For deployments managed outside the Dash0 UI, use the Lambda Extension's manual setup instructions.

Load the durable execution plugin

You can add the plugin in two ways:

The Dash0 layer does not include the AWS durable execution plugin, and setting an environment variable alone does not install it. Choose one packaging option, then enable the plugin.

Option 1: Package the plugin with your function

Install the AWS packages in your function project:

bash
npm install @aws/durable-execution-sdk-js@3.0.0 @aws/durable-execution-sdk-js-otel@2.0.0 @aws-sdk/client-sqs@3.1161.0 @aws-sdk/client-lambda@3.1161.0

Include the plugin and its required peer dependencies in the deployment package. We deployed an unbundled ZIP so the AWS SDK modules remained available for Dash0's auto-instrumentation.

Then enable the plugin.

Option 2: Attach the plugin as a layer

For an existing durable function using SDK 3.x on Node.js 22 or later, put the plugin and its OpenTelemetry peer dependencies in a separate Lambda layer under nodejs/node_modules, and attach it to the function. Keep @aws/durable-execution-sdk-js in the function package, not in the plugin layer. AWS describes this in Dynamic loading from a Lambda layer.

Add the plugin without changing an existing durable function's handler: attach a separate layer containing the plugin and its OpenTelemetry peer dependencies, set DURABLE_EXECUTION_PLUGINS, and let the function's SDK load the plugin. Keep the Dash0 layer and /opt/wrapper for the global provider and export.

Then enable the plugin. No handler code changes are needed for this option.

Enable the plugin

For either packaging option, select the workflow-centered view with this Lambda environment variable:

text
DURABLE_EXECUTION_PLUGINS=@aws/durable-execution-sdk-js-otel/otel-execution

The SDK loads the plugin, while Dash0 handles the underlying instrumentation and export. This is the registration method used by our deployed example. We compare the two tracing views below.

Keep the Dash0 wrapper, /opt/wrapper. Do not replace it with the ADOT wrapper from AWS's alternative provider setup.

For registration in code with the plugin version used here, AWS exports createExecutionOtelPluginFactory() and createInvocationOtelPluginFactory() for withDurableExecution's plugins option. Register exactly one view, once. Use either environment registration or registration in code, not both. The examples here use plugin 2.0.0; the current AWS OpenTelemetry guide documents the unified factory API introduced in 2.1.0.

A small workflow with state worth inspecting

Our function receives this synthetic order:

json
{
  "orderId": "demo-order-1042",
  "sku": "coffee-beans-1kg",
  "quantity": 2,
  "destination": "Berlin"
}

It checkpoints a fulfillment plan, creates a callback, and sends the plan and callback identifier to SQS with DelaySeconds: 5. A second Lambda function, the worker, consumes the message and reports a simulated dispatch result through SendDurableExecutionCallbackSuccess. The durable function waits for that callback, then returns the result.

Set up the two functions with separate roles:

  • Durable function: Set FULFILLMENT_QUEUE_URL, grant permission to send to that queue, and grant its checkpoint permissions.
  • Worker: Configure an SQS event source mapping, and grant queue-consumption permissions and lambda:SendDurableExecutionCallbackSuccess for the target durable function's executions.
  • Both functions: Grant the instrumentation and logging permissions.

The handler is:

JavaScript
const { withDurableExecution } = require('@aws/durable-execution-sdk-js');
const { SQSClient, SendMessageCommand } = require('@aws-sdk/client-sqs');

const sqs = new SQSClient({});

exports.handler = withDurableExecution(async (event, context) => {
  if (
    !event ||
    typeof event.orderId !== 'string' || !event.orderId ||
    typeof event.sku !== 'string' || !event.sku ||
    !Number.isSafeInteger(event.quantity) || event.quantity < 1 ||
    typeof event.destination !== 'string' || !event.destination
  ) {
    throw new Error('Provide orderId, sku, positive integer quantity, and destination');
  }

  const plan = await context.step('prepare-fulfillment', async () => {
    const prepared = {
      orderId: event.orderId,
      sku: event.sku,
      quantity: event.quantity,
      destination: event.destination,
      warehouse: 'eu-central',
      status: 'ready-to-ship',
    };
    context.logger.info('Fulfillment plan prepared', { orderId: prepared.orderId });
    return prepared;
  });

  const result = await context.waitForCallback('dispatch-and-wait', async (callbackId) => {
    await sqs.send(new SendMessageCommand({
      QueueUrl: process.env.FULFILLMENT_QUEUE_URL,
      DelaySeconds: 5,
      MessageBody: JSON.stringify({ callbackId, plan }),
    }));
    context.logger.info('Fulfillment request queued', { orderId: plan.orderId });
  }, { timeout: { minutes: 2 } });

  return JSON.parse(result);
});

The worker is a regular Lambda function:

JavaScript
const { LambdaClient, SendDurableExecutionCallbackSuccessCommand } = require('@aws-sdk/client-lambda');

const lambda = new LambdaClient({});

exports.handler = async (event) => {
  for (const record of event.Records) {
    const { callbackId, plan } = JSON.parse(record.body);
    const result = {
      orderId: plan.orderId,
      status: 'dispatched',
      destination: plan.destination,
      warehouse: plan.warehouse,
      trackingId: `shipment-${plan.orderId}`,
      messageId: record.messageId,
    };
    await lambda.send(new SendDurableExecutionCallbackSuccessCommand({
      CallbackId: callbackId,
      Result: Buffer.from(JSON.stringify(result)),
    }));
    console.info('Fulfillment callback sent', { orderId: plan.orderId });
  }
};

Instrument the worker with Dash0 too. It does not need the durable execution plugin because it is not a durable function. Our mapping uses batch size one, visibility timeout 180 seconds, and a dead-letter queue after three receives. These settings make the demo easy to inspect, not a general production retry policy. Production consumers must handle duplicate delivery and callback failures deliberately.

We ran this workflow twice, once for each tracing view shown below. In both runs, the first durable invocation ended before the callback arrived. AWS then resumed the function in a second invocation. On replay, the preparation step returned its saved result instead of running its body again. The code that sent the SQS message, the submitter, did not run again during that successful replay.

What AWS shows you without the plugin

AWS already provides an execution history and each step's saved output without the OpenTelemetry plugin. Dash0's standard Lambda instrumentation can also capture invocation spans, supported outgoing SDK calls, and payloads without it. The plugin adds spans for the durable workflow and its operations, so you can follow those operations across suspension and resumption alongside the existing instrumentation.

The AWS Lambda console shows preparation completing, callback registration, the first invocation completing, CallbackSucceeded, and execution continuing to success.

AWS Lambda callback execution history
Figure 1. AWS Lambda's execution history. Callback success follows the first invocation's completion.

The five-second SQS delay only controls when the message becomes available. Delivery, worker execution, and callback processing add time. The wait is elapsed time, not active application computation. Delivery is not exactly once either. A send can repeat if it succeeds before its checkpoint commits, and SQS itself can deliver duplicates.

Choose the view that answers your question

The plugin provides two alternative telemetry views, not two execution behaviors. Switching views does not change the handler, checkpointed results, or callback wait. It changes how the plugin represents durable operations in spans.

We ran the same handler and input once with each view. Both executions prepared the plan, sent the delayed message, suspended, and resumed after the worker's callback. Each durable trace includes an instrumented caller, a Workflow span, and two plugin Invocation spans. The worker is a separate linked trace.

The animations highlight the structure and span links in each view. Their playback speed does not represent execution time or payload flow.

ViewBest questionOperation representation
Workflow-centeredWhat happened to this logical operation across the execution?Operations belong to Workflow or a containing durable operation. An operation spanning suspension retains its logical lifetime.
Invocation-centeredWhat did this Lambda invocation execute?Operations appear as invocation-bounded segments, with links connecting related segments and Workflow.

Workflow-centered: read the logical sequence

With /otel-execution, the tree follows the durable operation hierarchy, not which invocation ran each operation. prepare-fulfillment and dispatch-and-wait sit under Workflow. dispatch-and-wait contains the callback and submitter, and the submitter's attempt contains the SQS send.

Figure 2. Orange highlights logical hierarchy. Yellow follows submission in the first invocation. Teal connects the completed callback to the resumed invocation. Arrows show selected recorded span links, not parent-child edges.
  1. Logical hierarchy: Follow the submitter attempt into SendMessage and its HTTP request.
  2. One logical callback wait: Here the callback wait spans about 6.5 seconds, including suspension. This is elapsed time, not continuous handler computation.
  3. Invocations are still visible: The two Invocation spans appear under the Lambda handler spans. Links show which invocation recorded each operation, without making the operation a child of that invocation.

Follow the arrows from the submitter to the first invocation and from the completed callback to the resumed invocation. The callback link identifies the invocation that recorded completion, not an invocation that actively ran the entire wait.

Use this view to follow the order's progress. The callback wait remains one operation across an invocation boundary.

Invocation-centered: read each invocation's work

Select the other view:

text
DURABLE_EXECUTION_PLUGINS=@aws/durable-execution-sdk-js-otel/otel-invocation

Durable operations now sit beneath the Invocation that observed them. The first invocation contains preparation, callback registration, and SQS submission. The second contains the resumed context and callback completion.

Figure 3. Orange shows the first invocation, yellow the resumed invocation, and teal the continuation link between callback segments. Each stage replaces the previous highlights. Two segments represent one callback wait, not two waits or attempts.
  1. Invocation-local operations: Preparation and submission belong to the first branch. The resumed branch completes the wait.
  2. A wait split at the boundary: The callback wait becomes two short segments, about 206 ms before suspension and under 1 ms after resuming. A link connects the resumed segment to the initial one. Suspension is the gap between them, not a long span under either invocation. Segment durations are not Lambda billed duration.
  3. Workflow remains: The Workflow span still covers the execution, about 9.84 seconds here. Operations link to it instead of using it as their parent. This view does not turn each durable invocation into a separate trace.

Tree indentation represents parenting; link badges represent span links. Their counts are not retry counts. The resumed callback links to both its initial segment and Workflow.

The plugin's Invocation span and Lambda instrumentation's function and handler spans describe different layers. They do not mean extra invocations occurred. AWS history confirms two durable invocations in each run.

Start with workflow-centered tracing to follow the business sequence. Use invocation-centered tracing to investigate work before suspension or after resumption. These are separate runs, not a performance benchmark. For long-running workflows, also consider your backend's span ingestion window. AWS recommends invocation-centered tracing when long-open operation spans could exceed that window; the final Workflow span still faces that limit in either view.

Inspect what the execution received, stored, and sent

The two tracing views explain how the workflow's operations relate across invocations. Next, follow the order through the captured payloads and compare the restored checkpoint data with AWS's saved step output. These payloads come from Dash0's Lambda instrumentation, not from the durable plugin itself.

The original input

In our demo, the initial Lambda invocation span's Payload tab shows the durable runtime envelope. Inside it, ExecutionDetails.InputPayload contains the original order.

Original order in the initial Lambda payload
Figure 4. The original order inside the durable runtime's event envelope.

This gives us a concrete starting point: two bags of coffee, destined for Berlin. The incoming event does not contain warehouse or status. Preparation adds them.

Compare AWS's saved step result with the restored checkpoint data

The AWS console's Output tab for prepare-fulfillment shows the saved plan, including warehouse: "eu-central" and status: "ready-to-ship".

AWS preparation step output
Figure 5. AWS exposes the saved step output directly. This is the reference value for the restored plan.

When AWS resumes the function, it includes previously checkpointed results in the invocation's input. Dash0's Payload tab captures this runtime input. Here, InitialExecutionState.Operations contains the saved result of prepare-fulfillment, including the plan's warehouse and status in StepDetails.Result.

Stored preparation result in the resumed Lambda input
Figure 6. The checkpointed preparation result supplied by AWS to the resumed Lambda invocation, captured in Dash0's Payload tab.

This screenshot shows the resumed invocation's input, not a CheckpointDurableExecution API request. We also verified the same saved result in that call's captured HTTP response.

AWS saves the plan returned by prepare-fulfillment and includes it in the resumed invocation’s input. Dash0 captures that input, so you can inspect the restored plan without adding log statements.

Inspect the outgoing SDK call

Select the SendMessage span, open Attributes, and find messaging.publish.body. The request contains DelaySeconds: 5. Its MessageBody contains the callback identifier and fulfillment plan.

Outgoing SQS payload containing the callback identifier and fulfillment plan
Figure 7. The delayed SQS request contains the callback identifier and the same fulfillment plan. The identifier shown belongs to the retired demo, whose infrastructure has been removed.

The consumer's captured event contains the same message. Its callback changes the business status to dispatched and adds a tracking ID. We verified that the callback result equals the final durable execution result, and its message ID matches the producer's SQS response.

In this setup, the worker has its own trace. Its handler links to the producer's SendMessage span; it is not another child inside the durable workflow trace. Follow the link to connect the queued request with the callback SDK call.

Worker handler linked to the SQS producer
Figure 8. A recorded span link connects the worker and producer traces without inventing a parent-child relationship.

AWS's execution history and step output explain the durable execution itself. Dash0 connects the workflow telemetry with Lambda invocations, outgoing SDK calls, and captured payloads. You can compare what arrived, what was restored, and what was sent without reconstructing business payloads from hand-written log messages.

Payload capture has limits and masking rules. Review the Lambda Extension configuration before capturing sensitive data. Our examples use synthetic orders. Checkpoint tokens were masked as ****, but the callback identifier inside the JSON-encoded SQS body was not. Treat callback identifiers as sensitive and configure appropriate masking. Do not assume every payload will be captured in full.

When spans show up and when they don't

Workflow exports when execution reaches terminal success or failure. It is not a continuously updated progress record. Workflow-centered operation spans export on completion. Invocation-centered tracing can close a segment at an invocation boundary and represent continuation in another segment.

Sampling matters. A plain CLI invocation in our test carried upstream Sampled=0 and produced ordinary Lambda instrumentation without durable plugin spans. A sampled upstream invocation produced the expected spans. Check the incoming sampling decision rather than overriding it blindly.

If spans are absent, check that the plugin module is packaged, Dash0 tracing is enabled, and a compatible global provider is registered. Export is best effort. A killed invocation does not guarantee a final Workflow span.

Try it with your own workflow

Start with a function already instrumented for Dash0, load one plugin view, and run a workflow that suspends and resumes.

Follow a recognizable value through the original event, saved step result, outgoing SDK request, and callback result. Durable spans explain how the work progressed. Captured payloads help explain why it produced that result.

Read AWS's announcement: AWS Lambda Durable Functions observability with OpenTelemetry. For setup guidance and tracing limitations, see the OpenTelemetry guide and the plugin README.