Skip to content

Commit 51f57f8

Browse files
Merge 1b7a0f3 into ee747ae
2 parents ee747ae + 1b7a0f3 commit 51f57f8

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

sentry/src/main/java/io/sentry/SentryTraceHeader.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)