Package com.google.genkit.ai.telemetry
Class GenerateTelemetry
java.lang.Object
com.google.genkit.ai.telemetry.GenerateTelemetry
GenerateTelemetry provides metrics collection for model generate actions.
This class tracks:
- Request counts per model
- Latency histograms
- Input/output token counts
- Input/output character counts
- Input/output image counts
The metrics follow the same naming conventions as the JS and Go SDKs for consistency across the Genkit ecosystem.
Meters are obtained lazily from GlobalOpenTelemetry to ensure they use the correct MeterProvider when telemetry plugins (like Firebase) are initialized.
-
Method Summary
Modifier and TypeMethodDescriptionstatic GenerateTelemetryGets the singleton instance of GenerateTelemetry.voidrecordGenerateMetrics(String modelName, String featureName, String path, ModelResponse response, long latencyMs, String error) Records metrics for a generate action.
-
Method Details
-
getInstance
Gets the singleton instance of GenerateTelemetry.- Returns:
- the GenerateTelemetry instance
-
recordGenerateMetrics
public void recordGenerateMetrics(String modelName, String featureName, String path, ModelResponse response, long latencyMs, String error) Records metrics for a generate action.- Parameters:
modelName- the model namefeatureName- the feature name (flow name or "generate")path- the span pathresponse- the model response (may be null)latencyMs- the latency in millisecondserror- the error name if failed, null otherwise
-