| 68 | /// Optionally start a child span for each invocation. |
| 69 | template <typename T> |
| 70 | AsyncGenerator<T> WrapAsyncGenerator(AsyncGenerator<T> wrapped, |
| 71 | const std::string& span_name = "", |
| 72 | bool create_childspan = false) { |
| 73 | auto active_span = GetTracer()->GetCurrentSpan(); |
| 74 | return [=]() mutable -> Future<T> { |
| 75 | auto span = active_span; |
| 76 | auto scope = GetTracer()->WithActiveSpan(active_span); |
| 77 | auto fut = wrapped(); |
| 78 | if (create_childspan) { |
| 79 | span = GetTracer()->StartSpan(span_name); |
| 80 | } |
| 81 | fut.AddCallback([span](const Result<T>& result) { |
| 82 | MarkSpan(result.status(), span.get()); |
| 83 | span->End(); |
| 84 | }); |
| 85 | return fut; |
| 86 | }; |
| 87 | } |
| 88 | |
| 89 | /// \brief Propagate the given span to each invocation of an async generator. |
| 90 | template <typename T> |