Repository navigation
Tag http.status_code on AWS SDK spans for non-2xx service errors - #12749
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
Conversation
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.
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
There was a problem hiding this comment.
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.
🤖 Bits Code Review · Commit 6148839 · @DataDog review to ask questions
purple4reina
left a comment
There was a problem hiding this comment.
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.
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
1380b85
into
master
What Does This Do
Sets
http.status_codeon 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:TracingRequestHandler.afterErrorreceives a nullResponse, becauseAmazonHttpClientonly assigns it afterexecuteHelper()returns, and a service error throws from inside it.TracingExecutionInterceptor.onExecutionFailureonly looked atFailedExecution.response(), which is empty when the response could not be unmarshalled into anSdkResponse.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) andSdkServiceException.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 outsideDD_TRACE_HTTP_CLIENT_ERROR_STATUSES.Additional Notes
New JUnit 5 tests (
Aws1ErrorStatusCodeTest,Aws2ErrorStatusCodeTest) run SQSCreateQueueagainst a local server returning 301, 307, 400 through 499 (a spread of codes) and 500 through 504, and S3GetObjectMetadata(HEAD, no error body) on v1. They failed on master withhttp.status_codeunset for every code and pass with this change.test,forkedTest,latestDepTest,test_before_1_11_106andmuzzlepass 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.DeleteObjectsandS3.DeleteObject. With 1.66.0 only the 2xx calls had a status code. With this branch every non-2xx call had the righthttp.status_codeon 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, andHTTPStatusCodewas set for every call.Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: APMS-20698