Skip to content

Commit

Permalink
Update usage of ABI 2 to match breaking changes in opentelemetry-cpp …
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-mccann committed Jul 15, 2024
1 parent d953d32 commit e495b43
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions exporters/fluentd/test/trace/fluentd_recordable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,12 @@ TEST(FluentdExporter, SendTraceEvents) {
auto processor = std::unique_ptr<SpanProcessor>(
new sdktrace::SimpleSpanProcessor(std::move(exporter)));

auto provider = nostd::shared_ptr<trace::TracerProvider>(
auto provider = std::shared_ptr<sdktrace::TracerProvider>(
new TracerProvider(std::move(processor)));

std::shared_ptr<trace::TracerProvider> api_provider = provider;
// Set the global trace provider
opentelemetry::trace::Provider::SetTracerProvider(provider);
opentelemetry::trace::Provider::SetTracerProvider(api_provider);

std::string providerName = "MyInstrumentationName";
auto tracer = provider->GetTracer(providerName);
Expand Down Expand Up @@ -426,8 +427,16 @@ TEST(FluentdExporter, SendTraceEvents) {
}
span1->End(); // end MySpanL1

#if OPENTELEMETRY_ABI_VERSION_NO == 1
tracer->ForceFlushWithMicroseconds(1000);
tracer->CloseWithMicroseconds(0);
#else
/* In ABI 2 >= otel-cpp v1.16.0, only the sdk Tracer objects
* have the ForceFlush...() and Close...() methods. The Close()
* method simply calls ForceFlush(). Use the SDK provider ForceFlush() instead.
*/
provider->ForceFlush();
#endif /* OPENTELEMETRY_ABI_VERSION_NO == 1 */

testServer.WaitForEvents(6, 200); // 6 batches must arrive in 200ms
testServer.Stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ class MockTracer : public opentelemetry::trace::Tracer
MOCK_METHOD(nostd::shared_ptr<trace::Span>, StartSpanInternal,
(nostd::string_view name, trace::SpanKind kind));

#if OPENTELEMETRY_ABI_VERSION_NO == 1
MOCK_METHOD(void, ForceFlushWithMicroseconds, (uint64_t timeout), (noexcept));
MOCK_METHOD(void, CloseWithMicroseconds, (uint64_t timeout), (noexcept));
#endif /* OPENTELEMETRY_ABI_VERSION_NO == 1 */
};

class MockSpan : public opentelemetry::trace::Span
Expand Down

0 comments on commit e495b43

Please sign in to comment.