Skip to content

test(appsec): read lambda inferred-span AppSec data from the service-entry span#7176

Closed
zarirhamza wants to merge 1 commit into
mainfrom
zarir/lambda-inferred-span-appsec-service-entry
Closed

test(appsec): read lambda inferred-span AppSec data from the service-entry span#7176
zarirhamza wants to merge 1 commit into
mainfrom
zarir/lambda-inferred-span-appsec-service-entry

Conversation

@zarirhamza

Copy link
Copy Markdown
Contributor

Motivation

Test_Lambda_Inferred_Span_Tags::test_lambda_inferred_span asserts the AppSec report is on the aws.lambda span. With the Serverless Service Representation (SSR) work, the inferred API Gateway span now uses DD_SERVICE (the same service as the function span). Because _dd.top_level / service-entry is computed by comparing a span's service to its parent's, the inferred span becomes the service-entry span and AppSec attaches its report there instead of on the downstream aws.lambda span.

This makes the test fail (UnboundLocalError — no AppSec data found on the aws.lambda span) for the Python lambda layer once the inferred-span service change ships (see DataDog/datadog-lambda-python#834).

Change

Capture the reference AppSec payload from whichever span is the service-entry span: the aws.lambda span (older behavior / other tracers) or the inferred span (new SSR behavior). The inferred-span validation is unchanged.

This keeps the test green for:

  • Older Python layer versions (AppSec on aws.lambda, mirrored to the inferred span)
  • New Python layer versions (AppSec on the inferred service-entry span)

Note: this test is missing_feature for nodejs/java lambda, so only Python is affected.

Test plan

  • APPSEC_LAMBDA_INFERRED_SPANS scenario passes for python_lambda apigw-rest and apigw-http with the SSR inferred-span service change

…y span

The AppSec report is carried by the service-entry (top-level) span. With
serverless service representation, the inferred API Gateway span shares the
function's service and becomes the service-entry span, so the AppSec report
moves there from the aws.lambda span. Accept the AppSec reference data from
either span so the test holds across layer versions.
@github-actions

Copy link
Copy Markdown
Contributor

CODEOWNERS have been resolved as:

tests/appsec/test_inferred_spans.py                                     @DataDog/asm-libraries @DataDog/system-tests-core

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jun 18, 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: dd23604 | Docs | Datadog PR Page | Give us feedback!

@datadog-system-tests-org

datadog-system-tests-org Bot commented Jun 18, 2026

Copy link
Copy Markdown

Pipelines

⚠️ Warnings

🚦 1 Pipeline job failed

Testing the test | all-jobs-are-green   View in Datadog   GitHub Actions

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: dd23604 | Docs | Give us feedback!

@zarirhamza zarirhamza marked this pull request as ready for review June 18, 2026 19:28
@zarirhamza zarirhamza requested review from a team as code owners June 18, 2026 19:28

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dd236049b5

ℹ️ 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".

for _, _, span, appsec_data in interfaces.library.get_appsec_events(self.r):
if span.get("name") == "aws.lambda":
lambda_span_appsec_data = appsec_data
if span.get("name") == "aws.lambda" or span.get("name") in INFERRED_SPAN_NAMES:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Search the full trace for inferred AppSec data

When AppSec moves onto the inferred API Gateway span, adding the inferred names here is not enough because get_appsec_events(self.r) still uses full_trace=False; utils/interfaces/_library/core.py::get_spans then yields only spans whose extracted request id matches the response. In Lambda traces where the request id remains on aws.lambda but the AppSec payload is only on aws.apigateway/aws.httpapi, this loop never sees the new service-entry span and the assertion below still fails, so this should read events with full_trace=True like the inferred-span validation does.

Useful? React with 👍 / 👎.

@zarirhamza zarirhamza closed this Jun 18, 2026
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.

1 participant