Skip to content

Commit

Permalink
Call TracerContext::ForceFlush when force flush or shut a tracer, f…
Browse files Browse the repository at this point in the history
…ix the unit test in open-telemetry#1793 .

Signed-off-by: owent <admin@owent.net>
  • Loading branch information
owent committed Mar 20, 2023
1 parent 597205c commit c9f5d4c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sdk/include/opentelemetry/sdk/trace/tracer_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class TracerContext
/**
* Shutdown the span processor associated with this tracer provider.
*/
bool Shutdown() noexcept;
bool Shutdown(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept;

private:
// order of declaration is important here - resource object should be destroyed after processor.
Expand Down
14 changes: 12 additions & 2 deletions sdk/src/trace/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,22 @@ nostd::shared_ptr<trace_api::Span> Tracer::StartSpan(

void Tracer::ForceFlushWithMicroseconds(uint64_t timeout) noexcept
{
(void)timeout;
if (context_)
{
context_->ForceFlush(
std::chrono::microseconds{static_cast<std::chrono::microseconds::rep>(timeout)});
}
}

void Tracer::CloseWithMicroseconds(uint64_t timeout) noexcept
{
(void)timeout;
// Trace context is shared by many tracers.So we just call ForceFlush to flush all pending spans
// and do not shutdown it.
if (context_)
{
context_->ForceFlush(
std::chrono::microseconds{static_cast<std::chrono::microseconds::rep>(timeout)});
}
}
} // namespace trace
} // namespace sdk
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/trace/tracer_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ bool TracerContext::ForceFlush(std::chrono::microseconds timeout) noexcept
return processor_->ForceFlush(timeout);
}

bool TracerContext::Shutdown() noexcept
bool TracerContext::Shutdown(std::chrono::microseconds timeout) noexcept
{
return processor_->Shutdown();
return processor_->Shutdown(timeout);
}

} // namespace trace
Expand Down

0 comments on commit c9f5d4c

Please sign in to comment.