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
- Request tracing
- Performance metrics
- Error tracking
- Usage analytics
Durable Streaming (Beta)
Durable streaming persists stream state, allowing clients to disconnect and reconnect without losing progress. The plugin provides twoStreamManager implementations:
Firestore Stream Manager
Persists stream state in Google Cloud Firestore:- 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:- 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:functions/src/index.ts:
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
- Go to Firebase Console
- Select your project
- Navigate to Genkit section
- 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:Best Practices
Production Monitoring
- Always enable telemetry in production:
-
Set up alerts in Firebase Console for:
- High error rates
- Increased latency
- Usage spikes
-
Review metrics regularly to identify:
- Performance bottlenecks
- Cost optimization opportunities
- Usage patterns
Durable Streaming
-
Choose the right storage:
- Firestore - Most use cases, strict 1MB limit
- RTDB - Larger streams, more flexible
- Handle stream limits:
- Clean up old streams periodically: