Skip to content

Commit

Permalink
Convert null to empty string for tracer name (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomsonTan authored Apr 29, 2021
1 parent a987f0a commit fc7a325
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sdk/src/trace/tracer_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ nostd::shared_ptr<opentelemetry::trace::Tracer> TracerProvider::GetTracer(
nostd::string_view library_name,
nostd::string_view library_version) noexcept
{
if (library_name.data() == nullptr)
{
library_name = "";
}
// if (library_name == "") {
// // TODO: log invalid library_name.
// }
Expand Down
3 changes: 3 additions & 0 deletions sdk/test/trace/tracer_provider_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ TEST(TracerProvider, GetTracer)
auto t1 = tp1.GetTracer("test");
auto t2 = tp1.GetTracer("test");
auto t3 = tp1.GetTracer("different", "1.0.0");
auto t4 = tp1.GetTracer("");
auto t5 = tp1.GetTracer(opentelemetry::nostd::string_view{});
ASSERT_NE(nullptr, t1);
ASSERT_NE(nullptr, t2);
ASSERT_NE(nullptr, t3);

// Should return the same instance each time.
ASSERT_EQ(t1, t2);
ASSERT_NE(t1, t3);
ASSERT_EQ(t4, t5);

// Should be an sdk::trace::Tracer with the processor attached.
auto sdkTracer1 = dynamic_cast<Tracer *>(t1.get());
Expand Down

0 comments on commit fc7a325

Please sign in to comment.