diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:44:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:44:33 +0000 |
commit | b196c6498d22e47bb9d0da0153068ec54eac7956 (patch) | |
tree | 1a994a492581e93224a7ee6455f5d4e9d2ec8e59 /mocktracer/src/json_recorder.cpp | |
parent | Initial commit. (diff) | |
download | opentracing-cpp-b196c6498d22e47bb9d0da0153068ec54eac7956.tar.xz opentracing-cpp-b196c6498d22e47bb9d0da0153068ec54eac7956.zip |
Adding upstream version 1.6.0.upstream/1.6.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | mocktracer/src/json_recorder.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/mocktracer/src/json_recorder.cpp b/mocktracer/src/json_recorder.cpp new file mode 100644 index 0000000..5d30d9a --- /dev/null +++ b/mocktracer/src/json_recorder.cpp @@ -0,0 +1,30 @@ +#include <opentracing/mocktracer/json.h> +#include <opentracing/mocktracer/json_recorder.h> + +namespace opentracing { +BEGIN_OPENTRACING_ABI_NAMESPACE +namespace mocktracer { +JsonRecorder::JsonRecorder(std::unique_ptr<std::ostream>&& out) + : out_{std::move(out)} {} + +void JsonRecorder::RecordSpan(SpanData&& span_data) noexcept try { + std::lock_guard<std::mutex> lock_guard{mutex_}; + spans_.emplace_back(std::move(span_data)); +} catch (const std::exception&) { + // Drop span. +} + +void JsonRecorder::Close() noexcept try { + if (out_ == nullptr) { + return; + } + std::lock_guard<std::mutex> lock_guard{mutex_}; + ToJson(*out_, spans_); + out_->flush(); + spans_.clear(); +} catch (const std::exception&) { + // Ignore errors. +} +} // namespace mocktracer +END_OPENTRACING_ABI_NAMESPACE +} // namespace opentracing |