Package com.google.genkit.core.tracing
Class Tracer
java.lang.Object
com.google.genkit.core.tracing.Tracer
Tracer provides tracing utilities for Genkit operations. It integrates with
OpenTelemetry for distributed tracing.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdds an event to the current span.static voidconfigureTelemetryServer(String serverUrl) Configures the telemetry server URL for exporting traces.static booleanReturns true if the telemetry exporter is configured.static SpanContextnewChildSpanContext(SpanContext parent) Creates a child span context from a parent.static SpanContextCreates a new root span context.static voidrecordException(Throwable exception) Records an exception on the current span.static voidregisterSpanProcessor(io.opentelemetry.sdk.trace.SpanProcessor processor) Registers an additional span processor for exporting traces.static <I,O> O runInNewSpan(ActionContext ctx, SpanMetadata metadata, I input, BiFunction<SpanContext, I, O> fn) Runs a function within a new tracing span.
-
Method Details
-
configureTelemetryServer
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, throws GenkitExceptionO> fn) Runs a function within a new tracing span.- Type Parameters:
I- the input typeO- the output type- Parameters:
ctx- the action contextmetadata- the span metadatainput- the input to pass to the functionfn- the function to execute- Returns:
- the function result
- Throws:
GenkitException- if the function throws an exception
-
newRootSpanContext
Creates a new root span context.- Returns:
- a new SpanContext with a unique trace ID
-
newChildSpanContext
Creates a child span context from a parent.- Parameters:
parent- the parent span context- Returns:
- a new child SpanContext
-
addEvent
Adds an event to the current span.- Parameters:
name- the event nameattributes- the event attributes
-
recordException
Records an exception on the current span.- Parameters:
exception- the exception to record
-