Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ForceFlush to TracerProvider in SDK #588

Merged
merged 2 commits into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions sdk/include/opentelemetry/sdk/trace/tracer_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpanProcessor> processor_;
std::shared_ptr<opentelemetry::trace::Tracer> tracer_;
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/logs/logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions sdk/src/trace/tracer_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions sdk/test/trace/tracer_provider_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,12 @@ TEST(TracerProvider, Shutdown)

EXPECT_TRUE(tp1.Shutdown());
}

TEST(TracerProvider, ForceFlush)
{
std::shared_ptr<SpanProcessor> processor1(new SimpleSpanProcessor(nullptr));

TracerProvider tp1(processor1);

EXPECT_TRUE(tp1.ForceFlush());
}