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

Add jaeger-debug-id as a tag #190

Merged
merged 2 commits into from
Nov 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a unit test which can check that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @yurishkuro thanks for the review; tests added in 7d81527

}
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