From 0e63f5ee4866197e496fb06d24955b6aac2ab594 Mon Sep 17 00:00:00 2001 From: Willie Abrams Date: Tue, 5 Mar 2024 13:31:27 -0600 Subject: [PATCH] incorporating reviewer feedback --- sdk/src/resource/resource_detector.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sdk/src/resource/resource_detector.cc b/sdk/src/resource/resource_detector.cc index 161b825b83..2f560e1150 100644 --- a/sdk/src/resource/resource_detector.cc +++ b/sdk/src/resource/resource_detector.cc @@ -4,6 +4,7 @@ #include "opentelemetry/sdk/resource/resource_detector.h" #include "opentelemetry/sdk/common/env_variables.h" #include "opentelemetry/sdk/resource/resource.h" +#include "opentelemetry/sdk/resource/semantic_conventions.h" #include #include @@ -39,16 +40,19 @@ Resource OTELResourceDetector::Detect() noexcept std::string token; while (std::getline(iss, token, ',')) { - size_t pos = token.find('='); - std::string key = token.substr(0, pos); - std::string value = token.substr(pos + 1); - attributes[key] = value; + size_t pos = token.find('='); + if (pos != std::string::npos) + { + std::string key = token.substr(0, pos); + std::string value = token.substr(pos + 1); + attributes[key] = value; + } } } if (service_name_exists) { - attributes["service.name"] = service_name; + attributes[SemanticConventions::kServiceName] = service_name; } return Resource(attributes);