File tree Expand file tree Collapse file tree 11 files changed +58
-68
lines changed
include/opentelemetry/sdk Expand file tree Collapse file tree 11 files changed +58
-68
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ // Copyright The OpenTelemetry Authors
2+ // SPDX-License-Identifier: Apache-2.0
3+
4+ #pragma once
5+
6+ #include " opentelemetry/sdk/resource/resource.h"
7+ #include " opentelemetry/sdk/resource/resource_detector.h"
8+ #include " opentelemetry/version.h"
9+
10+ OPENTELEMETRY_BEGIN_NAMESPACE
11+ namespace sdk
12+ {
13+ namespace resource
14+ {
15+
16+ /* *
17+ * ContainerResourceDetector to detect resource attributes when running inside a containerized
18+ * environment. This detector extracts metadata such as container ID from cgroup information and
19+ * sets attributes like container.id following the OpenTelemetry semantic conventions.
20+ */
21+ class ContainerResourceDetector : public ResourceDetector
22+ {
23+ public:
24+ Resource Detect () noexcept override ;
25+ };
26+
27+ /* *
28+ * Reads the container.id from /proc/self/cgroup file.
29+ * @param file_path file path of cgroup
30+ * @return container.id as string or empty string
31+ */
32+ std::string GetContainerIDFromCgroup (const char *file_path);
33+
34+ /* *
35+ * Matches the line with the regex to find container.id
36+ * @param line a single line of text, typically from the /proc/self/cgroup file
37+ * @return matched id or empty string
38+ */
39+ std::string ExtractContainerIDFromLine (const std::string &line);
40+
41+ } // namespace resource
42+ } // namespace sdk
43+ OPENTELEMETRY_END_NAMESPACE
Original file line number Diff line number Diff line change @@ -39,17 +39,6 @@ class OTELResourceDetector : public ResourceDetector
3939 Resource Detect () noexcept override ;
4040};
4141
42- /* *
43- * ContainerResourceDetector to detect resource attributes when running inside a containerized
44- * environment. This detector extracts metadata such as container ID from cgroup information and
45- * sets attributes like container.id following the OpenTelemetry semantic conventions.
46- */
47- class ContainerResourceDetector : public ResourceDetector
48- {
49- public:
50- Resource Detect () noexcept override ;
51- };
52-
5342} // namespace resource
5443} // namespace sdk
5544OPENTELEMETRY_END_NAMESPACE
Original file line number Diff line number Diff line change @@ -57,17 +57,6 @@ cc_library(
5757 ],
5858)
5959
60- cc_library (
61- name = "container" ,
62- srcs = [
63- "container.cc" ,
64- ],
65- deps = [
66- "//api" ,
67- "//sdk:headers" ,
68- ],
69- )
70-
7160cc_library (
7261 name = "global_log_handler" ,
7362 srcs = [
Original file line number Diff line number Diff line change 11# Copyright The OpenTelemetry Authors
22# SPDX-License-Identifier: Apache-2.0
33
4- set (COMMON_SRCS random.cc global_log_handler.cc env_variables.cc container .cc
5- base64.cc disabled.cc)
4+ set (COMMON_SRCS random.cc global_log_handler.cc env_variables.cc base64 .cc
5+ disabled.cc)
66if (WIN32 )
77 list (APPEND COMMON_SRCS platform/fork_windows.cc)
88else ()
Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ cc_library(
1010 deps = [
1111 "//api" ,
1212 "//sdk:headers" ,
13- "//sdk/src/common:container" ,
1413 "//sdk/src/common:env_variables" ,
1514 ],
1615)
Original file line number Diff line number Diff line change 11# Copyright The OpenTelemetry Authors
22# SPDX-License-Identifier: Apache-2.0
33
4- add_library (opentelemetry_resources resource .cc resource_detector.cc
5- container_detector.cc)
4+ add_library (opentelemetry_resources resource .cc resource_detector.cc
5+ container.cc container_detector.cc)
66
77set_target_properties (opentelemetry_resources PROPERTIES EXPORT_NAME resources)
88set_target_version(opentelemetry_resources)
Original file line number Diff line number Diff line change 11// Copyright The OpenTelemetry Authors
22// SPDX-License-Identifier: Apache-2.0
33
4- #include " opentelemetry/sdk/common/container .h"
4+ #include " opentelemetry/sdk/resource/container_resource_detector .h"
55
66#include < fstream>
77#include < regex>
1111OPENTELEMETRY_BEGIN_NAMESPACE
1212namespace sdk
1313{
14- namespace common
14+ namespace resource
1515{
1616std::string GetContainerIDFromCgroup (const char *file_path)
1717{
@@ -41,6 +41,6 @@ std::string ExtractContainerIDFromLine(const std::string &line)
4141
4242 return " " ;
4343}
44- } // namespace common
44+ } // namespace resource
4545} // namespace sdk
4646OPENTELEMETRY_END_NAMESPACE
Original file line number Diff line number Diff line change 22// SPDX-License-Identifier: Apache-2.0
33
44#include " opentelemetry/nostd/variant.h"
5- #include " opentelemetry/sdk/common/container .h"
5+ #include " opentelemetry/sdk/resource/container_resource_detector .h"
66#include " opentelemetry/sdk/resource/resource.h"
7- #include " opentelemetry/sdk/resource/resource_detector.h"
87#include " opentelemetry/semconv/incubating/container_attributes.h"
98#include " opentelemetry/version.h"
109
@@ -24,7 +23,7 @@ const char *KCGroupPath = "/proc/self/cgroup";
2423
2524Resource ContainerResourceDetector::Detect () noexcept
2625{
27- std::string container_id = opentelemetry::sdk::common ::GetContainerIDFromCgroup (KCGroupPath);
26+ std::string container_id = opentelemetry::sdk::resource ::GetContainerIDFromCgroup (KCGroupPath);
2827 if (container_id.empty ())
2928 {
3029 return ResourceDetector::Create ({});
Original file line number Diff line number Diff line change 66#include < utility>
77
88#include " opentelemetry/nostd/variant.h"
9+ #include " opentelemetry/sdk/resource/container_resource_detector.h"
910#include " opentelemetry/sdk/resource/resource.h"
1011#include " opentelemetry/sdk/resource/resource_detector.h"
1112#include " opentelemetry/sdk/version/version.h"
You can’t perform that action at this time.
0 commit comments