diff --git a/exporters/zipkin/src/recordable.cc b/exporters/zipkin/src/recordable.cc index 283e02ed45..a6722f225f 100644 --- a/exporters/zipkin/src/recordable.cc +++ b/exporters/zipkin/src/recordable.cc @@ -16,7 +16,8 @@ #include "opentelemetry/exporters/zipkin/recordable.h" -#include +#include +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -24,6 +25,14 @@ namespace exporter namespace zipkin { +// constexpr needs keys to be constexpr, const is next best to use. +static const std::map 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. // @@ -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 @@ -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 diff --git a/exporters/zipkin/test/zipkin_recordable_test.cc b/exporters/zipkin/test/zipkin_recordable_test.cc index f189d04d9c..a5eb1dc934 100644 --- a/exporters/zipkin/test/zipkin_recordable_test.cc +++ b/exporters/zipkin/test/zipkin_recordable_test.cc @@ -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;