Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
Add jaeger-debug-id as a tag (#190)
Browse files Browse the repository at this point in the history
* Add jaeger-debug-id as a tag

If the trace was started with a debugID, adding jaeger-debug-id
as tag ensures that the trace will be sampled in the "debug" mode.

Additionally, the root span will have this ID as a searchable tag.

Resolves: #136

Signed-off-by: Chris Goller <[email protected]>

* Add test for jaeger-debug-id correlation tag creation

Signed-off-by: Chris Goller <[email protected]>
  • Loading branch information
goller authored and yurishkuro committed Nov 23, 2019
1 parent 2c39cc2 commit 741b1af
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/jaegertracing/Tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

#include "jaegertracing/Tag.h"
#include "jaegertracing/Tracer.h"
#include "jaegertracing/Reference.h"
#include "jaegertracing/TraceID.h"
Expand Down Expand Up @@ -85,6 +86,7 @@ Tracer::StartSpanWithOptions(string_view operationName,
flags |=
(static_cast<unsigned char>(SpanContext::Flag::kSampled) |
static_cast<unsigned char>(SpanContext::Flag::kDebug));
samplerTags.push_back(Tag(kJaegerDebugHeader, parent->debugID()));
}
else {
const auto samplingStatus =
Expand Down
44 changes: 43 additions & 1 deletion src/jaegertracing/TracerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ absTimeDiff(const typename ClockType::time_point& lhs,
TEST(Tracer, testTracer)
{
{

const auto handle = testutils::TracerUtil::installGlobalTracer();
const auto tracer =
std::static_pointer_cast<Tracer>(opentracing::Tracer::Global());
Expand Down Expand Up @@ -269,6 +269,48 @@ TEST(Tracer, testTracer)
//std::this_thread::sleep_for(std::chrono::milliseconds(10000));
}

TEST(Tracer, testDebugSpan)
{
const auto handle = testutils::TracerUtil::installGlobalTracer();
const auto tracer =
std::static_pointer_cast<Tracer>(opentracing::Tracer::Global());

// we force span sampling and require debug-id as the extracted
// jaeger-debug-id correlation value.
std::string correlationID = "debug-id";

StrMap headers ={
{kJaegerDebugHeader, correlationID},
};

WriterMock<opentracing::HTTPHeadersWriter> headerWriter(headers);
ReaderMock<opentracing::HTTPHeadersReader> headerReader(headers);

const FakeSpanContext fakeCtx;
tracer->Inject(fakeCtx, headerWriter);
auto ext = tracer->Extract(headerReader);

const SpanContext* ctx = dynamic_cast<SpanContext*>(ext->release());
opentracing::StartSpanOptions opts;
opts.references.emplace_back(opentracing::SpanReferenceType::ChildOfRef, ctx);

auto otspan = tracer->StartSpanWithOptions("name", opts);
// downcast to jaegertracing span implementation so we can inspect tags
const std::unique_ptr<Span> span(dynamic_cast<Span*>(otspan.release()));

const auto& spanTags = span->tags();
auto spanItr =
std::find_if(std::begin(spanTags), std::end(spanTags), [](const Tag& tag) {
return tag.key() == kJaegerDebugHeader;
});
ASSERT_NE(std::end(spanTags), spanItr);
ASSERT_TRUE(spanItr->value().is<std::string>());
ASSERT_EQ(spanItr->value().get<std::string>(), correlationID);

tracer->Close();
opentracing::Tracer::InitGlobal(opentracing::MakeNoopTracer());
}

TEST(Tracer, testConstructorFailure)
{
Config config;
Expand Down

0 comments on commit 741b1af

Please sign in to comment.