Skip to content

Commit

Permalink
HPCC-33163 Avoid wasteful invalid Span log entries
Browse files Browse the repository at this point in the history
- Adds ISpan isValid method
- Avoids wasteful log outpus if span !isValid

Signed-off-by: Rodrigo Pastrana <[email protected]>
  • Loading branch information
rpastrana committed Jan 22, 2025
1 parent 045afbd commit fa042bf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions system/jlib/jlog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions system/jlib/jtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,15 @@ class CSpan : public CInterfaceOf<ISpan>
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)
Expand Down Expand Up @@ -910,6 +919,7 @@ class CNullSpan final : public CInterfaceOf<ISpan>
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 {};
Expand Down
1 change: 1 addition & 0 deletions system/jlib/jtrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fa042bf

Please sign in to comment.