]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tracing/osd/rgw: using jspan as alias to opentelemetry::Span 53547/head
authorYuval Lifshitz <ylifshit@redhat.com>
Tue, 10 Oct 2023 17:30:54 +0000 (17:30 +0000)
committerYuval Lifshitz <ylifshit@redhat.com>
Thu, 12 Oct 2023 04:54:37 +0000 (04:54 +0000)
and jspan_ptr as jspan shared pointer

Signed-off-by: Yuval Lifshitz <ylifshit@redhat.com>
src/common/tracer.cc
src/common/tracer.h
src/osd/OpRequest.h
src/rgw/rgw_common.h
src/rgw/rgw_op.h
src/rgw/rgw_req_context.h
src/rgw/rgw_sal.h

index 1146da319500d9336cf84b3e94f3646a3961d2a5..e98053735b48d88ea41d5a0af2ee08559c777648 100644 (file)
@@ -17,7 +17,7 @@
 namespace tracing {
 
 const opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> 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;
index 94efedbed6e10610a3a4799f4d0a76e0d420d890..291ff9de25a7becc77b8b881ebc736bde3d0f1e8 100644 (file)
@@ -9,7 +9,8 @@
 #ifdef HAVE_JAEGER
 #include "opentelemetry/trace/provider.h"
 
-using jspan = opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span>;
+using jspan = opentelemetry::trace::Span;
+using jspan_ptr = opentelemetry::nostd::shared_ptr<jspan>;
 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<opentelemetry::trace::Tracer> noop_tracer;
-  const static jspan noop_span;
+  const static jspan_ptr noop_span;
   CephContext* cct = nullptr;;
   opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> 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 <typename T>
   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) {}
index 8df4f25d53e595348eeccb7f89ae74fa768f458b..23f3b1d932e9f38d093594e308968226b6c0be66 100644 (file)
@@ -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<class T>
   const T* get_req() const { return static_cast<const T*>(request); }
index a71f1368070eca594f7368acc0a0450fac35acac..1094d0cd443eae82a681e8d2ef929a4e48daff8d 100644 (file)
@@ -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<rgw::IAM::Policy> session_policies;
 
-  jspan trace;
+  jspan_ptr trace;
   bool trace_enabled = false;
 
   //Principal tags that come in as part of AssumeRoleWithWebIdentity
index b5ce737147f187eda7ec6ed308209158c9bb0718..ffc65836ce621133da91750449376f7920155869 100644 (file)
@@ -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<ceph::real_time> 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<rgw::sal::MPSerializer> 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() {}
 
index b0030ca1a94b9f2d15d72d899ad9130e37fa8086..b8c284187c8799c43cb50a9f307cd716a79f42bd 100644 (file)
@@ -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;
 };
 
index 7cfd4923761f41715d0d3ee884607ddf27fb634f..e7a3dfe0aa52e979e8f963c0859bbaee9fd8d210 100644 (file)
 
 #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"