diff --git a/system/jlib/jtrace.cpp b/system/jlib/jtrace.cpp index f50e696c3f0..8ead5b470ca 100644 --- a/system/jlib/jtrace.cpp +++ b/system/jlib/jtrace.cpp @@ -557,7 +557,7 @@ class CSpan : public CInterfaceOf return spanID.get(); } - ISpan * createClientSpan(const char * name) override; + ISpan * createClientSpan(const char * name, const SpanTimeStamp * spanStartTimeStamp = nullptr) override; ISpan * createInternalSpan(const char * name) override; virtual void endSpan() final override @@ -918,7 +918,7 @@ class CNullSpan final : public CInterfaceOf virtual const char* queryCallerId() const override { return nullptr; } virtual const char* queryLocalId() const override { return nullptr; } - virtual ISpan * createClientSpan(const char * name) override { return getNullSpan(); } + virtual ISpan * createClientSpan(const char * name, const SpanTimeStamp * spanStartTimeStamp = nullptr) override { return getNullSpan(); } virtual ISpan * createInternalSpan(const char * name) override { return getNullSpan(); } private: @@ -1001,9 +1001,14 @@ class CInternalSpan : public CChildSpan class CClientSpan : public CChildSpan { public: - CClientSpan(const char * spanName, CSpan * parent) + CClientSpan(const char * spanName, CSpan * parent, const SpanTimeStamp * spanStartTimeStamp = nullptr) : CChildSpan(spanName, parent) { + 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); } @@ -1015,9 +1020,9 @@ class CClientSpan : public CChildSpan } }; -ISpan * CSpan::createClientSpan(const char * name) +ISpan * CSpan::createClientSpan(const char * name, const SpanTimeStamp * spanStartTimeStamp) { - return new CClientSpan(name, this); + return new CClientSpan(name, this, spanStartTimeStamp); } ISpan * CSpan::createInternalSpan(const char * name) diff --git a/system/jlib/jtrace.hpp b/system/jlib/jtrace.hpp index 85b6e3bb915..f0541534910 100644 --- a/system/jlib/jtrace.hpp +++ b/system/jlib/jtrace.hpp @@ -108,6 +108,29 @@ struct SpanError void setError(const char * _errorMessage, int _errorCode) { errorMessage = _errorMessage; errorCode = _errorCode; } }; +struct SpanTimeStamp +{ + std::chrono::nanoseconds steadyClockTime = std::chrono::nanoseconds::zero(); + std::chrono::nanoseconds systemClockTime = std::chrono::nanoseconds::zero(); + + void now() + { + systemClockTime = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); + steadyClockTime = std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()); + } + + void setMSTickTime(const unsigned int msTickTime) + { + systemClockTime = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch() - std::chrono::milliseconds(msTick() - msTickTime)); + steadyClockTime = std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch() - std::chrono::milliseconds(msTick() - msTickTime)); + } + + bool isInitialized() const + { + return systemClockTime != std::chrono::nanoseconds::zero(); + } +}; + interface ISpan : extends IInterface { virtual void setSpanAttribute(const char * key, const char * val) = 0; @@ -127,7 +150,7 @@ interface ISpan : extends IInterface virtual const char * queryTraceId() const = 0; virtual const char * querySpanId() const = 0; - virtual ISpan * createClientSpan(const char * name) = 0; + virtual ISpan * createClientSpan(const char * name, const SpanTimeStamp * spanStartTimeStamp = nullptr) = 0; virtual ISpan * createInternalSpan(const char * name) = 0; //Old-style global/caller/local id interface functions @@ -159,29 +182,6 @@ class jlib_decl OwnedSpanScope extern jlib_decl IProperties * getClientHeaders(const ISpan * span); extern jlib_decl IProperties * getSpanContext(const ISpan * span); -struct SpanTimeStamp -{ - std::chrono::nanoseconds steadyClockTime = std::chrono::nanoseconds::zero(); - std::chrono::nanoseconds systemClockTime = std::chrono::nanoseconds::zero(); - - void now() - { - systemClockTime = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); - steadyClockTime = std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()); - } - - void setMSTickTime(const unsigned int msTickTime) - { - systemClockTime = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch() - std::chrono::milliseconds(msTick() - msTickTime)); - steadyClockTime = std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch() - std::chrono::milliseconds(msTick() - msTickTime)); - } - - bool isInitialized() const - { - return systemClockTime != std::chrono::nanoseconds::zero(); - } -}; - interface ITraceManager : extends IInterface { virtual ISpan * createServerSpan(const char * name, const IProperties * httpHeaders, const SpanTimeStamp * spanStartTimeStamp, SpanFlags flags = SpanFlags::None) const = 0;