33
44#include " opentelemetry/sdk/resource/resource_detector.h"
55#include " opentelemetry/nostd/variant.h"
6- #include " opentelemetry/sdk/common/env_variables.h"
76#include " opentelemetry/sdk/common/container.h"
7+ #include " opentelemetry/sdk/common/env_variables.h"
88#include " opentelemetry/sdk/resource/resource.h"
9- #include " opentelemetry/semconv/service_attributes.h"
109#include " opentelemetry/semconv/incubating/container_attributes.h"
10+ #include " opentelemetry/semconv/service_attributes.h"
1111#include " opentelemetry/version.h"
1212
1313#include < stddef.h>
@@ -21,12 +21,8 @@ namespace sdk
2121namespace resource
2222{
2323
24- const char *OTEL_RESOURCE_ATTRIBUTES = " OTEL_RESOURCE_ATTRIBUTES" ;
25- const char *OTEL_SERVICE_NAME = " OTEL_SERVICE_NAME" ;
26- /* *
27- * This is the file path from where we can get container.id
28- */
29- const char *C_GROUP_PATH = " /proc/self/cgroup" ;
24+ const char *KOtelResourceAttributes = " OTEL_RESOURCE_ATTRIBUTES" ;
25+ const char *KOtelServiceName = " OTEL_SERVICE_NAME" ;
3026
3127Resource ResourceDetector::Create (const ResourceAttributes &attributes,
3228 const std::string &schema_url)
@@ -39,9 +35,9 @@ Resource OTELResourceDetector::Detect() noexcept
3935 std::string attributes_str, service_name;
4036
4137 bool attributes_exists = opentelemetry::sdk::common::GetStringEnvironmentVariable (
42- OTEL_RESOURCE_ATTRIBUTES , attributes_str);
38+ KOtelResourceAttributes , attributes_str);
4339 bool service_name_exists =
44- opentelemetry::sdk::common::GetStringEnvironmentVariable (OTEL_SERVICE_NAME , service_name);
40+ opentelemetry::sdk::common::GetStringEnvironmentVariable (KOtelServiceName , service_name);
4541
4642 if (!attributes_exists && !service_name_exists)
4743 {
@@ -74,23 +70,6 @@ Resource OTELResourceDetector::Detect() noexcept
7470 return ResourceDetector::Create (attributes);
7571}
7672
77- Resource ContainerResourceDetector::Detect () noexcept
78- {
79- std::string container_id = opentelemetry::sdk::common::GetContainerIDFromCgroup (C_GROUP_PATH);
80- if (container_id.empty ())
81- {
82- return ResourceDetector::Create ({});
83- }
84-
85- ResourceAttributes attributes;
86-
87- if (!container_id.empty ())
88- {
89- attributes[semconv::container::kContainerId ] = container_id;
90- }
91- return ResourceDetector::Create (attributes);
92- }
93-
9473} // namespace resource
9574} // namespace sdk
9675OPENTELEMETRY_END_NAMESPACE
0 commit comments