@@ -15,10 +15,10 @@ public final class SentryTraceHeader {
1515 private final @ NotNull SpanId spanId ;
1616 private final @ Nullable Boolean sampled ;
1717
18+ // Use numbered capture groups for Android API level < 26 compatibility
1819 private static final Pattern SENTRY_TRACEPARENT_HEADER_REGEX =
1920 Pattern .compile (
20- "^[ \\ t]*(?<traceId>[0-9a-f]{32})-(?<spanId>[0-9a-f]{16})(?<sampled>-[01])?[ \\ t]*$" ,
21- Pattern .CASE_INSENSITIVE );
21+ "^[ \\ t]*([0-9a-f]{32})-([0-9a-f]{16})(-[01])?[ \\ t]*$" , Pattern .CASE_INSENSITIVE );
2222
2323 public SentryTraceHeader (
2424 final @ NotNull SentryId traceId ,
@@ -33,14 +33,15 @@ public SentryTraceHeader(final @NotNull String value) throws InvalidSentryTraceH
3333 Matcher matcher = SENTRY_TRACEPARENT_HEADER_REGEX .matcher (value );
3434 boolean matchesExist = matcher .matches ();
3535
36- if (!matchesExist || matcher . group ( "traceId" ) == null || matcher . group ( "spanId" ) == null ) {
36+ if (!matchesExist ) {
3737 throw new InvalidSentryTraceHeaderException (value );
3838 }
3939
40- this .traceId = new SentryId (matcher .group ("traceId" ));
41- this .spanId = new SpanId (matcher .group ("spanId" ));
42- this .sampled =
43- matcher .group ("sampled" ) == null ? null : "1" .equals (matcher .group ("sampled" ).substring (1 ));
40+ this .traceId = new SentryId (matcher .group (1 ));
41+ this .spanId = new SpanId (matcher .group (2 ));
42+
43+ String sampled = matcher .group (3 );
44+ this .sampled = sampled == null ? null : "1" .equals (sampled .substring (1 ));
4445 }
4546
4647 public @ NotNull String getName () {
0 commit comments