Class Tracer

java.lang.Object
com.google.genkit.core.tracing.Tracer

public final class Tracer extends Object
Tracer provides tracing utilities for Genkit operations. It integrates with OpenTelemetry for distributed tracing.
  • Method Details

    • configureTelemetryServer

      public static void configureTelemetryServer(String serverUrl)
      Configures the telemetry server URL for exporting traces. This is typically called when the CLI notifies the runtime of the telemetry server URL.
      Parameters:
      serverUrl - the telemetry server URL
    • registerSpanProcessor

      public static void registerSpanProcessor(io.opentelemetry.sdk.trace.SpanProcessor processor)
      Registers an additional span processor for exporting traces. This allows plugins (like Firebase) to add their own exporters to send traces to external services like Google Cloud Trace.
      Parameters:
      processor - the span processor to add
    • isTelemetryConfigured

      public static boolean isTelemetryConfigured()
      Returns true if the telemetry exporter is configured.
    • runInNewSpan

      public static <I, O> O runInNewSpan(ActionContext ctx, SpanMetadata metadata, I input, BiFunction<SpanContext,I,O> fn) throws GenkitException
      Runs a function within a new tracing span.
      Type Parameters:
      I - the input type
      O - the output type
      Parameters:
      ctx - the action context
      metadata - the span metadata
      input - the input to pass to the function
      fn - the function to execute
      Returns:
      the function result
      Throws:
      GenkitException - if the function throws an exception
    • newRootSpanContext

      public static SpanContext newRootSpanContext()
      Creates a new root span context.
      Returns:
      a new SpanContext with a unique trace ID
    • newChildSpanContext

      public static SpanContext newChildSpanContext(SpanContext parent)
      Creates a child span context from a parent.
      Parameters:
      parent - the parent span context
      Returns:
      a new child SpanContext
    • addEvent

      public static void addEvent(String name, Map<String,String> attributes)
      Adds an event to the current span.
      Parameters:
      name - the event name
      attributes - the event attributes
    • recordException

      public static void recordException(Throwable exception)
      Records an exception on the current span.
      Parameters:
      exception - the exception to record