diff --git a/CMakeLists.txt b/CMakeLists.txt index b0db1cbfe7..f637f489ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -495,6 +495,25 @@ 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() diff --git a/cmake/opentelemetry-cpp-config.cmake.in b/cmake/opentelemetry-cpp-config.cmake.in index b6dcd5e276..58f36bb5f0 100644 --- a/cmake/opentelemetry-cpp-config.cmake.in +++ b/cmake/opentelemetry-cpp-config.cmake.in @@ -46,6 +46,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 # # ============================================================================= @@ -101,7 +102,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}) diff --git a/opentracing-shim/CMakeLists.txt b/opentracing-shim/CMakeLists.txt index 7800cbdc91..c484e2bcc4 100644 --- a/opentracing-shim/CMakeLists.txt +++ b/opentracing-shim/CMakeLists.txt @@ -1,46 +1,73 @@ set(this_target opentelemetry_opentracing_shim) -#message("CMAKE_CURRENT_LIST_DIR " ${CMAKE_CURRENT_LIST_DIR}) -#message("CMAKE_CURRENT_SOURCE_DIR " ${CMAKE_CURRENT_SOURCE_DIR}) -#message("CMAKE_SOURCE_DIR " ${CMAKE_SOURCE_DIR}) -#message("PROJECT_SOURCE_DIR " ${PROJECT_SOURCE_DIR}) - -#add_library(${this_target} INTERFACE) -#target_include_directories( -# ${this_target} -# PUBLIC "$" -# "$" -# "$") -# -#set_target_properties(${this_target} PROPERTIES EXPORT_NAME "opentracing-shim") -#target_link_libraries(${this_target} INTERFACE ${this_target} opentracing-cpp) -# -#get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) -#foreach(dir ${dirs}) -# message(STATUS "dir='${dir}'") -#endforeach() -# -#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/opentracing-shim -# DESTINATION include/opentelemetry/ -# FILES_MATCHING -# PATTERN "*.h") - -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_SOURCE_DIR}/third_party/opentracing-cpp/include - ${CMAKE_SOURCE_DIR}/third_party/opentracing-cpp/build/include - ${CMAKE_SOURCE_DIR}/third_party/opentracing-cpp/3rd_party/include) - -add_subdirectory(src) +add_library(${this_target} + src/span_shim.cc + src/span_context_shim.cc + src/tracer_shim.cc) + +set_target_properties(${this_target} PROPERTIES EXPORT_NAME opentracing_shim) + +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") +endif() + +target_include_directories( + ${this_target} + PUBLIC "$" + "$") + +target_link_libraries( + ${this_target} + PUBLIC opentelemetry_api) + +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) - add_subdirectory(test) + 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 \ No newline at end of file diff --git a/opentracing-shim/include/propagation.h b/opentracing-shim/include/opentelemetry/opentracingshim/propagation.h similarity index 100% rename from opentracing-shim/include/propagation.h rename to opentracing-shim/include/opentelemetry/opentracingshim/propagation.h diff --git a/opentracing-shim/include/shim_utils.h b/opentracing-shim/include/opentelemetry/opentracingshim/shim_utils.h similarity index 99% rename from opentracing-shim/include/shim_utils.h rename to opentracing-shim/include/opentelemetry/opentracingshim/shim_utils.h index 55d38089c0..adca341b89 100644 --- a/opentracing-shim/include/shim_utils.h +++ b/opentracing-shim/include/opentelemetry/opentracingshim/shim_utils.h @@ -5,7 +5,7 @@ #pragma once -#include "span_context_shim.h" +#include "opentelemetry/opentracingshim/span_context_shim.h" #include "opentelemetry/baggage/baggage.h" #include "opentelemetry/baggage/baggage_context.h" diff --git a/opentracing-shim/include/span_context_shim.h b/opentracing-shim/include/opentelemetry/opentracingshim/span_context_shim.h similarity index 100% rename from opentracing-shim/include/span_context_shim.h rename to opentracing-shim/include/opentelemetry/opentracingshim/span_context_shim.h diff --git a/opentracing-shim/include/span_shim.h b/opentracing-shim/include/opentelemetry/opentracingshim/span_shim.h similarity index 94% rename from opentracing-shim/include/span_shim.h rename to opentracing-shim/include/opentelemetry/opentracingshim/span_shim.h index 238738228f..062421447e 100644 --- a/opentracing-shim/include/span_shim.h +++ b/opentracing-shim/include/opentelemetry/opentracingshim/span_shim.h @@ -5,8 +5,8 @@ #pragma once -#include "tracer_shim.h" -#include "span_context_shim.h" +#include "opentelemetry/opentracingshim/tracer_shim.h" +#include "opentelemetry/opentracingshim/span_context_shim.h" #include "opentelemetry/baggage/baggage.h" #include "opentelemetry/common/attribute_value.h" diff --git a/opentracing-shim/include/tracer_shim.h b/opentracing-shim/include/opentelemetry/opentracingshim/tracer_shim.h similarity index 100% rename from opentracing-shim/include/tracer_shim.h rename to opentracing-shim/include/opentelemetry/opentracingshim/tracer_shim.h diff --git a/opentracing-shim/src/CMakeLists.txt b/opentracing-shim/src/CMakeLists.txt deleted file mode 100644 index 037e171773..0000000000 --- a/opentracing-shim/src/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -set(this_target opentelemetry_opentracing_shim) -set(target_name opentracing_shim) - -file(GLOB_RECURSE SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cc) -file(GLOB_RECURSE HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/../include/*.h) - -add_library(${this_target} SHARED ${SOURCE_FILES} ${HEADER_FILES}) - -set_target_properties(${this_target} PROPERTIES EXPORT_NAME ${target_name}) - -target_include_directories( - ${this_target} - PUBLIC "$" - "$") - -target_link_libraries(${this_target} PUBLIC opentelemetry_api opentracing) - -install( - TARGETS ${this_target} - EXPORT "${PROJECT_NAME}-target" - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - -get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) -foreach(dir ${dirs}) - message(STATUS "dir='${dir}'") -endforeach() \ No newline at end of file diff --git a/opentracing-shim/src/span_context_shim.cc b/opentracing-shim/src/span_context_shim.cc index 207f7b1be6..d179a3a728 100644 --- a/opentracing-shim/src/span_context_shim.cc +++ b/opentracing-shim/src/span_context_shim.cc @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "span_context_shim.h" +#include "opentelemetry/opentracingshim/span_context_shim.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace opentracingshim diff --git a/opentracing-shim/src/span_shim.cc b/opentracing-shim/src/span_shim.cc index b40b897d0a..77f8c3a262 100644 --- a/opentracing-shim/src/span_shim.cc +++ b/opentracing-shim/src/span_shim.cc @@ -3,10 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "span_shim.h" -#include "span_context_shim.h" -#include "tracer_shim.h" -#include "shim_utils.h" +#include "opentelemetry/opentracingshim/span_shim.h" +#include "opentelemetry/opentracingshim/span_context_shim.h" +#include "opentelemetry/opentracingshim/tracer_shim.h" +#include "opentelemetry/opentracingshim/shim_utils.h" #include "opentelemetry/trace/semantic_conventions.h" #include "opentelemetry/trace/span_metadata.h" diff --git a/opentracing-shim/src/tracer_shim.cc b/opentracing-shim/src/tracer_shim.cc index f3c93570f3..a3bef986e3 100644 --- a/opentracing-shim/src/tracer_shim.cc +++ b/opentracing-shim/src/tracer_shim.cc @@ -3,10 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "tracer_shim.h" -#include "span_shim.h" -#include "shim_utils.h" -#include "propagation.h" +#include "opentelemetry/opentracingshim/tracer_shim.h" +#include "opentelemetry/opentracingshim/span_shim.h" +#include "opentelemetry/opentracingshim/shim_utils.h" +#include "opentelemetry/opentracingshim/propagation.h" #include "opentelemetry/context/propagation/global_propagator.h" #include "opentelemetry/trace/context.h" diff --git a/opentracing-shim/test/CMakeLists.txt b/opentracing-shim/test/CMakeLists.txt deleted file mode 100644 index 19b5cbf44a..0000000000 --- a/opentracing-shim/test/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -set(this_target shim_test) - -file(GLOB source_files ${CMAKE_CURRENT_LIST_DIR}/*.*) - -add_executable(${this_target} ${source_files}) - -target_link_libraries(${this_target} - ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} - opentelemetry_api - opentelemetry_opentracing_shim - opentracing) - -#gtest_add_tests( -# TARGET ${this_target} -# TEST_PREFIX ${this_target}. -# TEST_LIST ${this_target}) diff --git a/opentracing-shim/test/propagation_test.cc b/opentracing-shim/test/propagation_test.cc index 717cb99c9a..1850d9bd73 100644 --- a/opentracing-shim/test/propagation_test.cc +++ b/opentracing-shim/test/propagation_test.cc @@ -3,9 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "propagation.h" #include "shim_mocks.h" +#include "opentelemetry/opentracingshim/propagation.h" + #include namespace baggage = opentelemetry::baggage; diff --git a/opentracing-shim/test/shim_mocks.h b/opentracing-shim/test/shim_mocks.h index 7994dcdec9..8467d15dab 100644 --- a/opentracing-shim/test/shim_mocks.h +++ b/opentracing-shim/test/shim_mocks.h @@ -6,6 +6,7 @@ #pragma once #include "opentelemetry/baggage/baggage_context.h" +#include "opentelemetry/context/propagation/text_map_propagator.h" #include "opentelemetry/trace/span.h" #include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_metadata.h" diff --git a/opentracing-shim/test/shim_utils_test.cc b/opentracing-shim/test/shim_utils_test.cc index c5c37021d6..712d286de2 100644 --- a/opentracing-shim/test/shim_utils_test.cc +++ b/opentracing-shim/test/shim_utils_test.cc @@ -3,9 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "shim_utils.h" #include "shim_mocks.h" +#include "opentelemetry/opentracingshim/shim_utils.h" + #include "opentracing/tracer.h" #include diff --git a/opentracing-shim/test/span_context_shim_test.cc b/opentracing-shim/test/span_context_shim_test.cc index b8aacd66fe..195e66c807 100644 --- a/opentracing-shim/test/span_context_shim_test.cc +++ b/opentracing-shim/test/span_context_shim_test.cc @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "span_context_shim.h" +#include "opentelemetry/opentracingshim/span_context_shim.h" #include "opentelemetry/baggage/baggage.h" #include "opentelemetry/trace/span_context.h" diff --git a/opentracing-shim/test/span_shim_test.cc b/opentracing-shim/test/span_shim_test.cc index c002a24fba..48c498e261 100644 --- a/opentracing-shim/test/span_shim_test.cc +++ b/opentracing-shim/test/span_shim_test.cc @@ -3,10 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "span_shim.h" -#include "tracer_shim.h" #include "shim_mocks.h" +#include "opentelemetry/opentracingshim/span_shim.h" +#include "opentelemetry/opentracingshim/tracer_shim.h" + #include namespace trace_api = opentelemetry::trace; diff --git a/opentracing-shim/test/tracer_shim_test.cc b/opentracing-shim/test/tracer_shim_test.cc index a69bd0a7a3..742584d8b0 100644 --- a/opentracing-shim/test/tracer_shim_test.cc +++ b/opentracing-shim/test/tracer_shim_test.cc @@ -3,12 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "tracer_shim.h" -#include "span_shim.h" -#include "span_context_shim.h" -#include "shim_utils.h" #include "shim_mocks.h" +#include "opentelemetry/opentracingshim/tracer_shim.h" +#include "opentelemetry/opentracingshim/span_shim.h" +#include "opentelemetry/opentracingshim/span_context_shim.h" +#include "opentelemetry/opentracingshim/shim_utils.h" + #include "opentracing/noop.h" #include diff --git a/third_party/opentracing-cpp b/third_party/opentracing-cpp new file mode 160000 index 0000000000..06b57f48de --- /dev/null +++ b/third_party/opentracing-cpp @@ -0,0 +1 @@ +Subproject commit 06b57f48ded1fa3bdd3d4346f6ef29e40e08eaf5