Skip to content

AwsXrayPropagator can create invalid trace headers during baggage propagation #563

Open
@davidconnard

Description

@davidconnard

Describe the bug
AwsXrayPropagator attempts to include baggage properties when creating the XRay trace header. It has code that attempts to limit the baggage to 256 characters, "as per the spec", but, that code can produce headers that are longer than 256 characters, triggering invalid requests to AWS.

see https://github.com/open-telemetry/opentelemetry-java-contrib/blob/main/aws-xray-propagator/src/main/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayPropagator.java#L130

According to https://docs.aws.amazon.com/ja_jp/step-functions/latest/apireference/API_StartExecution.html#API_StartExecution_RequestSyntax
the trace header spec appears to be 256 characters overall and not 256 characters for the remainder "baggage" bits of the header.

the AWS X-Ray trace header. The trace header can also be passed in the request payload.
Length Constraints: Minimum length of 0. Maximum length of 256.

So, AwsXrayPropagator should take into account the entire length of the trace header (so far) when deciding whether to append (further) baggage ... and not just the length of the baggage part of it. The logic is incorrectly only looking at the additional length from baggage.

Steps to reproduce
Send requests to the AWS SDK where there is a large baggage header in the tracing context.

What did you expect to see?
The AWS SDK call should work

What did you see instead?
The AWS SDK call fails, with errors such as:

Caused by: software.amazon.awssdk.services.sfn.model.ValidationException: 1 validation error detected: Value Root=1-00000000-000000009b10a2dc482684aa;Parent=d70e93f77b4a569c;Sampled=0;<244 characters of baggage contents redacted> failed to satisfy constraint: Member must have length less than or equal to 256 (Service: Sfn, Status Code: 400, Request ID: )

In this failed request, the baggage contents comprised of multiple properties, and the logic stopped appending when the baggage reached 244 characters. At this point, the overall header (which failed the request) was 320 characters long. So ... the truncation logic is working, but is failing to take into account the characters already in the trace header.

Additional context
This was reproduced against the SfnAsyncClient startExecutionRequest. I assume it is also reproducible against other AWS services - however, it may be that the Sfn service may be more aggressive than other services with the 256 character validation?

Metadata

Metadata

Assignees

Labels

X-RayAWS X-Ray components

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions