From ec4c666d3f33239f1e0789738ea6ff0480f46e9d Mon Sep 17 00:00:00 2001 From: Gabriel Kay Date: Tue, 26 Jun 2018 16:57:21 -0400 Subject: [PATCH] Adds compatability for Opentracing 1.5.0 --- WORKSPACE | 2 +- ci/WORKSPACE | 2 +- ci/build_plugin.sh | 2 +- zipkin_opentracing/src/dynamic_load.cc | 40 +++++++++++++++++++------- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index d3ac814..4d9872a 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -3,7 +3,7 @@ workspace(name = "com_github_rnburn_zipkin_opentracing") git_repository( name = "io_opentracing_cpp", remote = "https://github.com/opentracing/opentracing-cpp", - commit = "44e74489586550c388cca92f3ece187b3f1bf5d5", + commit = "ac50154a7713877f877981c33c3375003b6ebfe1", ) # TODO: Fill in libcurl dependency diff --git a/ci/WORKSPACE b/ci/WORKSPACE index 62272f6..2e2e11c 100644 --- a/ci/WORKSPACE +++ b/ci/WORKSPACE @@ -3,7 +3,7 @@ workspace(name = "com_github_rnburn_zipkin_opentracing") git_repository( name = "io_opentracing_cpp", remote = "https://github.com/opentracing/opentracing-cpp", - commit = "44e74489586550c388cca92f3ece187b3f1bf5d5", + commit = "ac50154a7713877f877981c33c3375003b6ebfe1", ) new_local_repository( diff --git a/ci/build_plugin.sh b/ci/build_plugin.sh index aa25953..7efd378 100755 --- a/ci/build_plugin.sh +++ b/ci/build_plugin.sh @@ -9,7 +9,7 @@ apt-get install --no-install-recommends --no-install-suggests -y \ git \ ca-certificates -export OPENTRACING_VERSION=1.4.0 +export OPENTRACING_VERSION=1.5.0 # Compile for a portable cpu architecture export CFLAGS="-march=x86-64" diff --git a/zipkin_opentracing/src/dynamic_load.cc b/zipkin_opentracing/src/dynamic_load.cc index 426be3c..b077ec2 100644 --- a/zipkin_opentracing/src/dynamic_load.cc +++ b/zipkin_opentracing/src/dynamic_load.cc @@ -1,21 +1,41 @@ #include "tracer_factory.h" #include +#include +#include #include -int OpenTracingMakeTracerFactory(const char *opentracing_version, - const void **error_category, - void **tracer_factory) { - if (std::strcmp(opentracing_version, OPENTRACING_VERSION) != 0) { + +static int OpenTracingMakeTracerFactoryFunction( + const char* opentracing_version, const char* opentracing_abi_version, + const void** error_category, void* error_message, + void** tracer_factory) try { + if (opentracing_version == nullptr || opentracing_abi_version == nullptr || + error_message == nullptr || error_category == nullptr || + tracer_factory == nullptr) { + fprintf(stderr, + "`opentracing_version`, `opentracing_abi_version`, " + "`error_message`, `error_category`, and `tracer_factory` must be " + "non-null.\n"); + std::terminate(); + } + + if (std::strcmp(opentracing_abi_version, OPENTRACING_ABI_VERSION) != 0) { *error_category = - static_cast(&opentracing::dynamic_load_error_category()); + static_cast(&opentracing::dynamic_load_error_category()); + auto& message = *static_cast(error_message); + message = + "incompatible OpenTracing ABI versions; " + "expected " OPENTRACING_ABI_VERSION " but got "; + message.append(opentracing_abi_version); return opentracing::incompatible_library_versions_error.value(); } - *tracer_factory = new (std::nothrow) zipkin::OtTracerFactory{}; - if (tracer_factory == nullptr) { - *error_category = static_cast(&std::generic_category()); - return static_cast(std::errc::not_enough_memory); - } + *tracer_factory = new zipkin::OtTracerFactory{}; return 0; +} catch (const std::bad_alloc&) { + *error_category = static_cast(&std::generic_category()); + return static_cast(std::errc::not_enough_memory); } + +OPENTRACING_DECLARE_IMPL_FACTORY(OpenTracingMakeTracerFactoryFunction)