Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ endif::[]
events. With the new `OVERRIDE` option, non-file logs can be ECS-reformatted automatically as well - {pull}1793[#1793]
* Instrumentation for Vert.x Web {pull}1697[#1697]
* Changed log level of vm arguments to debug
* Giving precedence for the W3C `tracecontext` header over the `elastic-apm-traceparent` header - {pull}1821[#1821]

[float]
===== Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ public boolean asChildOf(TraceContext child, @Nullable Object carrier, TextHeade
}

boolean isValid = false;
String traceparent = traceContextHeaderGetter.getFirstHeader(ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, carrier);
String traceparent = traceContextHeaderGetter.getFirstHeader(W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, carrier);
if (traceparent != null) {
isValid = child.asChildOf(traceparent);
}

if (!isValid) {
// Look for the legacy Elastic traceparent header (in case this comes from an older agent)
traceparent = traceContextHeaderGetter.getFirstHeader(W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, carrier);
traceparent = traceContextHeaderGetter.getFirstHeader(ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, carrier);
if (traceparent != null) {
isValid = child.asChildOf(traceparent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ void testChildOfElasticTraceparentHeader() {
}

@Test
void testElasticTraceparentHeaderPrecedence() {
void testW3CTraceparentHeaderPrecedence() {
Map<String, String> textHeaderMap = Map.of(
TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01",
TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-dd8448eb211c80319c0af7651916cd43-f97918e1b9c7c989-00"
TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-00",
TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-dd8448eb211c80319c0af7651916cd43-f97918e1b9c7c989-01"
);
final TraceContext child = TraceContext.with64BitId(tracer);
assertThat(TraceContext.<Map<String, String>>getFromTraceContextTextHeaders().asChildOf(child, textHeaderMap, TextHeaderMapAccessor.INSTANCE)).isTrue();
assertThat(child.getTraceId().toString()).isEqualTo("dd8448eb211c80319c0af7651916cd43");
assertThat(child.getParentId().toString()).isEqualTo("f97918e1b9c7c989");
assertThat(child.getTraceId().toString()).isEqualTo("0af7651916cd43dd8448eb211c80319c");
assertThat(child.getParentId().toString()).isEqualTo("b9c7c989f97918e1");
assertThat(child.getId()).isNotEqualTo(child.getParentId());
assertThat(child.isSampled()).isFalse();
}
Expand Down