Exception safe from destructor

Signed-off-by: Frank Chen <frank.chen021@outlook.com>
This commit is contained in:
Frank Chen 2022-08-26 11:18:16 +08:00
parent 92f7ca3616
commit cf1081eada
2 changed files with 23 additions and 8 deletions

View File

@ -102,7 +102,7 @@ SpanHolder::SpanHolder(std::string_view _operation_name)
}
}
void SpanHolder::finish()
void SpanHolder::finish() noexcept
{
if (!this->isTraceEnabled())
return;
@ -293,16 +293,31 @@ TracingContextHolder::TracingContextHolder(
TracingContextHolder::~TracingContextHolder()
{
if (this->root_span.isTraceEnabled())
{
try
{
auto shared_span_log = current_thread_trace_context.span_log.lock();
if (shared_span_log)
{
try
{
this->root_span.addAttribute("clickhouse.thread_id", getThreadId());
}
catch (...)
{
/// Ignore any exceptions
}
this->root_span.finish_time_us
= std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
shared_span_log->add(OpenTelemetrySpanLogElement(this->root_span));
}
}
catch (...)
{
tryLogCurrentException(__FUNCTION__);
}
this->root_span.trace_id = UUID();
}

View File

@ -152,7 +152,7 @@ struct SpanHolder : public Span
/// Finish a span explicitly if needed.
/// It's safe to call it multiple times
void finish();
void finish() noexcept;
};
}