diff --git a/CHANGELOG.md b/CHANGELOG.md index ab5b802db6..b3e4115baf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ Increment the: ## [Unreleased] +* Added `ForceFlush` to `TracerProvider` in SDK. ([#588](https://github.com/open-telemetry/opentelemetry-cpp/pull/588)). + ## [0.0.1] 2020-12-16 ### Added diff --git a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h index a6de0a998d..acbe23dbee 100644 --- a/sdk/include/opentelemetry/sdk/trace/tracer_provider.h +++ b/sdk/include/opentelemetry/sdk/trace/tracer_provider.h @@ -66,6 +66,11 @@ class TracerProvider final : public opentelemetry::trace::TracerProvider */ bool Shutdown() noexcept; + /** + * Force flush the span processor associated with this tracer provider. + */ + bool ForceFlush(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept; + private: opentelemetry::sdk::AtomicSharedPtr processor_; std::shared_ptr tracer_; diff --git a/sdk/src/logs/logger.cc b/sdk/src/logs/logger.cc index 63f19b121b..0808f5a8e1 100644 --- a/sdk/src/logs/logger.cc +++ b/sdk/src/logs/logger.cc @@ -89,7 +89,7 @@ void Logger::Log(opentelemetry::logs::Severity severity, // Leave these fields in the recordable empty if neither the passed in values // nor the context values are valid (e.g. the application is not using traces) - // Traceid + // TraceId if (trace_id.IsValid()) { recordable->SetTraceId(trace_id); @@ -99,7 +99,7 @@ void Logger::Log(opentelemetry::logs::Severity severity, recordable->SetTraceId(span_context.trace_id()); } - // Spanid + // SpanId if (span_id.IsValid()) { recordable->SetSpanId(span_id); @@ -109,7 +109,7 @@ void Logger::Log(opentelemetry::logs::Severity severity, recordable->SetSpanId(span_id); } - // Traceflags + // TraceFlags if (trace_flags.IsSampled()) { recordable->SetTraceFlags(trace_flags); diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc index b37ae5de56..cc236292a2 100644 --- a/sdk/src/trace/tracer_provider.cc +++ b/sdk/src/trace/tracer_provider.cc @@ -48,6 +48,11 @@ bool TracerProvider::Shutdown() noexcept { return GetProcessor()->Shutdown(); } + +bool TracerProvider::ForceFlush(std::chrono::microseconds timeout) noexcept +{ + return GetProcessor()->ForceFlush(timeout); +} } // namespace trace } // namespace sdk OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/test/trace/tracer_provider_test.cc b/sdk/test/trace/tracer_provider_test.cc index 47c7ccc827..7cfe306278 100644 --- a/sdk/test/trace/tracer_provider_test.cc +++ b/sdk/test/trace/tracer_provider_test.cc @@ -70,3 +70,12 @@ TEST(TracerProvider, Shutdown) EXPECT_TRUE(tp1.Shutdown()); } + +TEST(TracerProvider, ForceFlush) +{ + std::shared_ptr processor1(new SimpleSpanProcessor(nullptr)); + + TracerProvider tp1(processor1); + + EXPECT_TRUE(tp1.ForceFlush()); +}