Skip to content

feat(libdd-trace-inferrer): add crate for AWS Lambda trigger span inference - #2327

Draft
ygree wants to merge 6 commits into
mainfrom
ygree/libdd-trace-inferrer
Draft

feat(libdd-trace-inferrer): add crate for AWS Lambda trigger span inference#2327
ygree wants to merge 6 commits into
mainfrom
ygree/libdd-trace-inferrer

Conversation

@ygree

@ygree ygree commented Aug 6, 2026

Copy link
Copy Markdown

What does this PR do?

Adds a new libdd-trace-inferrer crate that infers Datadog span metadata from AWS Lambda trigger JSON payloads. The crate detects supported AWS event sources, extracts span data, trigger tags, trace carriers, trace context, span links, and wrapped trigger spans.

Supported trigger coverage includes API Gateway HTTP/REST/WebSocket, ALB, Lambda Function URLs, SQS, SNS, DynamoDB, S3, EventBridge, Kinesis, MSK, and Step Functions. It also handles wrapped SNS/EventBridge payloads in SQS/SNS, including Datadog carriers in SQS binary message attributes and EventBridge bodies.

Motivation

This creates a runtime-neutral Rust implementation for Lambda trigger span inference that can be consumed by tracers through FFI. Centralizing this logic in libdatadog lets runtimes share consistent AWS trigger detection, service/resource naming, context extraction, and inferred span completion behavior.

Additional Notes

This crate is primarily an extraction/port of the AWS Lambda trigger span inference logic from datadog-lambda-extension Bottlecap (bottlecap/src/lifecycle/invocation/triggers/* and span_inferrer.rs) into libdatadog.

The implementation is refactored to be runtime-neutral, replacing extension-specific config, protobuf spans, span ID generation, and propagation dependencies with reusable crate types such as InferConfig, SpanData, InferenceResult, TraceContext, and complete_inference.

This PR also includes follow-up refinements such as SQS binary Datadog carrier handling and EventBridge carrier extraction from SQS bodies/input-transformed payloads.

This branch is currently used in AWS Lambda instrumentation: DataDog/dd-trace-rs#219

duncanista and others added 5 commits April 13, 2026 17:16
…rence

Implements a production-ready Rust library that infers Datadog trace
spans from AWS Lambda trigger event payloads. Supports all 13 AWS
trigger types (API Gateway HTTP/REST/WebSocket, ALB, Lambda Function
URL, SQS, SNS, S3, DynamoDB, Kinesis, EventBridge, MSK, Step
Functions) with full span enrichment, service name resolution, trace
context extraction, span pointers, and wrapped inferred span chaining.

The crate is decoupled from protobuf types and designed for consumption
by any tracer runtime through a future FFI layer.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ferenceResult

Streamline the Trigger trait by consolidating ARN, service mapping, and
resource key logic into `get_tags()` and `enrich_span()`, reducing the
number of required trait methods from 11 to 7. Each trigger now owns its
full tag construction including event_source_arn, eliminating the
intermediate assembly step in `build_result_from_trigger`.

Key changes:
- Rename `SpanPointer` -> `SpanLink` and `GeneratedTraceContext` -> `TraceContext`
  to better reflect their semantics (resource linking, not pointer indirection;
  pre-extracted context, not generated)
- Replace `should_create_inferred_span` field with a method that checks
  whether `span_data.name` is populated, making the contract explicit
- Remove `get_arn()`, `get_specific_service_id()`, `get_generic_service_id()`,
  and `get_dd_resource_key()` from the trait — triggers handle these internally
- Remove `trigger_type`, `event_source_arn`, `dd_resource_key` fields from
  InferenceResult, reducing coupling between the result and enum dispatch
- Pass `&InferConfig` to `get_tags()` so triggers can resolve service names
  and build ARNs without a second pass
- Take `&self` instead of `self` in `build_inference_result` macro dispatch
- Fix clippy warnings in tests (redundant pattern matching, field
  assignment outside initializer)
- Apply nightly rustfmt across all source files
- Add CODEOWNERS entry (@DataDog/apm-serverless)
- Add Dockerfile COPY step for libdd-trace-inferrer/Cargo.toml so the
  Docker build cache layer does not fail to load the workspace member
@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Aug 6, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 1080d34 | Docs | Datadog PR Page | Give us feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants