diff --git a/changelog/@unreleased/pr-1016.v2.yml b/changelog/@unreleased/pr-1016.v2.yml new file mode 100644 index 000000000..775ae344c --- /dev/null +++ b/changelog/@unreleased/pr-1016.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: Log at debug when `completeSpan` methods are used with no active trace + links: + - https://github.com/palantir/tracing-java/pull/1016 diff --git a/tracing/src/main/java/com/palantir/tracing/Tracer.java b/tracing/src/main/java/com/palantir/tracing/Tracer.java index b5fbc4a4d..d425b801c 100644 --- a/tracing/src/main/java/com/palantir/tracing/Tracer.java +++ b/tracing/src/main/java/com/palantir/tracing/Tracer.java @@ -640,6 +640,11 @@ public static void fastCompleteSpan(TagTranslator tag, T state) { if (trace.isObservable()) { completeSpanAndNotifyObservers(span, tag, state, trace.getTraceId()); } + } else if (log.isDebugEnabled()) { + log.debug( + "Attempted to complete spans when there is no active Trace. This may be the " + + "result of calling completeSpan more times than startSpan", + new SafeRuntimeException("not a real exception")); } } @@ -671,6 +676,12 @@ public static Optional completeSpan() { public static Optional completeSpan(@Safe Map metadata) { Trace trace = currentTrace.get(); if (trace == null) { + if (log.isDebugEnabled()) { + log.debug( + "Attempted to complete spans when there is no active Trace. This may be the " + + "result of calling completeSpan more times than startSpan", + new SafeRuntimeException("not a real exception")); + } return Optional.empty(); } Optional maybeSpan = popCurrentSpan(trace)