Skip to content

Commit

Permalink
Merge 85c86fa into 3848295
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomsonTan authored Feb 26, 2021
2 parents 3848295 + 85c86fa commit aa73133
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
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());
}

0 comments on commit aa73133

Please sign in to comment.