diff --git a/bazel/repository.bzl b/bazel/repository.bzl index 81c9b3f470..7fda79adf6 100644 --- a/bazel/repository.bzl +++ b/bazel/repository.bzl @@ -168,6 +168,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, diff --git a/opentracing-shim/BUILD b/opentracing-shim/BUILD new file mode 100644 index 0000000000..422edba39b --- /dev/null +++ b/opentracing-shim/BUILD @@ -0,0 +1,102 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "opentracing_shim", + srcs = [ + "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_utils_test.cc", + "test/shim_mocks.h", + ], + tags = [ + "opentracing_shim", + "test", + ], + deps = [ + ":opentracing_shim", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "span_shim_test", + srcs = [ + "test/span_shim_test.cc", + "test/shim_mocks.h", + ], + 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/tracer_shim_test.cc", + "test/shim_mocks.h", + ], + tags = [ + "opentracing_shim", + "test", + ], + deps = [ + ":opentracing_shim", + "@com_google_googletest//:gtest_main", + ], +) \ No newline at end of file diff --git a/opentracing-shim/include/opentelemetry/opentracingshim/shim_utils.h b/opentracing-shim/include/opentelemetry/opentracingshim/shim_utils.h index adca341b89..ed8c5d9890 100644 --- a/opentracing-shim/include/opentelemetry/opentracingshim/shim_utils.h +++ b/opentracing-shim/include/opentelemetry/opentracingshim/shim_utils.h @@ -36,7 +36,7 @@ static inline opentelemetry::common::AttributeValue attributeFromValue(const ope AttributeValue operator()(double v) { return v; } AttributeValue operator()(int64_t v) { return v; } AttributeValue operator()(uint64_t v) { return v; } - AttributeValue operator()(std::string v) { return v.c_str(); } + AttributeValue operator()(const std::string& v) { return v.c_str(); } AttributeValue operator()(opentracing::string_view v) { return nostd::string_view{v.data()}; } AttributeValue operator()(std::nullptr_t) { return nostd::string_view{}; } AttributeValue operator()(const char* v) { return v; } @@ -55,7 +55,7 @@ static inline std::string stringFromValue(const opentracing::Value& value) std::string operator()(double v) { return std::to_string(v); } std::string operator()(int64_t v) { return std::to_string(v); } std::string operator()(uint64_t v) { return std::to_string(v); } - std::string operator()(std::string v) { return v; } + std::string operator()(const std::string& v) { return v; } std::string operator()(opentracing::string_view v) { return std::string{v.data()}; } std::string operator()(std::nullptr_t) { return std::string{}; } std::string operator()(const char* v) { return std::string{v}; }