Skip to content

feat: inferred alb spans#838

Merged
chemystery09 merged 7 commits into
mainfrom
ishara/alb-inferred-span-frsles-851
Jul 1, 2026
Merged

feat: inferred alb spans#838
chemystery09 merged 7 commits into
mainfrom
ishara/alb-inferred-span-frsles-851

Conversation

@chemystery09

@chemystery09 chemystery09 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add create_inferred_span_from_alb_event to emit an inferred aws.alb span (span_type=http, span.kind=server) for ALB-triggered Lambdas, with HTTP request tags (http.method, http.url, http.useragent, etc.).
  • Wire the ALB dispatcher in create_inferred_span on event_type == EventTypes.ALB so both subtypes are covered: single-value headers and multiValueHeaders.
  • Add resolve_alb_request_headers to flatten multiValueHeaders (first value per key, matching datadog-lambda-js) for span creation, HTTP tag extraction, and inbound trace propagation.
  • Fix extract_http_tags for ALB events (no requestContext.stage) so http.url, http.route, and http.useragent are populated and copied onto the inferred span by the wrapper post-response (http.status_code, http.route, peer.service, dd_resource_key).

Closes FRSLES-851.

Test plan

  • pytest tests/test_trigger.py -k application_load_balancer -v
  • pytest tests/test_tracing.py::TestAlbInferredSpan -v
  • pytest tests/test_wrapper.py::TestAlbInferredSpanWrapper -v
  • Single-value and multiValueHeaders ALB fixtures (inferred span, HTTP tags, Datadog + W3C propagation)
  • Wrapper lifecycle: http.status_code, http.route, 5xx errors, peer.service, dd_resource_key, make_inferred_span=False
  • Validate on real AWS ALB + Lambda and attach before/after Datadog trace screenshots (HTTP Requests panel on aws.alb)

Test traces:

Before

image

After
image
image

chemystery09 and others added 2 commits June 25, 2026 16:35
When a Lambda is invoked behind an Application Load Balancer, create an
inferred aws.alb span with HTTP request tags and populate ALB HTTP facet
tags for http.url, http.route, and http.useragent.

FRSLES-851 / APMSVLS-542

Co-authored-by: Cursor <cursoragent@cursor.com>
Cover ALB inferred-span creation, service mapping, inbound trace context,
HTTP trigger tags, and full wrapper lifecycle including status code and
parent/child linkage.

FRSLES-851 / APMSVLS-542

Co-authored-by: Cursor <cursoragent@cursor.com>
@datadog-prod-us1-6

This comment has been minimized.

chemystery09 and others added 2 commits June 26, 2026 13:30
Handle both ALB event subtypes via resolve_alb_request_headers, fix
inbound trace propagation from multiValueHeaders, and expand unit/wrapper
coverage for HTTPS URLs, peer.service, and dd_resource_key.

FRSLES-851

Co-authored-by: Cursor <cursoragent@cursor.com>
Collapse http_url assignment and reformat TestAlbInferredSpanWrapper tests
so check_format.sh passes.

FRSLES-851

Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds first-class inferred tracing support for Application Load Balancer (ALB)–triggered Lambdas by creating an aws.alb inferred span and ensuring HTTP tag extraction + inbound trace propagation work for both single-value headers and multiValueHeaders ALB event shapes.

Changes:

  • Add ALB inferred span creation (aws.alb, span_type=http, span.kind=server) and wire it into create_inferred_span.
  • Introduce resolve_alb_request_headers to flatten ALB multiValueHeaders for span creation, HTTP tag extraction, and context propagation.
  • Fix extract_http_tags for ALB events so http.url, http.route, and http.useragent are populated; add/extend tests for inferred spans, mapping, propagation, and wrapper lifecycle.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
datadog_lambda/trigger.py Adds ALB header resolution and improves ALB HTTP tag extraction logic.
datadog_lambda/tracing.py Adds ALB inferred span creation and enables context extraction for ALB multiValueHeaders.
tests/test_trigger.py Extends trigger tag assertions for ALB and adds a multivalue-headers test.
tests/test_tracing.py Adds ALB to propagation coverage and introduces a dedicated inferred-span test suite for ALB.
tests/test_wrapper.py Adds end-to-end wrapper tests validating ALB inferred span behavior and tag copying.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread datadog_lambda/trigger.py
chemystery09 and others added 2 commits June 26, 2026 16:05
Reuse resolve_alb_request_headers for referer tagging so multiValueHeaders
events and lowercase referer keys are handled consistently with other ALB
HTTP facet tags.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@chemystery09 chemystery09 marked this pull request as ready for review June 26, 2026 20:12
@chemystery09 chemystery09 requested review from a team as code owners June 26, 2026 20:12
@chemystery09 chemystery09 changed the title feat: emit inferred aws.alb span for ALB-triggered Lambdas feat: inferred alb spans Jun 30, 2026
@ojproductions

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 8fb563cae2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ojproductions ojproductions left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks really good. Just a couple nits

Comment thread datadog_lambda/trigger.py Outdated
return event_source_arn


def resolve_alb_request_headers(event):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be renamed to something like resolve_multivalue_headers as this function isnt specific to ALB

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread datadog_lambda/tracing.py Outdated
Comment on lines +200 to +205
headers = event.get("headers")
if not isinstance(headers, dict) or not headers:
if isinstance(event.get("multiValueHeaders"), dict):
headers = resolve_alb_request_headers(event)
else:
headers = {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic is a bit redundant. resolve_alb_request_headers is making the same checks. a simple
headers = resolve_alb_request_headers(event)
would probably work

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Address PR review feedback: the header resolver is not ALB-specific, and
extract_context_from_http_event_or_context can delegate to it directly.

Co-authored-by: Cursor <cursoragent@cursor.com>

@ojproductions ojproductions left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@chemystery09 chemystery09 merged commit 1abf3f2 into main Jul 1, 2026
104 checks passed
@chemystery09 chemystery09 deleted the ishara/alb-inferred-span-frsles-851 branch July 1, 2026 17:17
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