Skip to content

Commit

Permalink
Merge branch 'main' into fix_api_version_2012
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Mar 3, 2023
2 parents 33dfbed + 4dff60a commit 0b626b7
Show file tree
Hide file tree
Showing 28 changed files with 2,392 additions and 6 deletions.
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)
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",
],
)

# 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/...
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

0 comments on commit 0b626b7

Please sign in to comment.