Skip to content

Commit

Permalink
Adds compatability for Opentracing 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Kay committed Jun 26, 2018
1 parent a74e991 commit 48f6462
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ci/build_plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
50 changes: 35 additions & 15 deletions zipkin_opentracing/src/dynamic_load.cc
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
#include "tracer_factory.h"
#include <cstring>
#include <cstdio>
#include <exception>
#include <opentracing/dynamic_load.h>

int OpenTracingMakeTracerFactory(const char *opentracing_version,
const void **error_category,
void **tracer_factory) {
if (std::strcmp(opentracing_version, OPENTRACING_VERSION) != 0) {
*error_category =
static_cast<const void *>(&opentracing::dynamic_load_error_category());
return opentracing::incompatible_library_versions_error.value();
}

*tracer_factory = new (std::nothrow) zipkin::OtTracerFactory{};
if (tracer_factory == nullptr) {
*error_category = static_cast<const void *>(&std::generic_category());
return static_cast<int>(std::errc::not_enough_memory);
}
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();
}

return 0;
}
if (std::strcmp(opentracing_abi_version, OPENTRACING_ABI_VERSION) != 0) {
*error_category =
static_cast<const void*>(&opentracing::dynamic_load_error_category());
auto& message = *static_cast<std::string*>(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 zipkin::OtTracerFactory{};

return 0;
} catch (const std::bad_alloc&) {
*error_category = static_cast<const void*>(&std::generic_category());
return static_cast<int>(std::errc::not_enough_memory);
}

OPENTRACING_DECLARE_IMPL_FACTORY(OpenTracingMakeTracerFactoryFunction)

0 comments on commit 48f6462

Please sign in to comment.