Class GenerateTelemetry

java.lang.Object
com.google.genkit.ai.telemetry.GenerateTelemetry

public class GenerateTelemetry extends Object
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 Details

    • getInstance

      public static GenerateTelemetry 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 name
      featureName - the feature name (flow name or "generate")
      path - the span path
      response - the model response (may be null)
      latencyMs - the latency in milliseconds
      error - the error name if failed, null otherwise