From fc7a325efa96978ff867caa2ab9c56305e28fddf Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Thu, 29 Apr 2021 12:55:43 -0700 Subject: [PATCH] Convert null to empty string for tracer name (#712) --- sdk/src/trace/tracer_provider.cc | 4 ++++ sdk/test/trace/tracer_provider_test.cc | 3 +++ 2 files changed, 7 insertions(+) diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc index a210555f35..25b0eb6747 100644 --- a/sdk/src/trace/tracer_provider.cc +++ b/sdk/src/trace/tracer_provider.cc @@ -33,6 +33,10 @@ nostd::shared_ptr 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. // } diff --git a/sdk/test/trace/tracer_provider_test.cc b/sdk/test/trace/tracer_provider_test.cc index 9832389822..4943346269 100644 --- a/sdk/test/trace/tracer_provider_test.cc +++ b/sdk/test/trace/tracer_provider_test.cc @@ -21,6 +21,8 @@ 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); @@ -28,6 +30,7 @@ TEST(TracerProvider, GetTracer) // 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(t1.get());