From 8532f596e67f82016c1247fcd67385cd7890ee02 Mon Sep 17 00:00:00 2001 From: Yuval Lifshitz Date: Tue, 10 Oct 2023 17:30:54 +0000 Subject: [PATCH] tracing/osd/rgw: using jspan as alias to opentelemetry::Span and jspan_ptr as jspan shared pointer Signed-off-by: Yuval Lifshitz --- src/common/tracer.cc | 10 ++++----- src/common/tracer.h | 43 ++++++++++++++++++--------------------- src/osd/OpRequest.h | 2 +- src/rgw/rgw_common.h | 4 ++-- src/rgw/rgw_op.h | 8 ++++---- src/rgw/rgw_req_context.h | 6 ++---- src/rgw/rgw_sal.h | 2 +- 7 files changed, 35 insertions(+), 40 deletions(-) diff --git a/src/common/tracer.cc b/src/common/tracer.cc index 1146da319500d..e98053735b48d 100644 --- a/src/common/tracer.cc +++ b/src/common/tracer.cc @@ -17,7 +17,7 @@ namespace tracing { const opentelemetry::nostd::shared_ptr Tracer::noop_tracer = opentelemetry::trace::Provider::GetTracerProvider()->GetTracer("no-op", OPENTELEMETRY_SDK_VERSION); -const jspan Tracer::noop_span = noop_tracer->StartSpan("noop"); +const jspan_ptr Tracer::noop_span = noop_tracer->StartSpan("noop"); using bufferlist = ceph::buffer::list; @@ -38,7 +38,7 @@ void Tracer::init(CephContext* _cct, opentelemetry::nostd::string_view service_n } } -jspan Tracer::start_trace(opentelemetry::nostd::string_view trace_name) { +jspan_ptr Tracer::start_trace(opentelemetry::nostd::string_view trace_name) { ceph_assert(cct); if (is_enabled()) { ceph_assert(tracer); @@ -48,7 +48,7 @@ jspan Tracer::start_trace(opentelemetry::nostd::string_view trace_name) { return noop_span; } -jspan Tracer::start_trace(opentelemetry::nostd::string_view trace_name, bool trace_is_enabled) { +jspan_ptr Tracer::start_trace(opentelemetry::nostd::string_view trace_name, bool trace_is_enabled) { ceph_assert(cct); ldout(cct, 20) << "start trace enabled " << trace_is_enabled << " " << dendl; if (trace_is_enabled) { @@ -59,7 +59,7 @@ jspan Tracer::start_trace(opentelemetry::nostd::string_view trace_name, bool tra return noop_tracer->StartSpan(trace_name); } -jspan Tracer::add_span(opentelemetry::nostd::string_view span_name, const jspan& parent_span) { +jspan_ptr Tracer::add_span(opentelemetry::nostd::string_view span_name, const jspan_ptr& parent_span) { if (parent_span && parent_span->IsRecording()) { ceph_assert(tracer); opentelemetry::trace::StartSpanOptions span_opts; @@ -70,7 +70,7 @@ jspan Tracer::add_span(opentelemetry::nostd::string_view span_name, const jspan& return noop_span; } -jspan Tracer::add_span(opentelemetry::nostd::string_view span_name, const jspan_context& parent_ctx) { +jspan_ptr Tracer::add_span(opentelemetry::nostd::string_view span_name, const jspan_context& parent_ctx) { if (parent_ctx.IsValid()) { ceph_assert(tracer); opentelemetry::trace::StartSpanOptions span_opts; diff --git a/src/common/tracer.h b/src/common/tracer.h index 94efedbed6e10..291ff9de25a7b 100644 --- a/src/common/tracer.h +++ b/src/common/tracer.h @@ -9,7 +9,8 @@ #ifdef HAVE_JAEGER #include "opentelemetry/trace/provider.h" -using jspan = opentelemetry::nostd::shared_ptr; +using jspan = opentelemetry::trace::Span; +using jspan_ptr = opentelemetry::nostd::shared_ptr; using jspan_context = opentelemetry::trace::SpanContext; using jspan_attribute = opentelemetry::common::AttributeValue; @@ -18,7 +19,7 @@ namespace tracing { class Tracer { private: const static opentelemetry::nostd::shared_ptr noop_tracer; - const static jspan noop_span; + const static jspan_ptr noop_span; CephContext* cct = nullptr;; opentelemetry::nostd::shared_ptr tracer; @@ -30,18 +31,18 @@ class Tracer { bool is_enabled() const; // creates and returns a new span with `trace_name` // this span represents a trace, since it has no parent. - jspan start_trace(opentelemetry::nostd::string_view trace_name); + jspan_ptr start_trace(opentelemetry::nostd::string_view trace_name); // creates and returns a new span with `trace_name` // if false is given to `trace_is_enabled` param, noop span will be returned - jspan start_trace(opentelemetry::nostd::string_view trace_name, bool trace_is_enabled); + jspan_ptr start_trace(opentelemetry::nostd::string_view trace_name, bool trace_is_enabled); // creates and returns a new span with `span_name` which parent span is `parent_span' - jspan add_span(opentelemetry::nostd::string_view span_name, const jspan& parent_span); + jspan_ptr add_span(opentelemetry::nostd::string_view span_name, const jspan_ptr& 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); + jspan_ptr add_span(opentelemetry::nostd::string_view span_name, const jspan_context& parent_ctx); }; @@ -67,9 +68,9 @@ struct jspan_context { jspan_context(bool sampled_flag, bool is_remote) {} }; -namespace opentelemetry::trace { -struct Span { +class jspan { jspan_context _ctx; +public: template void SetAttribute(std::string_view key, const T& value) const noexcept {} void AddEvent(std::string_view) {} @@ -79,21 +80,17 @@ struct Span { void UpdateName(std::string_view) {} bool IsRecording() { return false; } }; -} -class jspan { - opentelemetry::trace::Span span; +class jspan_ptr { + jspan span; public: - opentelemetry::trace::Span& operator*() { return span; } - const opentelemetry::trace::Span& operator*() const { return span; } - - opentelemetry::trace::Span* operator->() { return &span; } - const opentelemetry::trace::Span* operator->() const { return &span; } - + jspan& operator*() { return span; } + const jspan& operator*() const { return span; } + jspan* operator->() { return &span; } + const jspan* operator->() const { return &span; } operator bool() const { return false; } - - opentelemetry::trace::Span* get() { return &span; } - const opentelemetry::trace::Span* get() const { return &span; } + jspan* get() { return &span; } + const jspan* get() const { return &span; } }; namespace tracing { @@ -101,9 +98,9 @@ namespace tracing { struct Tracer { void init(CephContext* _cct, std::string_view service_name) {} bool is_enabled() const { return false; } - jspan start_trace(std::string_view, bool enabled = true) { return {}; } - jspan add_span(std::string_view, const jspan&) { return {}; } - jspan add_span(std::string_view span_name, const jspan_context& parent_ctx) { return {}; } + jspan_ptr start_trace(std::string_view, bool enabled = true) { return {}; } + jspan_ptr add_span(std::string_view, const jspan_ptr&) { return {}; } + jspan_ptr add_span(std::string_view span_name, const jspan_context& parent_ctx) { return {}; } }; inline void encode(const jspan_context& span, bufferlist& bl, uint64_t f=0) {} diff --git a/src/osd/OpRequest.h b/src/osd/OpRequest.h index 8df4f25d53e59..23f3b1d932e9f 100644 --- a/src/osd/OpRequest.h +++ b/src/osd/OpRequest.h @@ -94,7 +94,7 @@ public: epoch_t min_epoch = 0; ///< min epoch needed to handle this msg bool hitset_inserted; - jspan osd_parent_span; + jspan_ptr osd_parent_span; template const T* get_req() const { return static_cast(request); } diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index a71f1368070ec..1094d0cd443ea 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -25,6 +25,7 @@ #include "common/ceph_crypto.h" #include "common/random_string.h" +#include "common/tracer.h" #include "rgw_acl.h" #include "rgw_bucket_layout.h" #include "rgw_cors.h" @@ -43,7 +44,6 @@ #include "cls/rgw/cls_rgw_types.h" #include "include/rados/librados.hpp" #include "rgw_public_access.h" -#include "common/tracer.h" #include "rgw_sal_fwd.h" namespace ceph { @@ -1232,7 +1232,7 @@ struct req_state : DoutPrefixProvider { std::vector session_policies; - jspan trace; + jspan_ptr trace; bool trace_enabled = false; //Principal tags that come in as part of AssumeRoleWithWebIdentity diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index b5ce737147f18..ffc65836ce621 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -1220,7 +1220,7 @@ protected: std::string multipart_upload_id; std::string multipart_part_str; int multipart_part_num = 0; - jspan multipart_trace; + jspan_ptr multipart_trace; boost::optional delete_at; //append obj @@ -1847,7 +1847,7 @@ protected: std::string upload_id; RGWAccessControlPolicy policy; ceph::real_time mtime; - jspan multipart_trace; + jspan_ptr multipart_trace; public: RGWInitMultipart() {} @@ -1875,7 +1875,7 @@ protected: std::string version_id; bufferlist data; std::unique_ptr serializer; - jspan multipart_trace; + jspan_ptr multipart_trace; public: RGWCompleteMultipart() {} @@ -1896,7 +1896,7 @@ public: class RGWAbortMultipart : public RGWOp { protected: - jspan multipart_trace; + jspan_ptr multipart_trace; public: RGWAbortMultipart() {} diff --git a/src/rgw/rgw_req_context.h b/src/rgw/rgw_req_context.h index b0030ca1a94b9..b8c284187c879 100644 --- a/src/rgw/rgw_req_context.h +++ b/src/rgw/rgw_req_context.h @@ -1,10 +1,8 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab ft=cpp +#pragma once #include "common/async/yield_context.h" -namespace opentelemetry::trace { - class Span; -} class DoutPrefixProvider; @@ -13,6 +11,6 @@ class DoutPrefixProvider; struct req_context { const DoutPrefixProvider* dpp{nullptr}; optional_yield y; - const opentelemetry::trace::Span* span{nullptr}; + const jspan* span; }; diff --git a/src/rgw/rgw_sal.h b/src/rgw/rgw_sal.h index 7cfd4923761f4..e7a3dfe0aa52e 100644 --- a/src/rgw/rgw_sal.h +++ b/src/rgw/rgw_sal.h @@ -15,11 +15,11 @@ #pragma once +#include "common/tracer.h" #include "rgw_sal_fwd.h" #include "rgw_lua.h" #include "rgw_user.h" #include "rgw_notify_event_type.h" -#include "common/tracer.h" #include "rgw_req_context.h" #include "rgw_datalog_notify.h" #include "include/random.h" -- 2.39.5