Skip to main content

Firebase Plugin

The @genkit-ai/firebase plugin provides Firebase integration for Genkit, including deployment to Cloud Functions for Firebase and comprehensive telemetry/monitoring capabilities.

Installation

Features

  • Telemetry & Monitoring - Production observability in Firebase console
  • Durable Streaming - Persistent stream state with Firestore or Realtime Database
  • Cloud Functions - Deploy flows as Firebase Cloud Functions
  • Firebase Integration - Seamless integration with Firebase services

Basic Setup

Enable Telemetry

This enables:
  • Request tracing
  • Performance metrics
  • Error tracking
  • Usage analytics
View telemetry in the Firebase Console under Genkit.

Durable Streaming (Beta)

Durable streaming persists stream state, allowing clients to disconnect and reconnect without losing progress. The plugin provides two StreamManager implementations:

Firestore Stream Manager

Persists stream state in Google Cloud Firestore:
Firestore Limitations:
  • Maximum document size: 1MB (strict Firestore limit)
  • If stream output exceeds 1MB, the flow will fail
  • Store entire stream history in a single document

Realtime Database Stream Manager

Persists stream state in Firebase Realtime Database:
RTDB Considerations:
  • No strict 1MB limit like Firestore
  • Better for larger streams
  • May impact performance with very large streams
  • Subject to other RTDB quotas

Client Usage

Clients can connect and reconnect to durable streams:

Deployment

Deploy to Cloud Functions for Firebase

1. Initialize Firebase project:
2. Define flows in functions/src/index.ts:
3. Deploy:

Using with Express

For HTTP endpoints, combine with the Express plugin:

Telemetry Features

Automatic Tracking

When Firebase telemetry is enabled, Genkit automatically tracks:
  • Flow executions - Start time, duration, success/failure
  • Model calls - Provider, model name, tokens used, latency
  • Tool calls - Tool name, execution time, errors
  • Errors - Stack traces, error types, frequency
  • Custom traces - User-defined trace spans

View in Firebase Console

  1. Go to Firebase Console
  2. Select your project
  3. Navigate to Genkit section
  4. View:
    • Flow performance metrics
    • Model usage and costs
    • Error rates and logs
    • Request volumes
    • Latency percentiles

Custom Traces

Add custom tracing to your flows:

Configuration Options

Telemetry Options

Stream Manager Options

Firestore:
Realtime Database:

Best Practices

Production Monitoring

  1. Always enable telemetry in production:
  1. Set up alerts in Firebase Console for:
    • High error rates
    • Increased latency
    • Usage spikes
  2. Review metrics regularly to identify:
    • Performance bottlenecks
    • Cost optimization opportunities
    • Usage patterns

Durable Streaming

  1. Choose the right storage:
    • Firestore - Most use cases, strict 1MB limit
    • RTDB - Larger streams, more flexible
  2. Handle stream limits:
  1. Clean up old streams periodically:

Security

Secure your Cloud Functions: