You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "teckick (via GitHub)" <gi...@apache.org> on 2023/04/14 17:19:06 UTC

[GitHub] [incubator-opendal] teckick commented on a diff in pull request #2001: Add OpenTelemetry metrics and trace

teckick commented on code in PR #2001:
URL: https://github.com/apache/incubator-opendal/pull/2001#discussion_r1167104596


##########
core/src/layers/oteltrace.rs:
##########
@@ -0,0 +1,53 @@
+use opentelemetry::global;
+use opentelemetry::trace::FutureExt;
+use opentelemetry::trace::Span;
+use opentelemetry::trace::TraceContextExt;
+use opentelemetry::trace::Tracer;
+use opentelemetry::Context;
+
+use crate::ops::*;
+use crate::raw::*;
+
+pub struct OtelTraceLayer;
+
+#[derive(Debug)]
+pub struct OtelTraceAccessor<A> {
+    inner: A,
+}
+
+#[async_trait]
+impl<A: Accessor> LayeredAccessor for OtelTraceAccessor<A> {
+    type Inner = A;
+    type Reader = OtelTraceWrapper<A::Reader>;
+    type BlockingReader = OtelTraceWrapper<A::BlockingReader>;
+    type Writer = OtelTraceWrapper<A::Writer>;
+    type BlockingWriter = OtelTraceWrapper<A::BlockingWriter>;
+    type Pager = OtelTraceWrapper<A::Pager>;
+    type BlockingPager = OtelTraceWrapper<A::BlockingPager>;
+
+    fn inner(&self) -> &Self::Inner {
+        &self.inner
+    }
+
+    fn metadata(&self) -> AccessorInfo {
+        let tracer = global::tracer("opendal");
+        tracer.in_span("metadata", self.inner.info())
+    }
+
+    async fn create(&self, path: &str, args: OpCreate) -> Result<RpCreate> {
+        let tracer = global::tracer("opendal");
+        let cx = Context::current_with_value(span);
+        self.inner.create(path, args).with_context(cx).await
+    }

Review Comment:
   @Xuanwo Should I import the `opentelemetry` crate and use the trace API like this?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org