obelix74 commented on code in PR #3468:
URL: https://github.com/apache/polaris/pull/3468#discussion_r2706390959


##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -429,6 +431,46 @@ public void closeTaskExecutor(@Disposes 
@Identifier("task-executor") ManagedExec
     executor.close();
   }
 
+  /**
+   * Produces the current OpenTelemetry {@link SpanContext} for the request.
+   *
+   * <p>This allows custom {@link PolarisMetricsReporter} implementations to 
access the current
+   * trace and span IDs for correlation with external monitoring systems.
+   *
+   * <p>Example usage in a custom metrics reporter:
+   *
+   * <pre>{@code
+   * @ApplicationScoped
+   * @Identifier("custom")
+   * public class CustomMetricsReporter implements PolarisMetricsReporter {
+   *
+   *   @Inject SpanContext spanContext;
+   *
+   *   @Override
+   *   public void reportMetric(String catalogName, TableIdentifier table,
+   *       MetricsReport metricsReport, long timestampMs) {
+   *     String traceId = spanContext.isValid() ? spanContext.getTraceId() : 
null;
+   *     String spanId = spanContext.isValid() ? spanContext.getSpanId() : 
null;
+   *     // Forward metrics with trace correlation...
+   *   }
+   * }
+   * }</pre>
+   *
+   * @return the current span context, or {@link SpanContext#getInvalid()} if 
no span is active
+   */
+  @Produces
+  @RequestScoped
+  public SpanContext currentSpanContext() {
+    Span currentSpan = Span.current();
+    if (currentSpan != null) {
+      SpanContext spanContext = currentSpan.getSpanContext();
+      if (spanContext != null) {
+        return spanContext;
+      }
+    }
+    return SpanContext.getInvalid();

Review Comment:
   A simple producer that allows users to inject a `SpanContext` for OTel.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to