Skip to content

Commit aa3f790

Browse files
Checking if span is valid before attaching the baggage to the context
see: micrometer-metrics/tracing#62
1 parent 1e749ef commit aa3f790

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

spring-cloud-sleuth-otel/src/main/java/org/springframework/cloud/sleuth/otel/bridge/Slf4jBaggageApplicationListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.stream.Collectors;
2121

2222
import io.opentelemetry.api.baggage.Baggage;
23+
import io.opentelemetry.api.trace.Span;
2324
import org.apache.commons.logging.Log;
2425
import org.apache.commons.logging.LogFactory;
2526
import org.slf4j.MDC;
@@ -45,7 +46,8 @@ private void onScopeAttached(EventPublishingContextWrapper.ScopeAttachedEvent ev
4546
if (log.isTraceEnabled()) {
4647
log.trace("Got scope attached event [" + event + "]");
4748
}
48-
if (event.getBaggage() != null) {
49+
Span span = event.getSpan();
50+
if (event.getBaggage() != null && span != null && span.getSpanContext().isValid()) {
4951
putEntriesIntoMdc(event.getBaggage());
5052
}
5153
}

0 commit comments

Comments
 (0)