Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the trace flags optional when parsing x-cloud-trace-context #350

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public final class XCloudTraceContextPropagator implements TextMapPropagator {
private static final String FIELD = "x-cloud-trace-context";
private static final Collection<String> FIELDS = Collections.singletonList(FIELD);
private static final Pattern VALUE_PATTERN =
Pattern.compile("(?<traceid>[0-9a-f]{32})\\/(?<spanid>[\\d]{1,20});o=(?<sampled>\\d+)");
Pattern.compile("(?<traceid>[0-9a-f]{32})\\/(?<spanid>[\\d]{1,20})(;o=(?<sampled>\\d+))?");
private static final Logger LOGGER =
Logger.getLogger(XCloudTraceContextPropagator.class.getCanonicalName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ public void testExtractNotSampled() {
Assert.assertEquals(false, span.getSpanContext().getTraceFlags().isSampled());
}

@Test
public void testExtractWithoutTraceFlags() {
Context context = Context.root();
Map<String, String> carrier = new HashMap<>();
carrier.put("x-cloud-trace-context", "00000000000000000000000000000010/15");
TextMapPropagator propagator = new XCloudTraceContextPropagator(false);

// Now try to extract the value.
Context updated = propagator.extract(context, carrier, GETTER);
Span span = Span.fromContext(updated);
Assert.assertNotNull(span);
Assert.assertEquals("00000000000000000000000000000010", span.getSpanContext().getTraceId());
Assert.assertEquals("000000000000000f", span.getSpanContext().getSpanId());
Assert.assertEquals(false, span.getSpanContext().getTraceFlags().isSampled());
}

@Test
public void testNotInjectOneway() {
Span span =
Expand Down
Loading