-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds compatability for Opentracing 1.5.0
- Loading branch information
Gabriel Kay
committed
Jun 26, 2018
1 parent
a74e991
commit 48f6462
Showing
2 changed files
with
36 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |