diff --git a/system/jlib/jlog.hpp b/system/jlib/jlog.hpp index b300f12038e..540e4bde8e6 100644 --- a/system/jlib/jlog.hpp +++ b/system/jlib/jlog.hpp @@ -608,7 +608,7 @@ class jlib_decl LogMsgTraceInfo const char * queryTraceID() const { - if (span) + if (span && span->isValid()) { const char * traceId = span->queryTraceId(); if (traceId) @@ -619,7 +619,7 @@ class jlib_decl LogMsgTraceInfo const char * querySpanID() const { - if (span) + if (span && span->isValid()) { const char * spanId = span->querySpanId(); if (spanId) diff --git a/system/jlib/jtrace.cpp b/system/jlib/jtrace.cpp index fdfb4058647..469c4380e7f 100644 --- a/system/jlib/jtrace.cpp +++ b/system/jlib/jtrace.cpp @@ -757,6 +757,15 @@ class CSpan : public CInterfaceOf return span ? span->IsRecording() : false; } + virtual bool isValid() const override + { + if (span == nullptr) + return false; + + auto spanCtx = span->GetContext(); + return spanCtx.IsValid(); + } + virtual void setSpanStatusSuccess(bool spanSucceeded, const char * statusMessage) { if (span != nullptr) @@ -910,6 +919,7 @@ class CNullSpan final : public CInterfaceOf virtual void toString(StringBuffer & out) const override {} virtual void getLogPrefix(StringBuffer & out) const override {} virtual bool isRecording() const { return false; } + virtual bool isValid() const { return false; } virtual void recordException(IException * e, bool spanFailed, bool escapedScope) override {} virtual void recordError(const SpanError & error) override {}; diff --git a/system/jlib/jtrace.hpp b/system/jlib/jtrace.hpp index 7f1e7d9431b..ff1619f9923 100644 --- a/system/jlib/jtrace.hpp +++ b/system/jlib/jtrace.hpp @@ -133,6 +133,7 @@ struct SpanTimeStamp interface ISpan : extends IInterface { + virtual bool isValid() const = 0; virtual void setSpanAttribute(const char * key, const char * val) = 0; virtual void setSpanAttribute(const char *name, __uint64 value) = 0; virtual void setSpanAttributes(const IProperties * attributes) = 0;