File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ public final class SentryTraceHeader {
1717
1818 final Pattern SENTRY_TRACEPARENT_HEADER_REGEX =
1919 Pattern .compile (
20- "^[ \\ t]*(?<traceId>[0-9a-f]{32})-(?<spanId>[0-9a-f]{16})-? (?<sampled>[01])?[ \\ t]*$" ,
20+ "^[ \\ t]*(?<traceId>[0-9a-f]{32})-(?<spanId>[0-9a-f]{16})(?<sampled>- [01])?[ \\ t]*$" ,
2121 Pattern .CASE_INSENSITIVE );
2222
2323 public SentryTraceHeader (
@@ -39,7 +39,8 @@ public SentryTraceHeader(final @NotNull String value) throws InvalidSentryTraceH
3939
4040 this .traceId = new SentryId (matcher .group ("traceId" ));
4141 this .spanId = new SpanId (matcher .group ("spanId" ));
42- this .sampled = matcher .group ("sampled" ) == null ? null : "1" .equals (matcher .group ("sampled" ));
42+ this .sampled =
43+ matcher .group ("sampled" ) == null ? null : "1" .equals (matcher .group ("sampled" ).substring (1 ));
4344 }
4445
4546 public @ NotNull String getName () {
Original file line number Diff line number Diff line change @@ -16,6 +16,18 @@ class SentryTraceHeaderTest {
1616 assertEquals(" sentry-trace header does not conform to expected format: $sentryId " , ex.message)
1717 }
1818
19+ @Test
20+ fun `when there is a trailing dash without sampling decision throws exception` () {
21+ val sentryId = SentryId ()
22+ val spanId = SpanId ()
23+ val ex =
24+ assertFailsWith<InvalidSentryTraceHeaderException > { SentryTraceHeader (" $sentryId -$spanId -" ) }
25+ assertEquals(
26+ " sentry-trace header does not conform to expected format: $sentryId -$spanId -" ,
27+ ex.message,
28+ )
29+ }
30+
1931 @Test
2032 fun `when trace-id has less than 32 characters throws exception` () {
2133 val sentryId = SentryId ().toString().substring(0 , 8 )
You can’t perform that action at this time.
0 commit comments