#ifdef HAVE_JAEGER
+#include "opentelemetry/trace/propagation/jaeger.h"
+#include "opentelemetry/trace/propagation/detail/hex.h"
+
namespace tracing {
const opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> Tracer::noop_tracer = opentelemetry::trace::Provider::GetTracerProvider()->GetTracer("no-op", OPENTELEMETRY_SDK_VERSION);
+using bufferlist = ceph::buffer::list;
+
Tracer::Tracer(opentelemetry::nostd::string_view service_name) {
init(service_name);
}
return noop_tracer->StartSpan(trace_name);
}
-jspan Tracer::add_span(opentelemetry::nostd::string_view span_name, jspan& parent_span) {
+jspan Tracer::add_span(opentelemetry::nostd::string_view span_name, const jspan& parent_span) {
if (is_enabled() && parent_span) {
const auto parent_ctx = parent_span->GetContext();
- if (parent_ctx.IsValid()) {
- opentelemetry::trace::StartSpanOptions span_opts;
- span_opts.parent = parent_ctx;
- return tracer->StartSpan(span_name, span_opts);
- }
+ return add_span(span_name, parent_ctx);
+ }
+ return noop_tracer->StartSpan(span_name);
+}
+
+jspan Tracer::add_span(opentelemetry::nostd::string_view span_name, const jspan_context& parent_ctx) {
+ if (is_enabled() && parent_ctx.IsValid()) {
+ opentelemetry::trace::StartSpanOptions span_opts;
+ span_opts.parent = parent_ctx;
+ return tracer->StartSpan(span_name, span_opts);
}
return noop_tracer->StartSpan(span_name);
}
return g_ceph_context->_conf->jaeger_tracing_enable;
}
+void encode(const jspan_context& span_ctx, bufferlist& bl, uint64_t f) {
+ ENCODE_START(1, 1, bl);
+ using namespace opentelemetry;
+ using namespace trace;
+ auto is_valid = span_ctx.IsValid();
+ encode(is_valid, bl);
+ if (is_valid) {
+ encode_nohead(std::string_view(reinterpret_cast<const char*>(span_ctx.trace_id().Id().data()), TraceId::kSize), bl);
+ encode_nohead(std::string_view(reinterpret_cast<const char*>(span_ctx.span_id().Id().data()), SpanId::kSize), bl);
+ encode(span_ctx.trace_flags().flags(), bl);
+ }
+ ENCODE_FINISH(bl);
+}
+
+void decode(jspan_context& span_ctx, bufferlist::const_iterator& bl) {
+ using namespace opentelemetry;
+ using namespace trace;
+ DECODE_START(1, bl);
+ bool is_valid;
+ decode(is_valid, bl);
+ if (is_valid) {
+ std::array<uint8_t, TraceId::kSize> trace_id;
+ std::array<uint8_t, SpanId::kSize> span_id;
+ uint8_t flags;
+ decode(trace_id, bl);
+ decode(span_id, bl);
+ decode(flags, bl);
+ span_ctx = SpanContext(
+ TraceId(nostd::span<uint8_t, TraceId::kSize>(trace_id)),
+ SpanId(nostd::span<uint8_t, SpanId::kSize>(span_id)),
+ TraceFlags(flags),
+ true);
+ }
+ DECODE_FINISH(bl);
+}
} // namespace tracing
#endif // HAVE_JAEGER
#pragma once
#include "acconfig.h"
+#include "include/buffer.h"
#ifdef HAVE_JAEGER
#include "opentelemetry/sdk/trace/tracer_provider.h"
using jspan = opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span>;
+using jspan_context = opentelemetry::trace::SpanContext;
namespace tracing {
// this span represents a trace, since it has no parent.
jspan start_trace(opentelemetry::nostd::string_view trace_name);
// creates and returns a new span with `span_name` which parent span is `parent_span'
- jspan add_span(opentelemetry::nostd::string_view span_name, jspan& parent_span);
+ jspan add_span(opentelemetry::nostd::string_view span_name, const jspan& parent_span);
+ // creates and return a new span with `span_name`
+ // the span is added to the trace which it's context is `parent_ctx`.
+ // parent_ctx contains the required information of the trace.
+ jspan add_span(opentelemetry::nostd::string_view span_name, const jspan_context& parent_ctx);
};
+void encode(const jspan_context& span, ceph::buffer::list& bl, uint64_t f = 0);
+void decode(jspan_context& span_ctx, ceph::buffer::list::const_iterator& bl);
} // namespace tracing
#include <string_view>
+
+
class Value {
public:
template <typename T> Value(T val) {}
};
+struct jspan_context {
+ jspan_context() {}
+ jspan_context(bool sampled_flag, bool is_remote) {}
+};
+
struct span_stub {
+ jspan_context _ctx;
template <typename T>
void SetAttribute(std::string_view key, const T& value) const noexcept {}
void AddEvent(std::string_view, std::initializer_list<std::pair<std::string_view, Value>> fields) {}
+ const jspan_context& GetContext() { return _ctx; }
+ void UpdateName(std::string_view) {}
};
class jspan {
bool is_enabled() const { return false; }
jspan start_trace(std::string_view) { return {}; }
jspan add_span(std::string_view, const jspan&) { return {}; }
+ jspan add_span(std::string_view span_name, const jspan_context& parent_ctx) { return {}; }
void init(std::string_view service_name) {}
void shutdown() {}
};
+ inline void encode(const jspan_context& span, bufferlist& bl, uint64_t f=0) {}
+ inline void decode(jspan_context& span_ctx, ceph::buffer::list::const_iterator& bl) {}
}
#endif // !HAVE_JAEGER