Browse Source

set service.name iff it's not set by the `OTEL_SERVICE_NAME` env var

Grant Limberg 3 weeks ago
parent
commit
a0cc7babdf
1 changed files with 5 additions and 2 deletions
  1. 5 2
      service/OneService.cpp

+ 5 - 2
service/OneService.cpp

@@ -1074,16 +1074,19 @@ class OneServiceImpl : public OneService {
 			auto processor = std::unique_ptr<sdktrace::SpanProcessor>(new sdktrace::BatchSpanProcessor(std::move(exporter), batch_options));
 			auto processor = std::unique_ptr<sdktrace::SpanProcessor>(new sdktrace::BatchSpanProcessor(std::move(exporter), batch_options));
 			auto processors = std::vector<std::unique_ptr<sdktrace::SpanProcessor> >();
 			auto processors = std::vector<std::unique_ptr<sdktrace::SpanProcessor> >();
 			processors.push_back(std::move(processor));
 			processors.push_back(std::move(processor));
+
 			char buf[256];
 			char buf[256];
 			auto versionString = std::stringstream();
 			auto versionString = std::stringstream();
 			versionString << ZEROTIER_ONE_VERSION_MAJOR << "." << ZEROTIER_ONE_VERSION_MINOR << "." << ZEROTIER_ONE_VERSION_REVISION;
 			versionString << ZEROTIER_ONE_VERSION_MAJOR << "." << ZEROTIER_ONE_VERSION_MINOR << "." << ZEROTIER_ONE_VERSION_REVISION;
 			auto resource_attributes = sdkresource::ResourceAttributes { { "service.version", versionString.str() }, { "service.node_id", _node->identity().address().toString(buf) }, { "service.namespace", "com.zerotier.zerotier-one" } };
 			auto resource_attributes = sdkresource::ResourceAttributes { { "service.version", versionString.str() }, { "service.node_id", _node->identity().address().toString(buf) }, { "service.namespace", "com.zerotier.zerotier-one" } };
 			auto resource = sdkresource::Resource::Create(resource_attributes);
 			auto resource = sdkresource::Resource::Create(resource_attributes);
-			auto recvd_attributes = resource.GetAttributes();
-			if (! recvd_attributes.contains("service.name")) {
+			auto recvd_attributes = resource.GetAttributes().GetAttributes();
+			// If service.name is not set, we set it to "zerotier-one"
+			if (recvd_attributes.find("service.name") != recvd_attributes.end()) {
 				resource_attributes["service.name"] = "zerotier-one";
 				resource_attributes["service.name"] = "zerotier-one";
 				resource = sdkresource::Resource::Create(resource_attributes);
 				resource = sdkresource::Resource::Create(resource_attributes);
 			}
 			}
+
 			auto sampler = std::unique_ptr<sdktrace::Sampler>(new sdktrace::TraceIdRatioBasedSampler(_exporterSampleRate));
 			auto sampler = std::unique_ptr<sdktrace::Sampler>(new sdktrace::TraceIdRatioBasedSampler(_exporterSampleRate));
 			auto tracer_context = std::make_unique<sdktrace::TracerContext>(std::move(processors), resource, std::move(sampler));
 			auto tracer_context = std::make_unique<sdktrace::TracerContext>(std::move(processors), resource, std::move(sampler));
 			_traceProvider = opentelemetry::nostd::shared_ptr<sdktrace::TracerProvider>(new sdktrace::TracerProvider(std::move(tracer_context)));
 			_traceProvider = opentelemetry::nostd::shared_ptr<sdktrace::TracerProvider>(new sdktrace::TracerProvider(std::move(tracer_context)));