Skip to content

Commit d3578dd

Browse files
committed
use STL with opentelemetry for variant
1 parent 0fdba06 commit d3578dd

File tree

10 files changed

+304
-35
lines changed

10 files changed

+304
-35
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
diff --git a/cmake/opentracing-cpp.cmake b/cmake/opentracing-cpp.cmake
2+
index f014ecd..fd8898a 100644
3+
--- a/cmake/opentracing-cpp.cmake
4+
+++ b/cmake/opentracing-cpp.cmake
5+
@@ -1,7 +1,11 @@
6+
# Copyright The OpenTelemetry Authors
7+
# SPDX-License-Identifier: Apache-2.0
8+
9+
-find_package(OpenTracing CONFIG QUIET)
10+
+find_package(OpenTracing CONFIG REQUIRED)
11+
+if(NOT TARGET OpenTracing::opentracing AND TARGET OpenTracing::opentracing-static)
12+
+ add_library(OpenTracing::opentracing ALIAS OpenTracing::opentracing-static)
13+
+endif()
14+
+
15+
set(OpenTracing_PROVIDER "find_package")
16+
17+
if(NOT OpenTracing_FOUND)
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
if (VCPKG_TARGET_IS_WINDOWS)
2+
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
3+
endif ()
4+
5+
vcpkg_from_github(
6+
OUT_SOURCE_PATH
7+
SOURCE_PATH
8+
REPO
9+
open-telemetry/opentelemetry-cpp
10+
REF
11+
"v${VERSION}"
12+
SHA512
13+
6dc0357d8b3410852d3f970f72b8bec59dba9d6c533ca600432102e65de161903bd9170d98cef7ff0af5191309577ffd2a69ccd004b840914a910a6a282204e4
14+
HEAD_REF
15+
main
16+
PATCHES
17+
fix-target_link.patch)
18+
19+
vcpkg_check_features(
20+
OUT_FEATURE_OPTIONS
21+
FEATURE_OPTIONS
22+
FEATURES
23+
etw
24+
WITH_ETW
25+
zipkin
26+
WITH_ZIPKIN
27+
prometheus
28+
WITH_PROMETHEUS
29+
elasticsearch
30+
WITH_ELASTICSEARCH
31+
otlp-file
32+
WITH_OTLP_FILE
33+
otlp-http
34+
WITH_OTLP_HTTP
35+
otlp-grpc
36+
WITH_OTLP_GRPC
37+
geneva
38+
WITH_GENEVA
39+
user-events
40+
WITH_USER_EVENTS
41+
opentracing
42+
WITH_OPENTRACING
43+
INVERTED_FEATURES
44+
user-events
45+
BUILD_TRACEPOINTS)
46+
47+
# opentelemetry-proto is a third party submodule and opentelemetry-cpp release
48+
# did not pack it.
49+
if (WITH_OTLP_FILE
50+
OR WITH_OTLP_GRPC
51+
OR WITH_OTLP_HTTP)
52+
set(OTEL_PROTO_VERSION "1.6.0")
53+
vcpkg_download_distfile(
54+
ARCHIVE
55+
URLS
56+
"https://github.com/open-telemetry/opentelemetry-proto/archive/v${OTEL_PROTO_VERSION}.tar.gz"
57+
FILENAME
58+
"opentelemetry-proto-${OTEL_PROTO_VERSION}.tar.gz"
59+
SHA512
60+
0e72e0c32d2d699d7a832a4c57a9dbe60e844d4c4e8d7b39eb45e4282cde89fccfeef893eae70b9d018643782090a7228c3ef60863b00747498e80f0cf1db8ae
61+
)
62+
63+
vcpkg_extract_source_archive(src ARCHIVE "${ARCHIVE}")
64+
file(REMOVE_RECURSE "${SOURCE_PATH}/third_party/opentelemetry-proto")
65+
file(COPY "${src}/."
66+
DESTINATION "${SOURCE_PATH}/third_party/opentelemetry-proto")
67+
# Create empty .git directory to prevent opentelemetry from cloning it
68+
# during build time
69+
file(MAKE_DIRECTORY "${SOURCE_PATH}/third_party/opentelemetry-proto/.git")
70+
list(
71+
APPEND
72+
FEATURE_OPTIONS
73+
"-DgRPC_CPP_PLUGIN_EXECUTABLE=${CURRENT_HOST_INSTALLED_DIR}/tools/grpc/grpc_cpp_plugin${VCPKG_HOST_EXECUTABLE_SUFFIX}"
74+
)
75+
endif ()
76+
list(APPEND FEATURE_OPTIONS -DCMAKE_CXX_STANDARD=17)
77+
list(APPEND FEATURE_OPTIONS -DWITH_STL=CXX17)
78+
79+
set(OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS "OFF")
80+
81+
if (WITH_GENEVA OR WITH_USER_EVENTS)
82+
# Geneva and user events exporters from opentelemetry-cpp-contrib are
83+
# tightly coupled with opentelemetry-cpp repo, so they should be ported as a
84+
# feature under opentelemetry-cpp.
85+
clone_opentelemetry_cpp_contrib(CONTRIB_SOURCE_PATH)
86+
87+
if (WITH_GENEVA)
88+
set(OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS
89+
"${CONTRIB_SOURCE_PATH}/exporters/geneva")
90+
if (VCPKG_TARGET_IS_WINDOWS)
91+
set(OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS
92+
"${OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS}\;${CONTRIB_SOURCE_PATH}/exporters/geneva-trace"
93+
)
94+
else ()
95+
set(OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS
96+
"${OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS}\;${CONTRIB_SOURCE_PATH}/exporters/fluentd"
97+
)
98+
endif ()
99+
endif ()
100+
101+
if (WITH_USER_EVENTS)
102+
if (WITH_GENEVA)
103+
set(OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS
104+
"${OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS}\;${CONTRIB_SOURCE_PATH}/exporters/user_events"
105+
)
106+
else ()
107+
set(OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS
108+
"${CONTRIB_SOURCE_PATH}/exporters/user_events")
109+
endif ()
110+
endif ()
111+
endif ()
112+
113+
vcpkg_cmake_configure(
114+
SOURCE_PATH
115+
"${SOURCE_PATH}"
116+
OPTIONS
117+
-DBUILD_TESTING=OFF
118+
-DWITH_EXAMPLES=OFF
119+
-DOPENTELEMETRY_INSTALL=ON
120+
-DWITH_BENCHMARK=OFF
121+
-DOPENTELEMETRY_EXTERNAL_COMPONENT_PATH=${OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS}
122+
${FEATURE_OPTIONS}
123+
MAYBE_UNUSED_VARIABLES
124+
WITH_GENEVA
125+
WITH_USER_EVENTS
126+
BUILD_TRACEPOINTS
127+
gRPC_CPP_PLUGIN_EXECUTABLE)
128+
129+
vcpkg_cmake_install()
130+
vcpkg_cmake_config_fixup(CONFIG_PATH "lib/cmake/${PORT}")
131+
vcpkg_copy_pdbs()
132+
133+
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
134+
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
135+
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
3+
"name": "opentelemetry-cpp",
4+
"version-semver": "1.23.0",
5+
"description": [
6+
"OpenTelemetry is a collection of tools, APIs, and SDKs.",
7+
"You use it to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) for analysis in order to understand your software's performance and behavior."
8+
],
9+
"homepage": "https://github.com/open-telemetry/opentelemetry-cpp",
10+
"license": "Apache-2.0",
11+
"dependencies": [
12+
"abseil",
13+
"nlohmann-json",
14+
{
15+
"name": "vcpkg-cmake",
16+
"host": true
17+
},
18+
{
19+
"name": "vcpkg-cmake-config",
20+
"host": true
21+
}
22+
],
23+
"features": {
24+
"elasticsearch": {
25+
"description": "Whether to include the Elasticsearch Client in the SDK",
26+
"dependencies": [
27+
{
28+
"name": "curl",
29+
"default-features": false
30+
}
31+
]
32+
},
33+
"etw": {
34+
"description": "Whether to include the ETW Exporter in the SDK",
35+
"supports": "windows"
36+
},
37+
"geneva": {
38+
"description": "Whether to include the Geneva Exporter from the opentelemetry-cpp-contrib repository",
39+
"dependencies": [
40+
{
41+
"name": "opentelemetry-cpp",
42+
"features": [
43+
"etw"
44+
],
45+
"platform": "windows"
46+
},
47+
"opentelemetry-cpp-contrib-version"
48+
]
49+
},
50+
"opentracing": {
51+
"description": "Whether to include the Opentracing shim",
52+
"dependencies": [
53+
"opentracing"
54+
]
55+
},
56+
"otlp-file": {
57+
"description": "Whether to include the OpenTelemetry Protocol to File exporter in the SDK",
58+
"supports": "!uwp",
59+
"dependencies": [
60+
"protobuf"
61+
]
62+
},
63+
"otlp-grpc": {
64+
"description": "Whether to include the OTLP gRPC exporter in the SDK",
65+
"dependencies": [
66+
"grpc",
67+
{
68+
"name": "grpc",
69+
"host": true
70+
}
71+
]
72+
},
73+
"otlp-http": {
74+
"description": "Whether to include the OpenTelemetry Protocol over HTTP in the SDK",
75+
"dependencies": [
76+
"curl",
77+
"protobuf"
78+
]
79+
},
80+
"prometheus": {
81+
"description": "Whether to include the Prometheus Client in the SDK",
82+
"dependencies": [
83+
"prometheus-cpp"
84+
]
85+
},
86+
"user-events": {
87+
"description": "Whether to include the User Events Exporter from the opentelemetry-cpp-contrib repository",
88+
"supports": "linux",
89+
"dependencies": [
90+
"libeventheader-tracepoint",
91+
"libtracepoint",
92+
{
93+
"name": "opentelemetry-cpp",
94+
"features": [
95+
"otlp-http"
96+
]
97+
},
98+
"opentelemetry-cpp-contrib-version"
99+
]
100+
},
101+
"zipkin": {
102+
"description": "Whether to include the Zipkin exporter in the SDK",
103+
"dependencies": [
104+
"curl"
105+
]
106+
}
107+
}
108+
}

ci/etc/oldest-deps/vcpkg.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"$TODO": "move `gtest` and `benchmark` to dev-dependencies",
99
"builtin-baseline": "6d9ed568117dd958c543b3ab8d3ed692965cac34",
1010
"dependencies": [
11-
{"name": "abseil", "version>=": "2020-09-23#3"},
11+
{"name": "abseil", "version>=": "20250127.1"},
1212
{"name": "crc32c", "version>=": "1.1.1"},
1313
{
1414
"name": "curl",
@@ -27,17 +27,21 @@
2727
"host": true
2828
},
2929
{"name": "grpc", "version>=": "1.33.1"},
30-
{"name": "opentelemetry-cpp", "version>=": "1.9.1"},
30+
{"name": "opentelemetry-cpp", "version>=": "1.20.0"},
3131
{"name": "protobuf", "version>=": "3.15.8"},
3232
{"name": "nlohmann-json", "version>=": "3.9.1"},
3333
"benchmark",
3434
{"name": "gtest", "version>=": "1.11.0", "host": true}
3535
],
3636
"overrides": [
37-
{ "name": "opentelemetry-cpp", "version": "1.9.1"},
37+
{ "name": "abseil", "version": "20250127.1"},
38+
{ "name": "opentelemetry-cpp", "version": "1.20.0"},
3839
{ "name": "protobuf", "version": "3.15.8" },
3940
{ "name": "grpc", "version": "1.36.4" },
4041
{ "name": "upb", "version": "2020-12-19" },
4142
{ "name": "gtest", "version": "1.12.0" }
42-
]
43+
],
44+
"configuration": {
45+
"overlay-ports" : [ "overlay-ports"]
46+
}
4347
}

ci/etc/vcpkg-version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2024.09.30
1+
2025.10.17

google/cloud/opentelemetry/internal/monitored_resource.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <algorithm>
2929
#include <numeric>
3030
#include <unordered_map>
31+
#include <variant>
3132

3233
namespace google {
3334
namespace cloud {
@@ -235,7 +236,7 @@ MonitoredResourceProvider MakeProvider(
235236

236237
std::string AsString(
237238
opentelemetry::sdk::common::OwnedAttributeValue const& attribute) {
238-
return absl::visit(AsStringVisitor{}, attribute);
239+
return std::visit(AsStringVisitor{}, attribute);
239240
}
240241

241242
MonitoredResource ToMonitoredResource(

google/cloud/opentelemetry/internal/monitoring_exporter_test.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <gmock/gmock.h>
2121
#include <opentelemetry/sdk/metrics/export/metric_producer.h>
2222
#include <opentelemetry/sdk/resource/resource.h>
23+
#include <variant>
2324

2425
namespace google {
2526
namespace cloud {
@@ -134,15 +135,14 @@ TEST(MonitoringExporter, ExportSuccess) {
134135
auto& labels = *resource.mutable_labels();
135136
auto const& attributes = pda.attributes.GetAttributes();
136137
labels["project_id"] =
137-
absl::get<std::string>(attributes.find("project_id")->second);
138+
std::get<std::string>(attributes.find("project_id")->second);
138139
labels["instance"] =
139-
absl::get<std::string>(attributes.find("instance")->second);
140+
std::get<std::string>(attributes.find("instance")->second);
140141
labels["cluster"] =
141-
absl::get<std::string>(attributes.find("cluster")->second);
142+
std::get<std::string>(attributes.find("cluster")->second);
142143
labels["table"] =
143-
absl::get<std::string>(attributes.find("table")->second);
144-
labels["zone"] =
145-
absl::get<std::string>(attributes.find("zone")->second);
144+
std::get<std::string>(attributes.find("table")->second);
145+
labels["zone"] = std::get<std::string>(attributes.find("zone")->second);
146146
return std::make_pair(labels["project_id"], resource);
147147
};
148148

google/cloud/opentelemetry/internal/recordable.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ void AddAttributeImpl(
208208
std::size_t limit) {
209209
auto* proto = ProtoOrDrop(attributes, key, limit);
210210
if (proto) {
211-
absl::visit(AttributeVisitor{*proto}, value);
211+
std::visit(AttributeVisitor{*proto}, value);
212212
} else {
213213
attributes.set_dropped_attributes_count(
214214
attributes.dropped_attributes_count() + 1);

0 commit comments

Comments
 (0)