Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opentracing shim #1909

Merged
merged 66 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
45e0c4b
First attempt
chusitoo Jan 1, 2023
321a801
Tracer unit tests wip
chusitoo Jan 2, 2023
36cca42
Add more comments from compatibility section
chusitoo Jan 2, 2023
81b8557
More tracer unit tests
chusitoo Jan 3, 2023
1fc7f33
Unit tests for shim utils
chusitoo Jan 4, 2023
4d99b85
Unit tests for span context shim
chusitoo Jan 4, 2023
22949e2
Unit tests for span shim
chusitoo Jan 4, 2023
f62eb78
Cleanup and more unit tests
chusitoo Jan 4, 2023
25aeac8
Reduce copying for StartSpan
chusitoo Jan 5, 2023
8f10779
Implement span context shim trace_id and span_id
chusitoo Jan 5, 2023
697c402
Update CMakeFile build and install
chusitoo Jan 6, 2023
2d2adf3
Add Bazel build, fix failing test
chusitoo Jan 8, 2023
5d15422
Add README
chusitoo Jan 8, 2023
32ba915
Additional tests and cleanup
chusitoo Jan 9, 2023
ddd71ab
Merge remote-tracking branch 'remotes/origin/main' into opentracing-shim
chusitoo Jan 9, 2023
4d91681
Disable by default
chusitoo Jan 9, 2023
cf5c93e
Merge branch 'main' into opentracing-shim
lalitb Jan 9, 2023
0c55471
Fixes for markdownlint
chusitoo Jan 9, 2023
43114f5
Exclude shim from bazel.noexcept and bazel.nortti
chusitoo Jan 10, 2023
fd03fcc
Value string conversion to Attribute is unsupported
chusitoo Jan 10, 2023
a0a5366
Fix format
chusitoo Jan 10, 2023
9df7351
Minor UT tuning
chusitoo Jan 10, 2023
96da882
Enable Opentracing shim in cmake.maintainer.test job
chusitoo Jan 10, 2023
b9178ef
Link with Opentracing lib
chusitoo Jan 10, 2023
20c99ec
Cannot compile shim for Windows because Opentracing Bazel build suppo…
chusitoo Jan 11, 2023
ba50b4d
Merge remote-tracking branch 'remotes/origin/main' into opentracing-shim
chusitoo Jan 11, 2023
7a0ca8d
Comments on why shim is ignored in some tests
chusitoo Jan 12, 2023
0708bb1
Move comments block inside function body
chusitoo Jan 12, 2023
32a291b
Merge remote-tracking branch 'remotes/origin/main' into opentracing-shim
chusitoo Jan 12, 2023
f6bc7de
Cleanup
chusitoo Jan 12, 2023
6636cc5
Fix error in package exclusion
chusitoo Jan 12, 2023
7b3d99a
Fix clang/gcc compilation warnings/errors
chusitoo Jan 12, 2023
18ff609
Move to own ci job
chusitoo Jan 13, 2023
0457d0b
Fix copy-paste error
chusitoo Jan 13, 2023
43ddff2
Format...
chusitoo Jan 14, 2023
d141674
Ignore CXXFLAGS for Opentracing
chusitoo Jan 14, 2023
3276cc0
Not sure why CI fails to exclude shim in Windows Bazel...
chusitoo Jan 14, 2023
07113bc
Fix typo in CXX flags
chusitoo Jan 15, 2023
a278709
Attempt removing shim via deleted_packages
chusitoo Jan 15, 2023
f74f67f
Disable redundant-move
chusitoo Jan 21, 2023
7c0a4df
Merge remote-tracking branch 'remotes/origin/main' into opentracing-shim
chusitoo Jan 21, 2023
20a0d9c
Merge remote-tracking branch 'remotes/origin/main' into opentracing-shim
chusitoo Jan 24, 2023
9d66d21
Merge remote-tracking branch 'remotes/origin/main' into opentracing-shim
chusitoo Jan 27, 2023
c4a38c1
Merge branch 'main' into opentracing-shim
chusitoo Feb 3, 2023
57b3051
Update references to OpenTracing
chusitoo Feb 6, 2023
cc360d7
Use static_cast when RTTI is disabled
chusitoo Feb 6, 2023
ecff298
Micro-optimizations
chusitoo Feb 6, 2023
4cf746f
Unit test for start span with error tag
chusitoo Feb 6, 2023
d500915
Remove exclusion of shim in bazel no-rtti test
chusitoo Feb 6, 2023
72ea0fb
Run opentracing-shim test job on latest Ubuntu
chusitoo Feb 6, 2023
1877e2d
Fix problems with UTs reported by Valgrind
chusitoo Feb 6, 2023
0f967df
Merge remote-tracking branch 'remotes/origin/main' into opentracing-shim
chusitoo Feb 7, 2023
241ff46
Put back string => string_view mapping
chusitoo Feb 8, 2023
f90d480
Merge branch 'main' into opentracing-shim
chusitoo Feb 8, 2023
afd1b4d
Add copyright and license
chusitoo Feb 9, 2023
f24c4cf
Merge branch 'main' into opentracing-shim
chusitoo Feb 10, 2023
60b880b
Merge branch 'main' into opentracing-shim
chusitoo Feb 10, 2023
2eadaf8
Merge branch 'main' into opentracing-shim
chusitoo Feb 10, 2023
36ead65
Merge branch 'main' into opentracing-shim
chusitoo Feb 10, 2023
55ae68e
Merge branch 'main' into opentracing-shim
chusitoo Feb 13, 2023
7a46efa
Merge branch 'main' into opentracing-shim
chusitoo Feb 15, 2023
52ecc0b
Merge branch 'main' into opentracing-shim
lalitb Feb 16, 2023
64edf81
Merge branch 'main' into opentracing-shim
marcalff Feb 20, 2023
a4cd537
Fix prometheus commit
chusitoo Feb 20, 2023
59108e4
Merge branch 'main' into opentracing-shim
lalitb Mar 3, 2023
ac8dc8f
Merge branch 'main' into opentracing-shim
esigo Mar 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ jobs:
sudo ./ci/install_abseil.sh
./ci/do_ci.sh cmake.abseil.test

cmake_opentracing_shim_test:
name: CMake test (with opentracing-shim)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: setup
run: |
sudo ./ci/setup_cmake.sh
sudo ./ci/setup_ci_environment.sh
- name: run cmake tests (enable opentracing-shim)
run: ./ci/do_ci.sh cmake.opentracing_shim.test

cmake_gcc_48_test:
name: CMake gcc 4.8 (without otlp exporter)
runs-on: ubuntu-18.04
Expand Down
5 changes: 5 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ branch = main
path = third_party/nlohmann-json
url = https://github.com/nlohmann/json
branch = master

[submodule "third_party/opentracing-cpp"]
path = third_party/opentracing-cpp
url = https://github.com/opentracing/opentracing-cpp.git
branch = master
26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ option(BUILD_W3CTRACECONTEXT_TEST "Whether to build w3c trace context" OFF)

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

option(WITH_OPENTRACING "Whether to include the Opentracing shim" OFF)

set(OTELCPP_PROTO_PATH
""
CACHE PATH "Path to opentelemetry-proto")
Expand Down Expand Up @@ -536,6 +538,29 @@ include_directories(api/include)

add_subdirectory(api)

if(WITH_OPENTRACING)
chusitoo marked this conversation as resolved.
Show resolved Hide resolved
find_package(OpenTracing CONFIG QUIET)
if(NOT OpenTracing_FOUND)
set(OPENTRACING_DIR "third_party/opentracing-cpp")
message("Trying to use local ${OPENTRACING_DIR} from submodule")
if(EXISTS "${PROJECT_SOURCE_DIR}/${OPENTRACING_DIR}/.git")
set(SAVED_BUILD_TESTING ${BUILD_TESTING})
set(BUILD_TESTING OFF)
add_subdirectory(${OPENTRACING_DIR})
set(BUILD_TESTING ${SAVED_BUILD_TESTING})
else()
message(
FATAL_ERROR
"\nopentracing-cpp package was not found. Please either provide it manually or clone with submodules. "
"To initialize, fetch and checkout any nested submodules, you can use the following command:\n"
"git submodule update --init --recursive")
endif()
else()
message("Using external opentracing-cpp")
endif()
add_subdirectory(opentracing-shim)
endif()

if(NOT WITH_API_ONLY)
set(BUILD_TESTING ${BUILD_TESTING})
include_directories(sdk/include)
Expand All @@ -545,6 +570,7 @@ if(NOT WITH_API_ONLY)
add_subdirectory(sdk)
add_subdirectory(ext)
add_subdirectory(exporters)

if(BUILD_TESTING)
add_subdirectory(test_common)
endif()
Expand Down
11 changes: 11 additions & 0 deletions bazel/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ def opentelemetry_cpp_deps():
],
)

# Opentracing
maybe(
http_archive,
name = "com_github_opentracing",
sha256 = "5b170042da4d1c4c231df6594da120875429d5231e9baa5179822ee8d1054ac3",
strip_prefix = "opentracing-cpp-1.6.0",
urls = [
"https://github.com/opentracing/opentracing-cpp/archive/refs/tags/v1.6.0.tar.gz",
chusitoo marked this conversation as resolved.
Show resolved Hide resolved
],
)

# boost headers from vcpkg
maybe(
native.new_local_repository,
Expand Down
2 changes: 1 addition & 1 deletion ci/do_ci.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $VCPKG_DIR = Join-Path "$SRC_DIR" "tools" "vcpkg"

switch ($action) {
"bazel.build" {
bazel build --copt=-DENABLE_TEST $BAZEL_OPTIONS --action_env=VCPKG_DIR=$VCPKG_DIR -- //...
bazel build --copt=-DENABLE_TEST $BAZEL_OPTIONS --action_env=VCPKG_DIR=$VCPKG_DIR --deleted_packages=opentracing-shim -- //...
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
Expand Down
19 changes: 15 additions & 4 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ elif [[ "$1" == "cmake.abseil.test" ]]; then
make
make test
exit 0
elif [[ "$1" == "cmake.opentracing_shim.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="-Werror -Wno-error=redundant-move $CXXFLAGS" \
-DWITH_OPENTRACING=ON \
"${SRC_DIR}"
make
make test
exit 0
elif [[ "$1" == "cmake.c++20.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
Expand Down Expand Up @@ -282,13 +292,14 @@ elif [[ "$1" == "bazel.legacy.test" ]]; then
exit 0
elif [[ "$1" == "bazel.noexcept" ]]; then
# there are some exceptions and error handling code from the Prometheus and Jaeger Clients
# that make this test always fail. ignore Prometheus and Jaeger exporters in the noexcept here.
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
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
# as well as Opentracing shim (due to some third party code in its Opentracing dependency)
# that make this test always fail. Ignore these packages in the noexcept test here.
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/...
chusitoo marked this conversation as resolved.
Show resolved Hide resolved
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/...
exit 0
elif [[ "$1" == "bazel.nortti" ]]; then
# there are some exceptions and error handling code from the Prometheus and Jaeger Clients
# that make this test always fail. ignore Prometheus and Jaeger exporters in the noexcept here.
# that make this test always fail. Ignore these packages in the nortti test here.
bazel $BAZEL_STARTUP_OPTIONS build --cxxopt=-fno-rtti --build_tag_filters=-jaeger $BAZEL_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//exporters/jaeger/...
bazel $BAZEL_STARTUP_OPTIONS test --cxxopt=-fno-rtti --build_tag_filters=-jaeger $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//exporters/jaeger/...
exit 0
Expand Down
4 changes: 3 additions & 1 deletion cmake/opentelemetry-cpp-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
# opentelemetry-cpp::jaeger_trace_exporter - Imported target of opentelemetry-cpp::jaeger_trace_exporter
# opentelemetry-cpp::zpages - Imported target of opentelemetry-cpp::zpages
# opentelemetry-cpp::http_client_curl - Imported target of opentelemetry-cpp::http_client_curl
# opentelemetry-cpp::opentracing_shim - Imported target of opentelemetry-cpp::opentracing_shim
#

# =============================================================================
Expand Down Expand Up @@ -102,7 +103,8 @@ set(_OPENTELEMETRY_CPP_LIBRARIES_TEST_TARGETS
etw_exporter
jaeger_trace_exporter
zpages
http_client_curl)
http_client_curl
opentracing_shim)
foreach(_TEST_TARGET IN LISTS _OPENTELEMETRY_CPP_LIBRARIES_TEST_TARGETS)
if(TARGET opentelemetry-cpp::${_TEST_TARGET})
list(APPEND OPENTELEMETRY_CPP_LIBRARIES opentelemetry-cpp::${_TEST_TARGET})
Expand Down
7 changes: 7 additions & 0 deletions docs/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,10 @@ Both these dependencies are listed here:

- [Zpages](/ext/src/zpages):
- None

- [Opentracing](/opentracing-shim)
shim:
- [`opentracing-cpp`](https://github.com/opentracing/opentracing-cpp)
OpenTracing API for C++
- A bridge layer implementing the OpenTracing API using the OpenTelemetry API
- License: `Apache License 2.0`
106 changes: 106 additions & 0 deletions opentracing-shim/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

package(default_visibility = ["//visibility:public"])

cc_library(
name = "opentracing_shim",
srcs = [
"src/shim_utils.cc",
"src/span_context_shim.cc",
"src/span_shim.cc",
"src/tracer_shim.cc",
],
hdrs = [
"include/opentelemetry/opentracingshim/propagation.h",
"include/opentelemetry/opentracingshim/shim_utils.h",
"include/opentelemetry/opentracingshim/span_context_shim.h",
"include/opentelemetry/opentracingshim/span_shim.h",
"include/opentelemetry/opentracingshim/tracer_shim.h",
],
strip_include_prefix = "include",
tags = ["opentracing"],
deps = [
"//api",
"@com_github_opentracing//:opentracing",
],
)

cc_test(
name = "propagation_test",
srcs = [
"test/propagation_test.cc",
"test/shim_mocks.h",
],
tags = [
"opentracing_shim",
"test",
],
deps = [
":opentracing_shim",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "shim_utils_test",
srcs = [
"test/shim_mocks.h",
"test/shim_utils_test.cc",
],
tags = [
"opentracing_shim",
"test",
],
deps = [
":opentracing_shim",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "span_shim_test",
srcs = [
"test/shim_mocks.h",
"test/span_shim_test.cc",
],
tags = [
"opentracing_shim",
"test",
],
deps = [
":opentracing_shim",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "span_context_shim_test",
srcs = [
"test/span_context_shim_test.cc",
],
tags = [
"opentracing_shim",
"test",
],
deps = [
":opentracing_shim",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "tracer_shim_test",
srcs = [
"test/shim_mocks.h",
"test/tracer_shim_test.cc",
],
tags = [
"opentracing_shim",
"test",
],
deps = [
":opentracing_shim",
"@com_google_googletest//:gtest_main",
],
)
61 changes: 61 additions & 0 deletions opentracing-shim/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

set(this_target opentelemetry_opentracing_shim)

add_library(${this_target} src/shim_utils.cc src/span_shim.cc
src/span_context_shim.cc src/tracer_shim.cc)

set_target_properties(${this_target} PROPERTIES EXPORT_NAME opentracing_shim)

target_include_directories(
${this_target} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:include>")

if(OPENTRACING_DIR)
include_directories(
"${CMAKE_BINARY_DIR}/${OPENTRACING_DIR}/include"
"${CMAKE_SOURCE_DIR}/${OPENTRACING_DIR}/include"
"${CMAKE_SOURCE_DIR}/${OPENTRACING_DIR}/3rd_party/include")
target_link_libraries(${this_target} opentelemetry_api opentracing)
else()
target_link_libraries(${this_target} opentelemetry_api
OpenTracing::opentracing)
endif()

install(
TARGETS ${this_target}
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(
DIRECTORY include/opentelemetry/opentracingshim
DESTINATION include/opentelemetry
FILES_MATCHING
PATTERN "*.h")

if(BUILD_TESTING)
foreach(testname propagation_test shim_utils_test span_shim_test
span_context_shim_test tracer_shim_test)

add_executable(${testname} "test/${testname}.cc")

if(OPENTRACING_DIR)
target_link_libraries(
${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
opentelemetry_api opentelemetry_opentracing_shim opentracing)
else()
target_link_libraries(
${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
opentelemetry_api opentelemetry_opentracing_shim
OpenTracing::opentracing)
endif()

gtest_add_tests(
TARGET ${testname}
TEST_PREFIX opentracing_shim.
TEST_LIST ${testname})
endforeach()
endif() # BUILD_TESTING
51 changes: 51 additions & 0 deletions opentracing-shim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# OpenTracing Shim

[![Apache License][license-image]][license-image]

The OpenTracing shim is a bridge layer from OpenTelemetry to the OpenTracing API.
It takes an OpenTelemetry Tracer and exposes it as an implementation compatible with
that of an OpenTracing Tracer.

## Usage

Use the TracerShim wherever you initialize your OpenTracing tracers.
There are 2 ways to expose an OpenTracing Tracer:

1. From the global OpenTelemetry configuration:

```cpp
auto tracer_shim = TracerShim::createTracerShim();
```

1. From a provided OpenTelemetry Tracer instance:

```cpp
auto tracer_shim = TracerShim::createTracerShim(tracer);
```

Optionally, one can also specify the propagators to be used for the OpenTracing `TextMap`
and `HttpHeaders` formats:

```cpp
OpenTracingPropagators propagators{
.text_map = nostd::shared_ptr<TextMapPropagator>(new CustomTextMap()),
.http_headers = nostd::shared_ptr<TextMapPropagator>(new trace::propagation::HttpTraceContext())
};

auto tracer_shim = TracerShim::createTracerShim(tracer, propagators);
```

If propagators are not specified, OpenTelemetry's global propagator will be used.

## License

Apache 2.0 - See [LICENSE][license-url] for more information.

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]

[discussions-url]: https://github.com/open-telemetry/opentelemetry-cpp/discussions
[license-url]: https://github.com/open-telemetry/opentelemetry-cpp/blob/main/LICENSE
[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
Loading