summaryrefslogtreecommitdiffstats
path: root/mocktracer/src/mock_span_context.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:44:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:44:33 +0000
commitb196c6498d22e47bb9d0da0153068ec54eac7956 (patch)
tree1a994a492581e93224a7ee6455f5d4e9d2ec8e59 /mocktracer/src/mock_span_context.h
parentInitial commit. (diff)
downloadopentracing-cpp-upstream/1.6.0.tar.xz
opentracing-cpp-upstream/1.6.0.zip
Adding upstream version 1.6.0.upstream/1.6.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mocktracer/src/mock_span_context.h')
-rw-r--r--mocktracer/src/mock_span_context.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/mocktracer/src/mock_span_context.h b/mocktracer/src/mock_span_context.h
new file mode 100644
index 0000000..ed156da
--- /dev/null
+++ b/mocktracer/src/mock_span_context.h
@@ -0,0 +1,79 @@
+#ifndef OPENTRACING_MOCKTRACER_SPAN_CONTEXT_H
+#define OPENTRACING_MOCKTRACER_SPAN_CONTEXT_H
+
+#include <opentracing/mocktracer/tracer.h>
+#include <exception>
+#include <mutex>
+#include <string>
+#include "propagation.h"
+
+namespace opentracing {
+BEGIN_OPENTRACING_ABI_NAMESPACE
+namespace mocktracer {
+
+class MockSpan;
+
+class MockSpanContext : public SpanContext {
+ public:
+ MockSpanContext() = default;
+
+ MockSpanContext(SpanContextData&& data) noexcept : data_(std::move(data)) {}
+
+ MockSpanContext(const MockSpanContext&) = delete;
+ MockSpanContext(MockSpanContext&&) = delete;
+
+ ~MockSpanContext() override = default;
+
+ MockSpanContext& operator=(const MockSpanContext&) = delete;
+ MockSpanContext& operator=(MockSpanContext&& other) noexcept;
+
+ void ForeachBaggageItem(
+ std::function<bool(const std::string& key, const std::string& value)> f)
+ const override;
+
+ std::string ToTraceID() const noexcept override try {
+ return std::to_string(data_.trace_id);
+ } catch (const std::exception& /*e*/) {
+ return {};
+ }
+
+ std::string ToSpanID() const noexcept override try {
+ return std::to_string(data_.span_id);
+ } catch (const std::exception& /*e*/) {
+ return {};
+ }
+
+ uint64_t trace_id() const noexcept { return data_.trace_id; }
+
+ uint64_t span_id() const noexcept { return data_.span_id; }
+
+ void CopyData(SpanContextData& data) const;
+
+ template <class Carrier>
+ expected<void> Inject(const PropagationOptions& propagation_options,
+ Carrier& writer) const {
+ std::lock_guard<std::mutex> lock_guard{baggage_mutex_};
+ return InjectSpanContext(propagation_options, writer, data_);
+ }
+
+ template <class Carrier>
+ expected<bool> Extract(const PropagationOptions& propagation_options,
+ Carrier& reader) {
+ std::lock_guard<std::mutex> lock_guard{baggage_mutex_};
+ return ExtractSpanContext(propagation_options, reader, data_);
+ }
+
+ std::unique_ptr<SpanContext> Clone() const noexcept override;
+
+ private:
+ friend MockSpan;
+
+ mutable std::mutex baggage_mutex_;
+ SpanContextData data_;
+};
+
+} // namespace mocktracer
+END_OPENTRACING_ABI_NAMESPACE
+} // namespace opentracing
+
+#endif // OPENTRACING_MOCKTRACER_SPAN_CONTEXT_H