]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | #include <opentracing/mocktracer/json.h> |
2 | #include <opentracing/mocktracer/json_recorder.h> | |
3 | ||
4 | namespace opentracing { | |
5 | BEGIN_OPENTRACING_ABI_NAMESPACE | |
6 | namespace mocktracer { | |
7 | JsonRecorder::JsonRecorder(std::unique_ptr<std::ostream>&& out) | |
8 | : out_{std::move(out)} {} | |
9 | ||
10 | void JsonRecorder::RecordSpan(SpanData&& span_data) noexcept try { | |
11 | std::lock_guard<std::mutex> lock_guard{mutex_}; | |
12 | spans_.emplace_back(std::move(span_data)); | |
13 | } catch (const std::exception&) { | |
14 | // Drop span. | |
15 | } | |
16 | ||
17 | void JsonRecorder::Close() noexcept try { | |
18 | if (out_ == nullptr) { | |
19 | return; | |
20 | } | |
21 | std::lock_guard<std::mutex> lock_guard{mutex_}; | |
22 | ToJson(*out_, spans_); | |
23 | out_->flush(); | |
24 | spans_.clear(); | |
25 | } catch (const std::exception&) { | |
26 | // Ignore errors. | |
27 | } | |
28 | } // namespace mocktracer | |
29 | END_OPENTRACING_ABI_NAMESPACE | |
30 | } // namespace opentracing |