Skip to content

Commit

Permalink
Enable setting Span endtime for ETW exporter (gabime#1846)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Dec 8, 2022
1 parent 7727620 commit 722ad4e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
12 changes: 11 additions & 1 deletion exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,17 @@ class Span : public opentelemetry::trace::Span
*/
void End(const opentelemetry::trace::EndSpanOptions &options = {}) noexcept override
{
end_time_ = std::chrono::system_clock::now();
// TODO - explicitly setting end_time as 0 is not supported, and would be changed to
// current_time.
if (options.end_steady_time.time_since_epoch().count() == 0)
{
end_time_ = std::chrono::system_clock::now();
}
else
{
end_time_ =
opentelemetry::common::SystemTimestamp(options.end_steady_time.time_since_epoch());
}

if (!has_ended_.exchange(true))
{
Expand Down
14 changes: 14 additions & 0 deletions exporters/etw/test/etw_tracer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,20 @@ TEST(ETWTracer, CustomSampler)
}
}

TEST(ETWTracer, EndWithCustomTime)
{
// Obtain a global tracer using C++11 magic static.
auto& globalTracer = GetGlobalTracer();
auto s1 = globalTracer.StartSpan("Span1");
auto traceId1 = s1->GetContext().trace_id();
opentelemetry::trace::EndSpanOptions end;
end.end_steady_time = opentelemetry::common::SteadyTimestamp(std::chrono::nanoseconds(40));
s1->End(end);
auto end_time = static_cast<opentelemetry::exporter::etw::Span *>(s1.get())->GetEndTime();
EXPECT_EQ(end.end_steady_time.time_since_epoch(), end_time.time_since_epoch());

}

/* clang-format on */

#endif

0 comments on commit 722ad4e

Please sign in to comment.