Skip to content

Commit 00decf9

Browse files
ci and requested changes
1 parent f075c93 commit 00decf9

File tree

11 files changed

+58
-68
lines changed

11 files changed

+58
-68
lines changed

sdk/include/opentelemetry/sdk/common/container.h

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

sdk/include/opentelemetry/sdk/resource/resource_detector.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff 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
5544
OPENTELEMETRY_END_NAMESPACE

sdk/src/common/BUILD

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff 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-
7160
cc_library(
7261
name = "global_log_handler",
7362
srcs = [

sdk/src/common/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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)
66
if(WIN32)
77
list(APPEND COMMON_SRCS platform/fork_windows.cc)
88
else()

sdk/src/resource/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff 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
)

sdk/src/resource/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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

77
set_target_properties(opentelemetry_resources PROPERTIES EXPORT_NAME resources)
88
set_target_version(opentelemetry_resources)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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>
@@ -11,7 +11,7 @@
1111
OPENTELEMETRY_BEGIN_NAMESPACE
1212
namespace sdk
1313
{
14-
namespace common
14+
namespace resource
1515
{
1616
std::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
4646
OPENTELEMETRY_END_NAMESPACE

sdk/src/resource/container_detector.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
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

2524
Resource 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({});

sdk/src/resource/resource.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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"

0 commit comments

Comments
 (0)