Skip to content

Commit

Permalink
HPCC-32691 Add optional timestamp arg to createClientSpan() 3
Browse files Browse the repository at this point in the history
Signed-off-by: M Kelly <[email protected]>
  • Loading branch information
mckellyln committed Sep 24, 2024
1 parent a7b543c commit 3d612b0
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions testing/unittests/jlibtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ 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 @@ -232,6 +231,13 @@ class JlibTraceTest : public CppUnit::TestFixture
OwnedSpanScope serverSpan = queryTraceManager().createServerSpan("declaredSpanStartTime", emptyMockHTTPHeaders, &declaredSpanStartTime);
//{ "type": "span", "name": "declaredSpanStartTime", "trace_id": "0a2eff24e1996540056745aaeb2f5824", "span_id": "46d0faf8b4da893e",
//"start": 1702672311203213259, "duration": 125311051 }

SpanTimeStamp clientSpanTimeStamp;
clientSpanTimeStamp.now();
MilliSleep(20);
OwnedSpanScope clientSpan = serverSpan->createClientSpan("clientSpanStartTime", &clientSpanTimeStamp);
//{ "type": "span", "name": "clientSpanStartTime", "trace_id": "f73b171fdcd120f88ca5b656866befee", "span_id": "7c798125d10ee0ec",
//"start": 1727200325699918374, "duration": 20256156, "parent_span_id": "b79fe15b7d727fca" }
}

auto reqStartMSTick = msTick();
Expand All @@ -248,6 +254,14 @@ class JlibTraceTest : public CppUnit::TestFixture
nowTimeStamp.now();
{
OwnedSpanScope serverSpan = queryTraceManager().createServerSpan("msTickOffsetStartTime", emptyMockHTTPHeaders, &msTickOffsetTimeStamp);

unsigned clientStartMS = msTick();
MilliSleep(20);
SpanTimeStamp clientSpanTimeStamp;
clientSpanTimeStamp.setMSTickTime(clientStartMS);
OwnedSpanScope clientSpan = serverSpan->createClientSpan("clientSpanOffsetTime", &clientSpanTimeStamp);
//{ "type": "span", "name": "clientSpanOffsetTime", "trace_id": "9a41723ddc0048d854ab34b79340e749", "span_id": "11af70aa6a6dbee3",
//"start": 1727200325770619773, "duration": 20015542, "parent_span_id": "531ad336071f453b" }
}

DBGLOG("MsTickOffset span actual start-time timestamp: %lld", (long long)(nowTimeStamp.systemClockTime).count());
Expand Down Expand Up @@ -483,33 +497,11 @@ class JlibTraceTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_MESSAGE("Mismatched localParentSpanID detected",
strsame(serverSpanID, retrievedSpanCtxAttributes->queryProp("localParentSpanID")));

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

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_EQUAL_MESSAGE("Unexpected missing remoteParentID detected", true,
retrievedSpanCtxAttributes->hasProp("remoteParentID"));

CPPUNIT_ASSERT_MESSAGE("Mismatched localParentSpanID detected",
strsame(serverSpanID, retrievedSpanCtxAttributes->queryProp("localParentSpanID")));
CPPUNIT_ASSERT_MESSAGE("Unexpected CallerID detected",
strsame(serverTraceID, retrievedSpanCtxAttributes->queryProp("remoteParentID")));

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

0 comments on commit 3d612b0

Please sign in to comment.