feat(libdd-trace-inferrer): add crate for AWS Lambda trigger span inference - #2327
Draft
ygree wants to merge 6 commits into
Draft
feat(libdd-trace-inferrer): add crate for AWS Lambda trigger span inference#2327ygree wants to merge 6 commits into
ygree wants to merge 6 commits into
Conversation
…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
🎉 All green!🧪 All tests passed 🔗 Commit SHA: 1080d34 | Docs | Datadog PR Page | Give us feedback! |
SNS-wrapped messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds a new
libdd-trace-inferrercrate 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
libdatadoglets 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-extensionBottlecap (bottlecap/src/lifecycle/invocation/triggers/*andspan_inferrer.rs) intolibdatadog.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, andcomplete_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