You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/04/04 15:22:40 UTC

[GitHub] [arrow] joosthooz commented on a diff in pull request #12609: ARROW-15067: [C++] Add tracing spans to the scanner

joosthooz commented on code in PR #12609:
URL: https://github.com/apache/arrow/pull/12609#discussion_r841866871


##########
cpp/src/arrow/util/tracing_internal.h:
##########
@@ -101,6 +86,33 @@ AsyncGenerator<T> WrapAsyncGenerator(AsyncGenerator<T> wrapped,
   };
 }
 
+/// \brief Propagate the given span to each invocation of an async generator.
+template <typename T>
+AsyncGenerator<T> PropagateSpanThroughAsyncGenerator(
+    AsyncGenerator<T> wrapped,
+    opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> span) {
+  return [=]() mutable -> Future<T> {
+    auto scope = GetTracer()->WithActiveSpan(span);
+    return wrapped();
+  };
+}
+
+/// \brief Propagate the currently active span to each invocation of an async generator.
+template <typename T>
+AsyncGenerator<T> PropagateSpanThroughAsyncGenerator(AsyncGenerator<T> wrapped) {
+  auto span = GetTracer()->GetCurrentSpan();
+  if (!span->GetContext().IsValid()) return wrapped;
+  return PropagateSpanThroughAsyncGenerator(std::move(wrapped), std::move(span));
+}
+
+/*
+ * PropagateSpanThroughAsyncGenerator - only makes sure the trace context is propagated,
+ * so that spans created when running generator instances asynchronously do not
+ * end up in a separate, disconnected trace.
+ * WrapAsyncGenerator - Connect the current span to the generator. When the generator
+ * finishes, it will stop the span. Optionally, create child spans at each invocation.

Review Comment:
   Yeah, after merging the 3 functions into 2, the extra block isn't really needed anymore. I've extended the `\brief`s instead.



-- 
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: github-unsubscribe@arrow.apache.org

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