From d70263fe4017f8159360fc780781ede1d277a008 Mon Sep 17 00:00:00 2001 From: Alek Date: Mon, 17 Feb 2020 15:12:58 -0700 Subject: [PATCH 1/7] An extension of enum opentracing::SpanReferenceType, for a new Span. Only to copy traceID and (for non-root spans) spanID, because spanID for root spans == traceID.low() Signed-off-by: Oleksandr Bukaiev --- examples/App.cpp | 5 +++++ src/jaegertracing/Reference.h | 4 ++++ src/jaegertracing/Tracer.cpp | 24 ++++++++++++++++++++---- src/jaegertracing/Tracer.h | 10 ++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/examples/App.cpp b/examples/App.cpp index f7df8a2a..71c035f3 100644 --- a/examples/App.cpp +++ b/examples/App.cpp @@ -24,6 +24,11 @@ void tracedSubroutine(const std::unique_ptr& parentSpan) void tracedFunction() { + // jaegertracing::SpanContext spanContextWithUserIDs { {111, 222}, 333, 0, 0, {} }; // TraceId and SpanID must be != 0 + // auto span = opentracing::Tracer::Global()->StartSpan( + // "tracedFunction1", {jaegertracing::JaegerSpecific_UseTheseIDs(&spanContextWithUserIDs)}); + // // spanID of span is 222, not 333, because it's a root span + auto span = opentracing::Tracer::Global()->StartSpan("tracedFunction"); tracedSubroutine(span); } diff --git a/src/jaegertracing/Reference.h b/src/jaegertracing/Reference.h index 52277aea..e11629b1 100644 --- a/src/jaegertracing/Reference.h +++ b/src/jaegertracing/Reference.h @@ -30,6 +30,10 @@ namespace thrift { class SpanRef; } +// An extension of enum opentracing::SpanReferenceType, for a new Span. Only to copy traceID and (for non-root spans) spanID +// spanID for root spans == traceID.low() +const static int SpanReferenceType_JaegerSpecific_UseTheseIDs = 99; + class Reference { public: using Type = opentracing::SpanReferenceType; diff --git a/src/jaegertracing/Tracer.cpp b/src/jaegertracing/Tracer.cpp index 1fb6087a..64ec8e4d 100644 --- a/src/jaegertracing/Tracer.cpp +++ b/src/jaegertracing/Tracer.cpp @@ -67,6 +67,7 @@ Tracer::StartSpanWithOptions(string_view operationName, try { const auto result = analyzeReferences(options.references); const auto* parent = result._parent; + const auto* self = result._self; const auto& references = result._references; std::vector samplerTags; @@ -75,10 +76,19 @@ Tracer::StartSpanWithOptions(string_view operationName, if (!parent || !parent->isValid()) { newTrace = true; auto highID = static_cast(0); - if (_options & kGen128BitOption) { - highID = randomID(); + auto lowID = static_cast(0); + if (self) { + highID = self->traceID().high(); + lowID = self->traceID().low(); } - const TraceID traceID(highID, randomID()); + else { + if (_options & kGen128BitOption) { + highID = randomID(); + } + lowID = randomID(); + } + const TraceID traceID(highID, lowID); + // self.spanID is ignored for the root span const auto spanID = traceID.low(); const auto parentID = 0; auto flags = static_cast(0); @@ -101,7 +111,7 @@ Tracer::StartSpanWithOptions(string_view operationName, } else { const auto traceID = parent->traceID(); - const auto spanID = randomID(); + const auto spanID = self ? self->spanID() : randomID(); const auto parentID = parent->spanID(); const auto flags = parent->flags(); ctx = SpanContext(traceID, spanID, parentID, flags, StrMap()); @@ -194,6 +204,12 @@ Tracer::analyzeReferences(const std::vector& references) const continue; } + if (static_cast(ref.first) == SpanReferenceType_JaegerSpecific_UseTheseIDs) + { + result._self = ctx; + continue; // not a reference + } + result._references.emplace_back(Reference(*ctx, ref.first)); if (!hasParent) { diff --git a/src/jaegertracing/Tracer.h b/src/jaegertracing/Tracer.h index b0619696..e52abf4b 100644 --- a/src/jaegertracing/Tracer.h +++ b/src/jaegertracing/Tracer.h @@ -273,11 +273,13 @@ class Tracer : public opentracing::Tracer, struct AnalyzedReferences { AnalyzedReferences() : _parent(nullptr) + , _self(nullptr) , _references() { } const SpanContext* _parent; + const SpanContext* _self; std::vector _references; }; @@ -301,6 +303,14 @@ class Tracer : public opentracing::Tracer, int _options; }; + +// JaegerSpecific_Self returns a StartSpanOption pointing to the Span that should be used as the started span context +// +// See opentracing::SpanReference +inline opentracing::SpanReference JaegerSpecific_UseTheseIDs(const opentracing::SpanContext* span_context) noexcept { + return {static_cast(SpanReferenceType_JaegerSpecific_UseTheseIDs), span_context}; +} + } // namespace jaegertracing #endif // JAEGERTRACING_TRACER_H From af121320e32922b33c6241270254a19ab2336dcb Mon Sep 17 00:00:00 2001 From: Oleksandr Bukaiev Date: Mon, 17 Feb 2020 17:40:07 -0700 Subject: [PATCH 2/7] 1) Renamed useTheseIDs to SelfRef, for consistency between different lang implementations of Jaeger client 2) SpanId is always taken from the SelfRef context Signed-off-by: Oleksandr Bukaiev --- examples/App.cpp | 9 +++++---- src/jaegertracing/Reference.h | 5 ++--- src/jaegertracing/Tracer.cpp | 5 ++--- src/jaegertracing/Tracer.h | 6 +++--- src/jaegertracing/TracerTest.cpp | 14 ++++++++++++++ 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/examples/App.cpp b/examples/App.cpp index 71c035f3..10801f0e 100644 --- a/examples/App.cpp +++ b/examples/App.cpp @@ -24,10 +24,11 @@ void tracedSubroutine(const std::unique_ptr& parentSpan) void tracedFunction() { - // jaegertracing::SpanContext spanContextWithUserIDs { {111, 222}, 333, 0, 0, {} }; // TraceId and SpanID must be != 0 - // auto span = opentracing::Tracer::Global()->StartSpan( - // "tracedFunction1", {jaegertracing::JaegerSpecific_UseTheseIDs(&spanContextWithUserIDs)}); - // // spanID of span is 222, not 333, because it's a root span + //{ + //jaegertracing::SpanContext spanContextWithUserIDs { {111, 222}, 333, 0, 0, {} }; // TraceId and SpanID must be != 0 + //auto span = opentracing::Tracer::Global()->StartSpan( + // "tracedFunction1", {jaegertracing::SelfRef(&spanContextWithUserIDs)}); + //} auto span = opentracing::Tracer::Global()->StartSpan("tracedFunction"); tracedSubroutine(span); diff --git a/src/jaegertracing/Reference.h b/src/jaegertracing/Reference.h index e11629b1..8d8bff71 100644 --- a/src/jaegertracing/Reference.h +++ b/src/jaegertracing/Reference.h @@ -30,9 +30,8 @@ namespace thrift { class SpanRef; } -// An extension of enum opentracing::SpanReferenceType, for a new Span. Only to copy traceID and (for non-root spans) spanID -// spanID for root spans == traceID.low() -const static int SpanReferenceType_JaegerSpecific_UseTheseIDs = 99; +// An extension of enum opentracing::SpanReferenceType, for a new Span. Only to copy traceID and spanID +const static int SpanReferenceType_JaegerSpecific_SelfRef = 99; class Reference { public: diff --git a/src/jaegertracing/Tracer.cpp b/src/jaegertracing/Tracer.cpp index 64ec8e4d..58863e8a 100644 --- a/src/jaegertracing/Tracer.cpp +++ b/src/jaegertracing/Tracer.cpp @@ -88,8 +88,7 @@ Tracer::StartSpanWithOptions(string_view operationName, lowID = randomID(); } const TraceID traceID(highID, lowID); - // self.spanID is ignored for the root span - const auto spanID = traceID.low(); + const auto spanID = self ? self->spanID() : traceID.low(); const auto parentID = 0; auto flags = static_cast(0); if (parent && parent->isDebugIDContainerOnly()) { @@ -204,7 +203,7 @@ Tracer::analyzeReferences(const std::vector& references) const continue; } - if (static_cast(ref.first) == SpanReferenceType_JaegerSpecific_UseTheseIDs) + if (static_cast(ref.first) == SpanReferenceType_JaegerSpecific_SelfRef) { result._self = ctx; continue; // not a reference diff --git a/src/jaegertracing/Tracer.h b/src/jaegertracing/Tracer.h index e52abf4b..ecaa6a87 100644 --- a/src/jaegertracing/Tracer.h +++ b/src/jaegertracing/Tracer.h @@ -304,11 +304,11 @@ class Tracer : public opentracing::Tracer, }; -// JaegerSpecific_Self returns a StartSpanOption pointing to the Span that should be used as the started span context +// jaegertracing::SelfRef returns a StartSpanOption pointing to the Span which traceID and spanID should become the new Span's IDs // // See opentracing::SpanReference -inline opentracing::SpanReference JaegerSpecific_UseTheseIDs(const opentracing::SpanContext* span_context) noexcept { - return {static_cast(SpanReferenceType_JaegerSpecific_UseTheseIDs), span_context}; +inline opentracing::SpanReference SelfRef(const opentracing::SpanContext* span_context) noexcept { + return {static_cast(SpanReferenceType_JaegerSpecific_SelfRef), span_context}; } } // namespace jaegertracing diff --git a/src/jaegertracing/TracerTest.cpp b/src/jaegertracing/TracerTest.cpp index 4a5a0057..c0246d47 100644 --- a/src/jaegertracing/TracerTest.cpp +++ b/src/jaegertracing/TracerTest.cpp @@ -490,4 +490,18 @@ TEST(Tracer, testTracerTags) ASSERT_EQ(std::string("test-service"), jaegerTracer->serviceName()); } +TEST(Tracer, testTracerStartSpanSelfRef) +{ + const auto handle = testutils::TracerUtil::installGlobalTracer(); + const auto tracer = std::static_pointer_cast(opentracing::Tracer::Global()); + { + jaegertracing::SpanContext spanSelfContext { {1, 2}, 3, 0, 0, {} }; + auto span = tracer->StartSpan("tracedFunction1", {jaegertracing::SelfRef(&spanSelfContext)}); + auto jaegerSpan = dynamic_cast(*span.get()); + ASSERT_EQ(jaegerSpan.context().traceID(), jaegertracing::TraceID(1, 2)); + ASSERT_EQ(jaegerSpan.context().spanID(), 3); + } + tracer->Close(); +} + } // namespace jaegertracing From d1681d4b2d8dc821f4bb63de5c789fb22eb47a19 Mon Sep 17 00:00:00 2001 From: Oleksandr Bukaiev Date: Mon, 17 Feb 2020 17:54:59 -0700 Subject: [PATCH 3/7] Seems like on some compilers jaegertracing::SpanContext::StrMap(initializer_list) is explicit Signed-off-by: Oleksandr Bukaiev --- src/jaegertracing/TracerTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jaegertracing/TracerTest.cpp b/src/jaegertracing/TracerTest.cpp index c0246d47..27cca66b 100644 --- a/src/jaegertracing/TracerTest.cpp +++ b/src/jaegertracing/TracerTest.cpp @@ -495,7 +495,7 @@ TEST(Tracer, testTracerStartSpanSelfRef) const auto handle = testutils::TracerUtil::installGlobalTracer(); const auto tracer = std::static_pointer_cast(opentracing::Tracer::Global()); { - jaegertracing::SpanContext spanSelfContext { {1, 2}, 3, 0, 0, {} }; + jaegertracing::SpanContext spanSelfContext { {1, 2}, 3, 0, 0, jaegertracing::SpanContext::StrMap() }; auto span = tracer->StartSpan("tracedFunction1", {jaegertracing::SelfRef(&spanSelfContext)}); auto jaegerSpan = dynamic_cast(*span.get()); ASSERT_EQ(jaegerSpan.context().traceID(), jaegertracing::TraceID(1, 2)); From d2accfd66df2435edfa74e663e8dea55a26ae9cc Mon Sep 17 00:00:00 2001 From: Oleksandr Bukaiev Date: Mon, 17 Feb 2020 19:28:18 -0700 Subject: [PATCH 4/7] Temporarily commented out the new unit test case body Signed-off-by: Oleksandr Bukaiev --- examples/App.cpp | 2 +- src/jaegertracing/TracerTest.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/App.cpp b/examples/App.cpp index 10801f0e..4d195d87 100644 --- a/examples/App.cpp +++ b/examples/App.cpp @@ -25,7 +25,7 @@ void tracedSubroutine(const std::unique_ptr& parentSpan) void tracedFunction() { //{ - //jaegertracing::SpanContext spanContextWithUserIDs { {111, 222}, 333, 0, 0, {} }; // TraceId and SpanID must be != 0 + //jaegertracing::SpanContext spanContextWithUserIDs { {111, 222}, 333, 0, 0, jaegertracing::SpanContext::StrMap() }; // TraceId and SpanID must be != 0 //auto span = opentracing::Tracer::Global()->StartSpan( // "tracedFunction1", {jaegertracing::SelfRef(&spanContextWithUserIDs)}); //} diff --git a/src/jaegertracing/TracerTest.cpp b/src/jaegertracing/TracerTest.cpp index 27cca66b..2e3f8735 100644 --- a/src/jaegertracing/TracerTest.cpp +++ b/src/jaegertracing/TracerTest.cpp @@ -492,6 +492,10 @@ TEST(Tracer, testTracerTags) TEST(Tracer, testTracerStartSpanSelfRef) { + // Got a strange error: SEH exception with code 0xc0000005 thrown in the test body. + // Commented out for now, check it later before the merge + + /* const auto handle = testutils::TracerUtil::installGlobalTracer(); const auto tracer = std::static_pointer_cast(opentracing::Tracer::Global()); { @@ -502,6 +506,7 @@ TEST(Tracer, testTracerStartSpanSelfRef) ASSERT_EQ(jaegerSpan.context().spanID(), 3); } tracer->Close(); + */ } } // namespace jaegertracing From 713ebca01861f28e78bea26b22df8764a9063cf7 Mon Sep 17 00:00:00 2001 From: Oleksandr Bukaiev Date: Wed, 19 Feb 2020 19:24:46 -0700 Subject: [PATCH 5/7] SelfRef only used for creating root spans and can be passed as the only reference to enforce this rule Signed-off-by: Oleksandr Bukaiev --- README.md | 8 ++++++++ examples/App.cpp | 6 ------ src/jaegertracing/Reference.h | 3 --- src/jaegertracing/Tracer.cpp | 14 +++++++++++++- src/jaegertracing/Tracer.h | 4 +--- src/jaegertracing/TracerTest.cpp | 19 ------------------- 6 files changed, 22 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 18e83c01..0ff2d79b 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,14 @@ JAEGER_SAMPLER_PARAM | The sampler parameter (double) JAEGER_SAMPLING_ENDPOINT | The url for the remote sampling conf when using sampler type remote. Default is http://127.0.0.1:5778/sampling JAEGER_TAGS | A comma separated list of `name = value` tracer level tags, which get added to all reported spans. The value can also refer to an environment variable using the format `${envVarName:default}`, where the `:default` is optional, and identifies a value to be used if the environment variable cannot be found +### SelfRef +Jaeger Tracer supports an additional reference type call 'SelfRef'. This allows a caller to provide traceId and spanId for the root span. +Must be the lone reference. +Usage example: + jaegertracing::SpanContext spanContextWithUserIDs { {1, 2}, 3, 0, 0, jaegertracing::SpanContext::StrMap() }; // TraceId and SpanID must be != 0 + auto span = opentracing::Tracer::Global()->StartSpan("tracedFunction1", {jaegertracing::SelfRef(&spanContextWithUserIDs)}); + + ## License [Apache 2.0 License](./LICENSE). diff --git a/examples/App.cpp b/examples/App.cpp index 4d195d87..f7df8a2a 100644 --- a/examples/App.cpp +++ b/examples/App.cpp @@ -24,12 +24,6 @@ void tracedSubroutine(const std::unique_ptr& parentSpan) void tracedFunction() { - //{ - //jaegertracing::SpanContext spanContextWithUserIDs { {111, 222}, 333, 0, 0, jaegertracing::SpanContext::StrMap() }; // TraceId and SpanID must be != 0 - //auto span = opentracing::Tracer::Global()->StartSpan( - // "tracedFunction1", {jaegertracing::SelfRef(&spanContextWithUserIDs)}); - //} - auto span = opentracing::Tracer::Global()->StartSpan("tracedFunction"); tracedSubroutine(span); } diff --git a/src/jaegertracing/Reference.h b/src/jaegertracing/Reference.h index 8d8bff71..52277aea 100644 --- a/src/jaegertracing/Reference.h +++ b/src/jaegertracing/Reference.h @@ -30,9 +30,6 @@ namespace thrift { class SpanRef; } -// An extension of enum opentracing::SpanReferenceType, for a new Span. Only to copy traceID and spanID -const static int SpanReferenceType_JaegerSpecific_SelfRef = 99; - class Reference { public: using Type = opentracing::SpanReferenceType; diff --git a/src/jaegertracing/Tracer.cpp b/src/jaegertracing/Tracer.cpp index 58863e8a..95a7f7c4 100644 --- a/src/jaegertracing/Tracer.cpp +++ b/src/jaegertracing/Tracer.cpp @@ -33,6 +33,10 @@ using SystemClock = Tracer::SystemClock; using SteadyClock = Tracer::SteadyClock; using TimePoints = std::tuple; +// An extension of enum opentracing::SpanReferenceType, for a new Span. Only to copy traceID and (for non-root spans) spanID +// spanID for root spans still traceID.low() +const static int SpanReferenceType_JaegerSpecific_SelfRef = 99; + TimePoints determineStartTimes(const opentracing::StartSpanOptions& options) { if (options.start_system_timestamp == SystemClock::time_point() && @@ -69,6 +73,10 @@ Tracer::StartSpanWithOptions(string_view operationName, const auto* parent = result._parent; const auto* self = result._self; const auto& references = result._references; + if (self && (parent || !references.empty())) + { + throw std::exception("Self reference must be the only reference"); + } std::vector samplerTags; auto newTrace = false; @@ -110,7 +118,7 @@ Tracer::StartSpanWithOptions(string_view operationName, } else { const auto traceID = parent->traceID(); - const auto spanID = self ? self->spanID() : randomID(); + const auto spanID = randomID(); const auto parentID = parent->spanID(); const auto flags = parent->flags(); ctx = SpanContext(traceID, spanID, parentID, flags, StrMap()); @@ -260,4 +268,8 @@ Tracer::make(const std::string& serviceName, options)); } +opentracing::SpanReference SelfRef(const opentracing::SpanContext* span_context) noexcept { + return {static_cast(SpanReferenceType_JaegerSpecific_SelfRef), span_context}; +} + } // namespace jaegertracing diff --git a/src/jaegertracing/Tracer.h b/src/jaegertracing/Tracer.h index ecaa6a87..56b074c0 100644 --- a/src/jaegertracing/Tracer.h +++ b/src/jaegertracing/Tracer.h @@ -307,9 +307,7 @@ class Tracer : public opentracing::Tracer, // jaegertracing::SelfRef returns a StartSpanOption pointing to the Span which traceID and spanID should become the new Span's IDs // // See opentracing::SpanReference -inline opentracing::SpanReference SelfRef(const opentracing::SpanContext* span_context) noexcept { - return {static_cast(SpanReferenceType_JaegerSpecific_SelfRef), span_context}; -} +opentracing::SpanReference SelfRef(const opentracing::SpanContext* span_context) noexcept; } // namespace jaegertracing diff --git a/src/jaegertracing/TracerTest.cpp b/src/jaegertracing/TracerTest.cpp index 2e3f8735..4a5a0057 100644 --- a/src/jaegertracing/TracerTest.cpp +++ b/src/jaegertracing/TracerTest.cpp @@ -490,23 +490,4 @@ TEST(Tracer, testTracerTags) ASSERT_EQ(std::string("test-service"), jaegerTracer->serviceName()); } -TEST(Tracer, testTracerStartSpanSelfRef) -{ - // Got a strange error: SEH exception with code 0xc0000005 thrown in the test body. - // Commented out for now, check it later before the merge - - /* - const auto handle = testutils::TracerUtil::installGlobalTracer(); - const auto tracer = std::static_pointer_cast(opentracing::Tracer::Global()); - { - jaegertracing::SpanContext spanSelfContext { {1, 2}, 3, 0, 0, jaegertracing::SpanContext::StrMap() }; - auto span = tracer->StartSpan("tracedFunction1", {jaegertracing::SelfRef(&spanSelfContext)}); - auto jaegerSpan = dynamic_cast(*span.get()); - ASSERT_EQ(jaegerSpan.context().traceID(), jaegertracing::TraceID(1, 2)); - ASSERT_EQ(jaegerSpan.context().spanID(), 3); - } - tracer->Close(); - */ -} - } // namespace jaegertracing From 3717a11efe3fea9b42706a28c5f167ed7fc667b2 Mon Sep 17 00:00:00 2001 From: Oleksandr Bukaiev Date: Wed, 19 Feb 2020 19:32:09 -0700 Subject: [PATCH 6/7] Apparently std::exception ctor with a const char* is not standard Signed-off-by: Oleksandr Bukaiev --- src/jaegertracing/Tracer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jaegertracing/Tracer.cpp b/src/jaegertracing/Tracer.cpp index 95a7f7c4..fd3a0608 100644 --- a/src/jaegertracing/Tracer.cpp +++ b/src/jaegertracing/Tracer.cpp @@ -75,7 +75,7 @@ Tracer::StartSpanWithOptions(string_view operationName, const auto& references = result._references; if (self && (parent || !references.empty())) { - throw std::exception("Self reference must be the only reference"); + throw std::exception(); // Self reference must be the only reference } std::vector samplerTags; From b2d3e125374968e3d1cee45338a8ba257c7c3320 Mon Sep 17 00:00:00 2001 From: Oleksandr Bukaiev Date: Thu, 20 Feb 2020 19:11:43 -0700 Subject: [PATCH 7/7] Updates in README and code comments as per reviewer's request Signed-off-by: Oleksandr Bukaiev --- README.md | 17 ++++++++++++----- src/jaegertracing/Tracer.cpp | 3 +-- src/jaegertracing/Tracer.h | 9 ++++++--- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0ff2d79b..d1d6146c 100644 --- a/README.md +++ b/README.md @@ -108,12 +108,19 @@ JAEGER_SAMPLING_ENDPOINT | The url for the remote sampling conf when using sampl JAEGER_TAGS | A comma separated list of `name = value` tracer level tags, which get added to all reported spans. The value can also refer to an environment variable using the format `${envVarName:default}`, where the `:default` is optional, and identifies a value to be used if the environment variable cannot be found ### SelfRef -Jaeger Tracer supports an additional reference type call 'SelfRef'. This allows a caller to provide traceId and spanId for the root span. -Must be the lone reference. -Usage example: - jaegertracing::SpanContext spanContextWithUserIDs { {1, 2}, 3, 0, 0, jaegertracing::SpanContext::StrMap() }; // TraceId and SpanID must be != 0 - auto span = opentracing::Tracer::Global()->StartSpan("tracedFunction1", {jaegertracing::SelfRef(&spanContextWithUserIDs)}); +Jaeger Tracer supports an additional reference type call 'SelfRef'. +It returns an opentracing::SpanReference which can be passed to Tracer::StartSpan +to influence the SpanContext of the newly created span. Specifically, the new span inherits the traceID +and spanID from the passed SELF reference. It can be used to pass externally generated IDs to the tracer, +with the purpose of recording spans from data generated elsewhere (e.g. from logs), or by augmenting the +data of the existing span (Jaeger backend will merge multiple instances of the spans with the same IDs). +Must be the lone reference, can be used only for root spans. +Usage example: +``` + jaegertracing::SpanContext customCtx { {1, 2}, 3, 0, 0, jaegertracing::SpanContext::StrMap() }; // TraceId and SpanID must be != 0 + auto span = tracer->StartSpan("spanName", { jaegertracing::SelfRef(&customCtx) }); +``` ## License diff --git a/src/jaegertracing/Tracer.cpp b/src/jaegertracing/Tracer.cpp index fd3a0608..d8f659fe 100644 --- a/src/jaegertracing/Tracer.cpp +++ b/src/jaegertracing/Tracer.cpp @@ -33,8 +33,7 @@ using SystemClock = Tracer::SystemClock; using SteadyClock = Tracer::SteadyClock; using TimePoints = std::tuple; -// An extension of enum opentracing::SpanReferenceType, for a new Span. Only to copy traceID and (for non-root spans) spanID -// spanID for root spans still traceID.low() +// An extension of opentracing::SpanReferenceType enum. See jaegertracing::SelfRef(). const static int SpanReferenceType_JaegerSpecific_SelfRef = 99; TimePoints determineStartTimes(const opentracing::StartSpanOptions& options) diff --git a/src/jaegertracing/Tracer.h b/src/jaegertracing/Tracer.h index 56b074c0..8d204267 100644 --- a/src/jaegertracing/Tracer.h +++ b/src/jaegertracing/Tracer.h @@ -304,9 +304,12 @@ class Tracer : public opentracing::Tracer, }; -// jaegertracing::SelfRef returns a StartSpanOption pointing to the Span which traceID and spanID should become the new Span's IDs -// -// See opentracing::SpanReference +// jaegertracing::SelfRef() returns an opentracing::SpanReference which can be passed to Tracer::StartSpan +// to influence the SpanContext of the newly created span. Specifically, the new span inherits the traceID +// and spanID from the passed SELF reference. It can be used to pass externally generated IDs to the tracer, +// with the purpose of recording spans from data generated elsewhere (e.g. from logs), or by augmenting the +// data of the existing span (Jaeger backend will merge multiple instances of the spans with the same IDs). +// Must be the lone reference, can be used only for root spans opentracing::SpanReference SelfRef(const opentracing::SpanContext* span_context) noexcept; } // namespace jaegertracing