Skip to content

Commit

Permalink
Set Spankind for Zipkin exporter (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Apr 28, 2021
1 parent 7f5252f commit a3755f4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
21 changes: 19 additions & 2 deletions exporters/zipkin/src/recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@

#include "opentelemetry/exporters/zipkin/recordable.h"

#include <iostream>
#include <map>
#include <string>

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace zipkin
{

// constexpr needs keys to be constexpr, const is next best to use.
static const std::map<opentelemetry::trace::SpanKind, std::string> kSpanKindMap = {
{opentelemetry::trace::SpanKind::kClient, "CLIENT"},
{opentelemetry::trace::SpanKind::kServer, "SERVER"},
{opentelemetry::trace::SpanKind::kConsumer, "CONSUMER"},
{opentelemetry::trace::SpanKind::kProducer, "PRODUCER"},
};

//
// See `attribute_value.h` for details.
//
Expand Down Expand Up @@ -215,6 +224,15 @@ void Recordable::SetDuration(std::chrono::nanoseconds duration) noexcept
span_["duration"] = duration.count();
}

void Recordable::SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept
{
auto span_iter = kSpanKindMap.find(span_kind);
if (span_iter != kSpanKindMap.end())
{
span_["kind"] = span_iter->second;
}
}

void Recordable::SetInstrumentationLibrary(
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
&instrumentation_library) noexcept
Expand All @@ -223,7 +241,6 @@ void Recordable::SetInstrumentationLibrary(
span_["tags"]["otel.library.version"] = instrumentation_library.GetVersion();
}

void Recordable::SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept {}
} // namespace zipkin
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
8 changes: 8 additions & 0 deletions exporters/zipkin/test/zipkin_recordable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ TEST(ZipkinSpanRecordable, SetStatus)
}
}

TEST(ZipkinSpanRecordable, SetSpanKind)
{
json j_json_client = {{"kind", "CLIENT"}};
opentelemetry::exporter::zipkin::Recordable rec;
rec.SetSpanKind(opentelemetry::trace::SpanKind::kClient);
EXPECT_EQ(rec.span(), j_json_client);
}

TEST(ZipkinSpanRecordable, AddEventDefault)
{
opentelemetry::exporter::zipkin::Recordable rec;
Expand Down

0 comments on commit a3755f4

Please sign in to comment.