Skip to content

Tag http.status_code on AWS SDK spans for non-2xx service errors - #12749

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
yeison.casado/aws-sdk-error-status-code
Oct 5, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
yeison.casado/aws-sdk-error-status-code

Conversation

@Yeison2020

@Yeison2020 Yeison2020 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Sets http.status_code on AWS SDK v1 and v2 spans when the call fails with a non-2xx service error (403, 404 NoSuchKey/NoSuchBucket, 409, 429, 503, ...). Before this, those spans were marked as errors but carried no status code.

Motivation

The status code is only set by HttpClientDecorator.onResponse, which needs a response object. On a service error neither SDK hands one to the tracer:

  • v1: TracingRequestHandler.afterError receives a null Response, because AmazonHttpClient only assigns it after executeHelper() returns, and a service error throws from inside it.
  • v2: TracingExecutionInterceptor.onExecutionFailure only looked at FailedExecution.response(), which is empty when the response could not be unmarshalled into an SdkResponse.

So those spans fell into the exception-only branch. The status was only visible in error.message, and client-side stats grouped these calls with no HTTP status, so a 404 and a 503 on the same resource were indistinguishable.

The fix reads the status from AmazonServiceException.getStatusCode() (v1) and SdkServiceException.statusCode() (v2) on that branch. Error marking is unchanged: the span is still an error from the exception, including for 3xx and 5xx that are outside DD_TRACE_HTTP_CLIENT_ERROR_STATUSES.

Additional Notes

New JUnit 5 tests (Aws1ErrorStatusCodeTest, Aws2ErrorStatusCodeTest) run SQS CreateQueue against a local server returning 301, 307, 400 through 499 (a spread of codes) and 500 through 504, and S3 GetObjectMetadata (HEAD, no error body) on v1. They failed on master with http.status_code unset for every code and pass with this change. test, forkedTest, latestDepTest, test_before_1_11_106 and muzzle pass for both modules.

I also checked it end to end with a sample app (APMS-20698 repro) using SDK v1 against LocalStack (2xx and real 404s) and a mock S3 endpoint forcing other codes, for S3.PutObject, S3.GetObject, S3.GetObjectMetadata, S3.ListObjectsV2, S3.DeleteObjects and S3.DeleteObject. With 1.66.0 only the 2xx calls had a status code. With this branch every non-2xx call had the right http.status_code on the span and in the client-side stats. I also captured the stats payload the Datadog Agent forwarded to the intake for a 1000 call run, and HTTPStatusCode was set for every call.

Contributor Checklist

Jira ticket: APMS-20698

When an AWS call fails with a non-2xx status (404 NoSuchKey, 403, 503, ...)
the SDK reports it as a service exception and the tracer only recorded the
exception. In SDK v1 TracingRequestHandler.afterError gets a null response,
and in SDK v2 FailedExecution.response() is empty, so the HttpClientDecorator
path that sets http.status_code never ran. The span was marked as an error
but had no status code, and client-side stats bucketed these calls with no
HTTP status.

Read the status from AmazonServiceException (v1) and SdkServiceException (v2)
on that path. Error marking is unchanged.
@Yeison2020 Yeison2020 added type: bug fix Bug fix inst: aws sdk AWS SDK instrumentation tag: ai generated Largely based on code generated by an AI or LLM labels Oct 5, 2026
@datadog-datadog-prod-us1

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 68.82% (+9.54%)

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

@Yeison2020
Yeison2020 marked this pull request as ready for review October 5, 2026 15:07
@Yeison2020
Yeison2020 requested a review from a team as a code owner October 5, 2026 15:07
@Yeison2020
Yeison2020 requested review from a team and jordan-wong and removed request for a team October 5, 2026 15:07
@dd-octo-sts

dd-octo-sts Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.04 s 13.97 s [-0.3%; +1.4%] (no difference)
startup:insecure-bank:tracing:Agent 12.88 s 13.07 s [-2.3%; -0.6%] (maybe better)
startup:petclinic:appsec:Agent 17.32 s 17.28 s [-0.8%; +1.2%] (no difference)
startup:petclinic:iast:Agent 17.12 s 17.18 s [-1.0%; +0.2%] (no difference)
startup:petclinic:profiling:Agent 16.93 s 16.91 s [-1.4%; +1.6%] (no difference)
startup:petclinic:sca:Agent 17.36 s 17.11 s [+0.5%; +2.5%] (maybe worse)
startup:petclinic:tracing:Agent 16.33 s 16.17 s [-0.0%; +2.0%] (no difference)

Commit: 61488397 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@Yeison2020

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 61488397de

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

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot 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.

Bits Code Review: PASS

More details

The changed failure branches tag positive status codes only from AWS service exceptions when no response exists, preserving the existing response and error handling for both SDK generations.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 6148839 · @DataDog review to ask questions

@purple4reina purple4reina 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.

I deployed a lambda function that makes two aws-sdk calls, both S3, one to a known bucket (200) and one to a fake bucket (404). When using the most recently released java lambda layer, I do not see the 404 http.status_code, but when I package this branch up as a layer, I do.

@Yeison2020
Yeison2020 added this pull request to the merge queue Oct 5, 2026
@dd-octo-sts

dd-octo-sts Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-10-05 20:24:23 UTC ℹ️ Start processing command /merge


2026-10-05 20:24:27 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-10-05 21:38:49 UTC ℹ️ MergeQueue: This merge request was merged

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 5, 2026
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 1380b85 into master Oct 5, 2026
621 of 637 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the yeison.casado/aws-sdk-error-status-code branch October 5, 2026 21:38
@github-actions github-actions Bot added this to the 1.67.0 milestone Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: aws sdk AWS SDK instrumentation tag: ai generated Largely based on code generated by an AI or LLM type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants