Skip to content

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

Draft
ygree wants to merge 7 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 7 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

Pipelines  Tests

Unblock PR with BitsAI

⚠️ Warnings

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 3 Pipeline jobs failed

DataDog/apm-reliability/libdatadog | benchmarks — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

Lint | clippy #ubuntu-latest stable — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

Compilation error in libdd-crashtracker/build.rs:54:43: redundant reference in println! argument; remove the redundant &amp;: dst_file.

Lint | clippy #windows-latest stable — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

Usage of unwrap_unchecked when an _unchecked variant of the associated function exists in libdd-alloc\src\linear.rs:37.

📋 Copy fix prompt
CI on my pull request is failing. Help me find and fix the root cause of each failing job below — they were flagged as caused by changes in this PR, so focus on the diff. For each job, explain the failure and propose a fix.

Before you start, set up the Datadog software-delivery tooling so you can
query the CI data yourself:

1. Check whether you already have the Datadog software-delivery MCP tools
   (e.g. a `search_datadog_ci_pipeline_events` tool) and the `unblock-pr` skill.
2. If either is missing, STOP and ask me for permission before installing
   anything. Do not install or run anything until I have said yes.
3. Only with my explicit approval, set up the Datadog software-delivery MCP
   server and skills by following:
     https://docs.datadoghq.com/getting_started/software_delivery_mcp_tools/
   then restart so the skill is picked up.
4. If I decline, skip all of the above and work from the context below alone.

Then run /unblock-pr — it will pull the CI data itself. The job context below is what we already know.

If /unblock-pr is not available — because I declined the setup above, or it did not install — work from the context below instead.

Datadog has already classified this failure as caused by changes in this PR.
Take that as given and work the fix:

1. Locate the change. Diff this branch against its base and find the change
   that produces this error. Explain the mechanism, don't just name a file:
     git fetch origin && git diff $(git merge-base origin/main HEAD)...HEAD
2. Reproduce it locally. Run the failing job's command or test before
   proposing anything.
3. Propose the smallest fix that addresses the root cause — not a workaround,
   not a broadened assertion, not a disabled or skipped test.
4. Re-run the same command to confirm, and say exactly what you ran.
5. If the failure turns out to be intermittent rather than deterministic, say
   so plainly instead of "fixing" it — that is a flaky test, and patching it
   hides the problem.

If the right move is to re-run the job rather than change code, use the job
link in the context below. For GitHub Actions: `gh run rerun <run-id> --failed`,
where the run ID is the number after `/runs/` in that URL (not the trailing
number, which is the job ID).

Branch: ygree/libdd-trace-inferrer

Lint | clippy #ubuntu-latest stable
Commit: 23ac8c22a487d4989dcda96265649f90415020b1
Error (code / build):
Compilation error in libdd-crashtracker/build.rs:54:43: redundant reference in `println!` argument; remove the redundant `&`: `dst_file`.
CI job: https://github.com/DataDog/libdatadog/actions/runs/33445533146/job/99663662957

Lint | clippy #windows-latest stable
Commit: 23ac8c22a487d4989dcda96265649f90415020b1
Error (code / build):
Usage of `unwrap_unchecked` when an `_unchecked` variant of the associated function exists in libdd-alloc\src\linear.rs:37.
CI job: https://github.com/DataDog/libdatadog/actions/runs/33445533146/job/99663663003

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 23ac8c2 | Docs | View more details | 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