Skip to content

Commit 4dff60a

Browse files
authored
Opentracing shim (#1909)
1 parent 9a5bb8d commit 4dff60a

28 files changed

+2392
-6
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ jobs:
131131
sudo ./ci/install_abseil.sh
132132
./ci/do_ci.sh cmake.abseil.test
133133
134+
cmake_opentracing_shim_test:
135+
name: CMake test (with opentracing-shim)
136+
runs-on: ubuntu-latest
137+
steps:
138+
- uses: actions/checkout@v3
139+
with:
140+
submodules: 'recursive'
141+
- name: setup
142+
run: |
143+
sudo ./ci/setup_cmake.sh
144+
sudo ./ci/setup_ci_environment.sh
145+
- name: run cmake tests (enable opentracing-shim)
146+
run: ./ci/do_ci.sh cmake.opentracing_shim.test
147+
134148
cmake_gcc_48_test:
135149
name: CMake gcc 4.8 (without otlp exporter)
136150
runs-on: ubuntu-18.04

.gitmodules

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ branch = main
3232
path = third_party/nlohmann-json
3333
url = https://github.com/nlohmann/json
3434
branch = master
35+
36+
[submodule "third_party/opentracing-cpp"]
37+
path = third_party/opentracing-cpp
38+
url = https://github.com/opentracing/opentracing-cpp.git
39+
branch = master

CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ option(BUILD_W3CTRACECONTEXT_TEST "Whether to build w3c trace context" OFF)
179179

180180
option(OTELCPP_MAINTAINER_MODE "Build in maintainer mode (-Wall -Werror)" OFF)
181181

182+
option(WITH_OPENTRACING "Whether to include the Opentracing shim" OFF)
183+
182184
set(OTELCPP_PROTO_PATH
183185
""
184186
CACHE PATH "Path to opentelemetry-proto")
@@ -536,6 +538,29 @@ include_directories(api/include)
536538

537539
add_subdirectory(api)
538540

541+
if(WITH_OPENTRACING)
542+
find_package(OpenTracing CONFIG QUIET)
543+
if(NOT OpenTracing_FOUND)
544+
set(OPENTRACING_DIR "third_party/opentracing-cpp")
545+
message("Trying to use local ${OPENTRACING_DIR} from submodule")
546+
if(EXISTS "${PROJECT_SOURCE_DIR}/${OPENTRACING_DIR}/.git")
547+
set(SAVED_BUILD_TESTING ${BUILD_TESTING})
548+
set(BUILD_TESTING OFF)
549+
add_subdirectory(${OPENTRACING_DIR})
550+
set(BUILD_TESTING ${SAVED_BUILD_TESTING})
551+
else()
552+
message(
553+
FATAL_ERROR
554+
"\nopentracing-cpp package was not found. Please either provide it manually or clone with submodules. "
555+
"To initialize, fetch and checkout any nested submodules, you can use the following command:\n"
556+
"git submodule update --init --recursive")
557+
endif()
558+
else()
559+
message("Using external opentracing-cpp")
560+
endif()
561+
add_subdirectory(opentracing-shim)
562+
endif()
563+
539564
if(NOT WITH_API_ONLY)
540565
set(BUILD_TESTING ${BUILD_TESTING})
541566
include_directories(sdk/include)
@@ -545,6 +570,7 @@ if(NOT WITH_API_ONLY)
545570
add_subdirectory(sdk)
546571
add_subdirectory(ext)
547572
add_subdirectory(exporters)
573+
548574
if(BUILD_TESTING)
549575
add_subdirectory(test_common)
550576
endif()

bazel/repository.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ def opentelemetry_cpp_deps():
182182
],
183183
)
184184

185+
# Opentracing
186+
maybe(
187+
http_archive,
188+
name = "com_github_opentracing",
189+
sha256 = "5b170042da4d1c4c231df6594da120875429d5231e9baa5179822ee8d1054ac3",
190+
strip_prefix = "opentracing-cpp-1.6.0",
191+
urls = [
192+
"https://github.com/opentracing/opentracing-cpp/archive/refs/tags/v1.6.0.tar.gz",
193+
],
194+
)
195+
185196
# boost headers from vcpkg
186197
maybe(
187198
native.new_local_repository,

ci/do_ci.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $VCPKG_DIR = Join-Path "$SRC_DIR" "tools" "vcpkg"
2525

2626
switch ($action) {
2727
"bazel.build" {
28-
bazel build --copt=-DENABLE_TEST $BAZEL_OPTIONS --action_env=VCPKG_DIR=$VCPKG_DIR -- //...
28+
bazel build --copt=-DENABLE_TEST $BAZEL_OPTIONS --action_env=VCPKG_DIR=$VCPKG_DIR --deleted_packages=opentracing-shim -- //...
2929
$exit = $LASTEXITCODE
3030
if ($exit -ne 0) {
3131
exit $exit

ci/do_ci.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ elif [[ "$1" == "cmake.abseil.test" ]]; then
141141
make
142142
make test
143143
exit 0
144+
elif [[ "$1" == "cmake.opentracing_shim.test" ]]; then
145+
cd "${BUILD_DIR}"
146+
rm -rf *
147+
cmake -DCMAKE_BUILD_TYPE=Debug \
148+
-DCMAKE_CXX_FLAGS="-Werror -Wno-error=redundant-move $CXXFLAGS" \
149+
-DWITH_OPENTRACING=ON \
150+
"${SRC_DIR}"
151+
make
152+
make test
153+
exit 0
144154
elif [[ "$1" == "cmake.c++20.test" ]]; then
145155
cd "${BUILD_DIR}"
146156
rm -rf *
@@ -282,13 +292,14 @@ elif [[ "$1" == "bazel.legacy.test" ]]; then
282292
exit 0
283293
elif [[ "$1" == "bazel.noexcept" ]]; then
284294
# there are some exceptions and error handling code from the Prometheus and Jaeger Clients
285-
# that make this test always fail. ignore Prometheus and Jaeger exporters in the noexcept here.
286-
bazel $BAZEL_STARTUP_OPTIONS build --copt=-fno-exceptions --build_tag_filters=-jaeger $BAZEL_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//exporters/jaeger/... -//examples/prometheus/... -//sdk/test/metrics:attributes_hashmap_test
287-
bazel $BAZEL_STARTUP_OPTIONS test --copt=-fno-exceptions --build_tag_filters=-jaeger $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//exporters/jaeger/... -//examples/prometheus/... -//sdk/test/metrics:attributes_hashmap_test
295+
# as well as Opentracing shim (due to some third party code in its Opentracing dependency)
296+
# that make this test always fail. Ignore these packages in the noexcept test here.
297+
bazel $BAZEL_STARTUP_OPTIONS build --copt=-fno-exceptions --build_tag_filters=-jaeger $BAZEL_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//exporters/jaeger/... -//examples/prometheus/... -//sdk/test/metrics:attributes_hashmap_test -//opentracing-shim/...
298+
bazel $BAZEL_STARTUP_OPTIONS test --copt=-fno-exceptions --build_tag_filters=-jaeger $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//exporters/jaeger/... -//examples/prometheus/... -//sdk/test/metrics:attributes_hashmap_test -//opentracing-shim/...
288299
exit 0
289300
elif [[ "$1" == "bazel.nortti" ]]; then
290301
# there are some exceptions and error handling code from the Prometheus and Jaeger Clients
291-
# that make this test always fail. ignore Prometheus and Jaeger exporters in the noexcept here.
302+
# that make this test always fail. Ignore these packages in the nortti test here.
292303
bazel $BAZEL_STARTUP_OPTIONS build --cxxopt=-fno-rtti --build_tag_filters=-jaeger $BAZEL_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//exporters/jaeger/...
293304
bazel $BAZEL_STARTUP_OPTIONS test --cxxopt=-fno-rtti --build_tag_filters=-jaeger $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//exporters/jaeger/...
294305
exit 0

cmake/opentelemetry-cpp-config.cmake.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
# opentelemetry-cpp::jaeger_trace_exporter - Imported target of opentelemetry-cpp::jaeger_trace_exporter
5050
# opentelemetry-cpp::zpages - Imported target of opentelemetry-cpp::zpages
5151
# opentelemetry-cpp::http_client_curl - Imported target of opentelemetry-cpp::http_client_curl
52+
# opentelemetry-cpp::opentracing_shim - Imported target of opentelemetry-cpp::opentracing_shim
5253
#
5354

5455
# =============================================================================
@@ -102,7 +103,8 @@ set(_OPENTELEMETRY_CPP_LIBRARIES_TEST_TARGETS
102103
etw_exporter
103104
jaeger_trace_exporter
104105
zpages
105-
http_client_curl)
106+
http_client_curl
107+
opentracing_shim)
106108
foreach(_TEST_TARGET IN LISTS _OPENTELEMETRY_CPP_LIBRARIES_TEST_TARGETS)
107109
if(TARGET opentelemetry-cpp::${_TEST_TARGET})
108110
list(APPEND OPENTELEMETRY_CPP_LIBRARIES opentelemetry-cpp::${_TEST_TARGET})

docs/dependencies.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,10 @@ Both these dependencies are listed here:
104104

105105
- [Zpages](/ext/src/zpages):
106106
- None
107+
108+
- [Opentracing](/opentracing-shim)
109+
shim:
110+
- [`opentracing-cpp`](https://github.com/opentracing/opentracing-cpp)
111+
OpenTracing API for C++
112+
- A bridge layer implementing the OpenTracing API using the OpenTelemetry API
113+
- License: `Apache License 2.0`

opentracing-shim/BUILD

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
package(default_visibility = ["//visibility:public"])
5+
6+
cc_library(
7+
name = "opentracing_shim",
8+
srcs = [
9+
"src/shim_utils.cc",
10+
"src/span_context_shim.cc",
11+
"src/span_shim.cc",
12+
"src/tracer_shim.cc",
13+
],
14+
hdrs = [
15+
"include/opentelemetry/opentracingshim/propagation.h",
16+
"include/opentelemetry/opentracingshim/shim_utils.h",
17+
"include/opentelemetry/opentracingshim/span_context_shim.h",
18+
"include/opentelemetry/opentracingshim/span_shim.h",
19+
"include/opentelemetry/opentracingshim/tracer_shim.h",
20+
],
21+
strip_include_prefix = "include",
22+
tags = ["opentracing"],
23+
deps = [
24+
"//api",
25+
"@com_github_opentracing//:opentracing",
26+
],
27+
)
28+
29+
cc_test(
30+
name = "propagation_test",
31+
srcs = [
32+
"test/propagation_test.cc",
33+
"test/shim_mocks.h",
34+
],
35+
tags = [
36+
"opentracing_shim",
37+
"test",
38+
],
39+
deps = [
40+
":opentracing_shim",
41+
"@com_google_googletest//:gtest_main",
42+
],
43+
)
44+
45+
cc_test(
46+
name = "shim_utils_test",
47+
srcs = [
48+
"test/shim_mocks.h",
49+
"test/shim_utils_test.cc",
50+
],
51+
tags = [
52+
"opentracing_shim",
53+
"test",
54+
],
55+
deps = [
56+
":opentracing_shim",
57+
"@com_google_googletest//:gtest_main",
58+
],
59+
)
60+
61+
cc_test(
62+
name = "span_shim_test",
63+
srcs = [
64+
"test/shim_mocks.h",
65+
"test/span_shim_test.cc",
66+
],
67+
tags = [
68+
"opentracing_shim",
69+
"test",
70+
],
71+
deps = [
72+
":opentracing_shim",
73+
"@com_google_googletest//:gtest_main",
74+
],
75+
)
76+
77+
cc_test(
78+
name = "span_context_shim_test",
79+
srcs = [
80+
"test/span_context_shim_test.cc",
81+
],
82+
tags = [
83+
"opentracing_shim",
84+
"test",
85+
],
86+
deps = [
87+
":opentracing_shim",
88+
"@com_google_googletest//:gtest_main",
89+
],
90+
)
91+
92+
cc_test(
93+
name = "tracer_shim_test",
94+
srcs = [
95+
"test/shim_mocks.h",
96+
"test/tracer_shim_test.cc",
97+
],
98+
tags = [
99+
"opentracing_shim",
100+
"test",
101+
],
102+
deps = [
103+
":opentracing_shim",
104+
"@com_google_googletest//:gtest_main",
105+
],
106+
)

opentracing-shim/CMakeLists.txt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
set(this_target opentelemetry_opentracing_shim)
5+
6+
add_library(${this_target} src/shim_utils.cc src/span_shim.cc
7+
src/span_context_shim.cc src/tracer_shim.cc)
8+
9+
set_target_properties(${this_target} PROPERTIES EXPORT_NAME opentracing_shim)
10+
11+
target_include_directories(
12+
${this_target} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
13+
"$<INSTALL_INTERFACE:include>")
14+
15+
if(OPENTRACING_DIR)
16+
include_directories(
17+
"${CMAKE_BINARY_DIR}/${OPENTRACING_DIR}/include"
18+
"${CMAKE_SOURCE_DIR}/${OPENTRACING_DIR}/include"
19+
"${CMAKE_SOURCE_DIR}/${OPENTRACING_DIR}/3rd_party/include")
20+
target_link_libraries(${this_target} opentelemetry_api opentracing)
21+
else()
22+
target_link_libraries(${this_target} opentelemetry_api
23+
OpenTracing::opentracing)
24+
endif()
25+
26+
install(
27+
TARGETS ${this_target}
28+
EXPORT "${PROJECT_NAME}-target"
29+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
30+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
31+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
32+
33+
install(
34+
DIRECTORY include/opentelemetry/opentracingshim
35+
DESTINATION include/opentelemetry
36+
FILES_MATCHING
37+
PATTERN "*.h")
38+
39+
if(BUILD_TESTING)
40+
foreach(testname propagation_test shim_utils_test span_shim_test
41+
span_context_shim_test tracer_shim_test)
42+
43+
add_executable(${testname} "test/${testname}.cc")
44+
45+
if(OPENTRACING_DIR)
46+
target_link_libraries(
47+
${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
48+
opentelemetry_api opentelemetry_opentracing_shim opentracing)
49+
else()
50+
target_link_libraries(
51+
${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
52+
opentelemetry_api opentelemetry_opentracing_shim
53+
OpenTracing::opentracing)
54+
endif()
55+
56+
gtest_add_tests(
57+
TARGET ${testname}
58+
TEST_PREFIX opentracing_shim.
59+
TEST_LIST ${testname})
60+
endforeach()
61+
endif() # BUILD_TESTING

0 commit comments

Comments
 (0)