Skip to content

Commit d199284

Browse files
committed
Call TracerContext::ForceFlush when force flush or shut a tracer, fix the unit test in open-telemetry#1793 .
Signed-off-by: owent <admin@owent.net>
1 parent d1c7f5d commit d199284

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

sdk/include/opentelemetry/sdk/trace/tracer_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class TracerContext
8787
/**
8888
* Shutdown the span processor associated with this tracer provider.
8989
*/
90-
bool Shutdown() noexcept;
90+
bool Shutdown(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept;
9191

9292
private:
9393
// order of declaration is important here - resource object should be destroyed after processor.

sdk/src/trace/tracer.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,22 @@ nostd::shared_ptr<trace_api::Span> Tracer::StartSpan(
104104

105105
void Tracer::ForceFlushWithMicroseconds(uint64_t timeout) noexcept
106106
{
107-
(void)timeout;
107+
if (context_)
108+
{
109+
context_->ForceFlush(
110+
std::chrono::microseconds{static_cast<std::chrono::microseconds::rep>(timeout)});
111+
}
108112
}
109113

110114
void Tracer::CloseWithMicroseconds(uint64_t timeout) noexcept
111115
{
112-
(void)timeout;
116+
// Trace context is shared by many tracers.So we just call ForceFlush to flush all pending spans
117+
// and do not shutdown it.
118+
if (context_)
119+
{
120+
context_->ForceFlush(
121+
std::chrono::microseconds{static_cast<std::chrono::microseconds::rep>(timeout)});
122+
}
113123
}
114124
} // namespace trace
115125
} // namespace sdk

sdk/src/trace/tracer_context.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ bool TracerContext::ForceFlush(std::chrono::microseconds timeout) noexcept
5353
return processor_->ForceFlush(timeout);
5454
}
5555

56-
bool TracerContext::Shutdown() noexcept
56+
bool TracerContext::Shutdown(std::chrono::microseconds timeout) noexcept
5757
{
58-
return processor_->Shutdown();
58+
return processor_->Shutdown(timeout);
5959
}
6060

6161
} // namespace trace

0 commit comments

Comments
 (0)