Skip to content

Commit

Permalink
Fixes java.lang.IllegalStateException: Missing: traceId with AWS prop…
Browse files Browse the repository at this point in the history
…agation type within AWSExtractor (#203)

* add test to exploit issue #201

* add fix for #201 and #202 with corresponding unit tests
  • Loading branch information
BenitoVisone authored Dec 18, 2023
1 parent 8da16ce commit 0df46f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public TraceContextOrSamplingFlags extract(R request) {
} else if (c >= 'a' && c <= 'f') {
traceIdHigh |= c - 'a' + 10;
} else {
traceIdHigh = 0L;
break OUTER; // invalid format
}
}
Expand All @@ -136,6 +137,8 @@ public TraceContextOrSamplingFlags extract(R request) {
} else if (c >= 'a' && c <= 'f') {
traceId |= c - 'a' + 10;
} else {
traceIdHigh = 0L;
traceId = 0L;
break OUTER; // invalid format
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,18 @@ public void extract_skips_really_malformed() {

assertThat(extractor.extract(carrier).samplingFlags()).isEqualTo(SamplingFlags.EMPTY);
}

@Test
public void extract_malformed_check_not_throws_exception_different_length() {
carrier.put("x-amzn-trace-id", "Root=1-1373cbb-77f4b48ed7ff3eebbd62b5e01;Parent=1a4e96536a3ff131;Sampled=0");

assertThat(extractor.extract(carrier).samplingFlags()).isEqualTo(SamplingFlags.EMPTY);
}

@Test
public void extract_malformed_throws_exception_not_hexadecimal_value() {
carrier.put("x-amzn-trace-id", "Root=1-1z373cbb-77f4b48ed7ff3eebbd62b5e01;Parent=1a4e96536a3ff131;Sampled=0");

assertThat(extractor.extract(carrier).samplingFlags()).isEqualTo(SamplingFlags.EMPTY);
}
}

0 comments on commit 0df46f5

Please sign in to comment.