Skip to content

Commit

Permalink
HPCC-32691 Add optional timestamp arg to createClientSpan() 2
Browse files Browse the repository at this point in the history
Signed-off-by: M Kelly <[email protected]>
  • Loading branch information
mckellyln committed Sep 19, 2024
1 parent efa28e8 commit 8aebdec
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
26 changes: 13 additions & 13 deletions system/jlib/jtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ class CSpan : public CInterfaceOf<ISpan>
}

ISpan * createClientSpan(const char * name, const SpanTimeStamp * spanStartTimeStamp = nullptr) override;
ISpan * createInternalSpan(const char * name) override;
ISpan * createInternalSpan(const char * name, const SpanTimeStamp * spanStartTimeStamp = nullptr) override;

virtual void endSpan() final override
{
Expand Down Expand Up @@ -919,7 +919,7 @@ class CNullSpan final : public CInterfaceOf<ISpan>
virtual const char* queryLocalId() const override { return nullptr; }

virtual ISpan * createClientSpan(const char * name, const SpanTimeStamp * spanStartTimeStamp = nullptr) override { return getNullSpan(); }
virtual ISpan * createInternalSpan(const char * name) override { return getNullSpan(); }
virtual ISpan * createInternalSpan(const char * name, const SpanTimeStamp * spanStartTimeStamp = nullptr) override { return getNullSpan(); }

private:
CNullSpan(const CNullSpan&) = delete;
Expand All @@ -930,9 +930,14 @@ class CNullSpan final : public CInterfaceOf<ISpan>
class CChildSpan : public CSpan
{
protected:
CChildSpan(const char * spanName, CSpan * parent)
CChildSpan(const char * spanName, CSpan * parent, const SpanTimeStamp *spanStartTimeStamp = nullptr)
: CSpan(spanName), localParentSpan(parent)
{
if (spanStartTimeStamp && spanStartTimeStamp->isInitialized())
{
opts.start_system_time = opentelemetry::common::SystemTimestamp(spanStartTimeStamp->systemClockTime);
opts.start_steady_time = opentelemetry::common::SteadyTimestamp(spanStartTimeStamp->steadyClockTime);
}
injectlocalParentSpan(localParentSpan);
}

Expand Down Expand Up @@ -984,8 +989,8 @@ class CChildSpan : public CSpan
class CInternalSpan : public CChildSpan
{
public:
CInternalSpan(const char * spanName, CSpan * parent)
: CChildSpan(spanName, parent)
CInternalSpan(const char * spanName, CSpan * parent, const SpanTimeStamp * spanStartTimeStamp = nullptr)
: CChildSpan(spanName, parent, spanStartTimeStamp)
{
opts.kind = opentelemetry::trace::SpanKind::kInternal;
init(SpanFlags::None);
Expand All @@ -1002,13 +1007,8 @@ class CClientSpan : public CChildSpan
{
public:
CClientSpan(const char * spanName, CSpan * parent, const SpanTimeStamp * spanStartTimeStamp = nullptr)
: CChildSpan(spanName, parent)
: CChildSpan(spanName, parent, spanStartTimeStamp)
{
if (spanStartTimeStamp && spanStartTimeStamp->isInitialized())
{
opts.start_system_time = opentelemetry::common::SystemTimestamp(spanStartTimeStamp->systemClockTime);
opts.start_steady_time = opentelemetry::common::SteadyTimestamp(spanStartTimeStamp->steadyClockTime);
}
opts.kind = opentelemetry::trace::SpanKind::kClient;
init(SpanFlags::None);
}
Expand All @@ -1025,9 +1025,9 @@ ISpan * CSpan::createClientSpan(const char * name, const SpanTimeStamp * spanSta
return new CClientSpan(name, this, spanStartTimeStamp);
}

ISpan * CSpan::createInternalSpan(const char * name)
ISpan * CSpan::createInternalSpan(const char * name, const SpanTimeStamp * spanStartTimeStamp)
{
return new CInternalSpan(name, this);
return new CInternalSpan(name, this, spanStartTimeStamp);
}

class CServerSpan : public CSpan
Expand Down
2 changes: 1 addition & 1 deletion system/jlib/jtrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ interface ISpan : extends IInterface
virtual const char * querySpanId() const = 0;

virtual ISpan * createClientSpan(const char * name, const SpanTimeStamp * spanStartTimeStamp = nullptr) = 0;
virtual ISpan * createInternalSpan(const char * name) = 0;
virtual ISpan * createInternalSpan(const char * name, const SpanTimeStamp * spanStartTimeStamp = nullptr) = 0;

//Old-style global/caller/local id interface functions
virtual const char* queryGlobalId() const = 0;
Expand Down
31 changes: 27 additions & 4 deletions testing/unittests/jlibtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class JlibTraceTest : public CppUnit::TestFixture
CPPUNIT_TEST(testPropegatedServerSpan);
CPPUNIT_TEST(testInvalidPropegatedServerSpan);
CPPUNIT_TEST(testInternalSpan);
CPPUNIT_TEST(testClientSpan);
CPPUNIT_TEST(testMultiNestedSpanTraceOutput);
CPPUNIT_TEST(testNullSpan);
CPPUNIT_TEST(testClientSpanGlobalID);
Expand Down Expand Up @@ -482,11 +483,33 @@ class JlibTraceTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_MESSAGE("Mismatched localParentSpanID detected",
strsame(serverSpanID, retrievedSpanCtxAttributes->queryProp("localParentSpanID")));

CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected missing remoteParentID detected", true,
retrievedSpanCtxAttributes->hasProp("remoteParentID"));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected GlobalID detected", false,
retrievedSpanCtxAttributes->hasProp(kGlobalIdHttpHeaderName));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected CallerID detected", false,
retrievedSpanCtxAttributes->hasProp(kCallerIdHttpHeaderName));

CPPUNIT_ASSERT_MESSAGE("Unexpected CallerID detected",
strsame(serverTraceID, retrievedSpanCtxAttributes->queryProp("remoteParentID")));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected Declared Parent SpanID detected", false,
retrievedSpanCtxAttributes->hasProp("remoteParentSpanID"));

CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected empty TraceID detected", false, isEmptyString(retrievedSpanCtxAttributes->queryProp("traceID")));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected empty SpanID detected", false, isEmptyString(retrievedSpanCtxAttributes->queryProp("spanID")));
}
}

{
unsigned startMs = msTick() - 1234;
SpanTimeStamp SpanTS;
SpanTS.setMSTickTime(startMs);
OwnedSpanScope clientSpan = serverSpan->createClientSpan("clientSpan", &SpanTS);
//retrieve clientSpan context with the intent to propogate otel and HPCC context
{
Owned<IProperties> retrievedSpanCtxAttributes = createProperties();
clientSpan->getSpanContext(retrievedSpanCtxAttributes);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected missing localParentSpanID detected", true,
retrievedSpanCtxAttributes->hasProp("localParentSpanID"));

CPPUNIT_ASSERT_MESSAGE("Mismatched localParentSpanID detected",
strsame(serverSpanID, retrievedSpanCtxAttributes->queryProp("localParentSpanID")));

CPPUNIT_ASSERT_EQUAL_MESSAGE("Unexpected GlobalID detected", false,
retrievedSpanCtxAttributes->hasProp(kGlobalIdHttpHeaderName));
Expand Down

0 comments on commit 8aebdec

Please sign in to comment.