Skip to content

Commit

Permalink
Few minor fixes for zipkin exporter (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Jul 1, 2021
1 parent 47859cc commit 8556485
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ namespace exporter
namespace zipkin
{

const char *kZipkinEndpointDefault = "http://localhost:9411/api/v2/spans";

static const std::string GetDefaultZipkinEndpoint()
inline const std::string GetDefaultZipkinEndpoint()
{
const char *otel_exporter_zipkin_endpoint_env = "OTEL_EXPORTER_ZIPKIN_ENDPOINT";
const char *kZipkinEndpointDefault = "http://localhost:9411/api/v2/spans";

#if defined(_MSC_VER)
// avoid calling std::getenv which is deprecated in MSVC.
size_t required_size = 0;
Expand Down
2 changes: 1 addition & 1 deletion exporters/zipkin/src/recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void Recordable::SetStartTime(opentelemetry::common::SystemTimestamp start_time)

void Recordable::SetDuration(std::chrono::nanoseconds duration) noexcept
{
span_["duration"] = duration.count();
span_["duration"] = std::chrono::duration_cast<std::chrono::microseconds>(duration).count();
}

void Recordable::SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept
Expand Down
12 changes: 5 additions & 7 deletions exporters/zipkin/test/zipkin_recordable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/exporters/zipkin/recordable.h"

#include <iostream>

#include <gtest/gtest.h>

namespace trace = opentelemetry::trace;
Expand Down Expand Up @@ -69,16 +67,16 @@ TEST(ZipkinSpanRecordable, SetStartTime)

TEST(ZipkinSpanRecordable, SetDuration)
{
json j_span = {{"duration", 10}, {"timestamp", 0}};
std::chrono::nanoseconds durationNS(1000000000); // in ns
std::chrono::microseconds durationMS =
std::chrono::duration_cast<std::chrono::microseconds>(durationNS); // in ms
json j_span = {{"duration", durationMS.count()}, {"timestamp", 0}};
opentelemetry::exporter::zipkin::Recordable rec;
// Start time is 0
opentelemetry::common::SystemTimestamp start_timestamp;

std::chrono::nanoseconds duration(10);
uint64_t unix_end = duration.count();

rec.SetStartTime(start_timestamp);
rec.SetDuration(duration);
rec.SetDuration(durationNS);
EXPECT_EQ(rec.span(), j_span);
}

Expand Down

0 comments on commit 8556485

Please sign in to comment.