Skip to content

Commit

Permalink
HPCC-32961 OwnedSpanScope assignment causes early span end
Browse files Browse the repository at this point in the history
- Added OwnedSpanScope assignment operator for ISpan*
- Deleted OwnedSpanScope copy constructor and assignment operator

Signed-off-by: James McMullan [email protected]
  • Loading branch information
jpmcmu committed Nov 15, 2024
1 parent 7067a3c commit 7b01729
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions system/jlib/jtrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,23 @@ class jlib_decl OwnedSpanScope
public:
OwnedSpanScope() = default;
OwnedSpanScope(ISpan * _ptr);
OwnedSpanScope(const OwnedSpanScope& rhs) = delete;
OwnedSpanScope(OwnedSpanScope&& rhs) = default;
~OwnedSpanScope();

inline ISpan * operator -> () const { return span; }
inline operator ISpan *() const { return span; }

inline OwnedSpanScope& operator=(ISpan * ptr) = delete;
inline OwnedSpanScope& operator=(const OwnedSpanScope& rhs) = delete;
inline OwnedSpanScope& operator=(OwnedSpanScope&& rhs)
{
setown(rhs.span.getClear());
prevSpan = rhs.prevSpan;

return *this;
}

void clear();
ISpan * query() const { return span; }
void set(ISpan * _span);
Expand Down
11 changes: 11 additions & 0 deletions testing/unittests/jlibtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,17 @@ class JlibTraceTest : public CppUnit::TestFixture
//"start": 1702668157790080022,
//"duration": 75316248 }
}

{
OwnedSpanScope serverSpan;
serverSpan = std::move(OwnedSpanScope(queryTraceManager().createServerSpan("movedSpanAssignment", emptyMockHTTPHeaders, &uninitializedTS)));
//sleep for 75 milliseconds after span creation, expect at least 75 milliseconds duration output
MilliSleep(75);

//14:22:37.865509 30396 { "type": "span", "name": "uninitializeddeclaredSpanStartTime", "trace_id": "f7844c5c09b413e008f912ded0e12dec", "span_id": "7fcf9042a090c663",
//"start": 1702668157790080022,
//"duration": 75316248 }
}
}

//not able to programmatically test yet, but can visually inspect trace output
Expand Down

0 comments on commit 7b01729

Please sign in to comment.