Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions py/plugins/firebase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,17 @@

This Genkit plugin provides a set of tools and utilities for working with
Firebase.

## Install

Firestore integrations (no telemetry):

```bash
pip install genkit-plugin-firebase
```

Telemetry export to Google Cloud Observability (Cloud Trace + Cloud Monitoring):

```bash
pip install "genkit-plugin-firebase[telemetry]"
```
4 changes: 4 additions & 0 deletions py/plugins/firebase/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ readme = "README.md"
requires-python = ">=3.10"
version = "0.5.0"

[project.optional-dependencies]
# Telemetry export uses the Google Cloud telemetry exporters (Cloud Trace/Monitoring).
telemetry = ["genkit-plugin-google-cloud"]

[project.urls]
"Bug Tracker" = "https://github.com/firebase/genkit/issues"
"Documentation" = "https://firebase.google.com/docs/genkit"
Expand Down
11 changes: 9 additions & 2 deletions py/plugins/firebase/src/genkit/plugins/firebase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@
- Genkit documentation: https://genkit.dev/
"""

from genkit.plugins.google_cloud.telemetry.tracing import add_gcp_telemetry

from .firestore import define_firestore_vector_store


Expand All @@ -195,6 +193,15 @@ def add_firebase_telemetry() -> None:
Exports traces to Cloud Trace and metrics to Cloud Monitoring.
In development (GENKIT_ENV=dev), telemetry is disabled by default.
"""
try:
# Imported lazily so Firestore-only users don't need telemetry deps.
from genkit.plugins.google_cloud.telemetry.tracing import add_gcp_telemetry
except ImportError as e: # pragma: no cover
raise ImportError(
'Firebase telemetry requires the Google Cloud telemetry exporter. '
'Install it with: pip install "genkit-plugin-firebase[telemetry]"'
) from e
Comment on lines +199 to +203
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The pragma: no cover on this except block indicates that this error handling path is not covered by tests. While this is sometimes acceptable for optional dependency checks, adding a test would increase robustness and verify that the helpful error message is raised correctly.

Consider adding a test case to py/plugins/firebase/tests/firebase_plugin_test.py that simulates the missing dependency. Here's an example using pytest and unittest.mock:

import sys
from unittest.mock import patch
import pytest
from genkit.plugins.firebase import add_firebase_telemetry

def test_add_firebase_telemetry_raises_on_missing_deps():
    """Test that an informative ImportError is raised if telemetry deps are missing."""
    # Temporarily remove the module from sys.modules to simulate it not being installed.
    with patch.dict(sys.modules, {'genkit.plugins.google_cloud.telemetry.tracing': None}):
        with pytest.raises(ImportError, match='Firebase telemetry requires the Google Cloud telemetry exporter'):
            add_firebase_telemetry()

This ensures that users who haven't installed the [telemetry] extra will receive the correct guidance.


add_gcp_telemetry(force_export=False)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _create_model_span(
return mock_span


@patch('genkit.plugins.firebase.add_gcp_telemetry')
@patch('genkit.plugins.google_cloud.telemetry.tracing.add_gcp_telemetry')
def test_firebase_telemetry_delegates_to_gcp(mock_add_gcp_telemetry: MagicMock) -> None:
"""Test that Firebase telemetry delegates to GCP telemetry."""
add_firebase_telemetry()
Expand Down
2 changes: 1 addition & 1 deletion py/plugins/firebase/tests/firebase_plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_package_name() -> None:
assert package_name() == 'genkit.plugins.firebase'


@patch('genkit.plugins.firebase.add_gcp_telemetry')
@patch('genkit.plugins.google_cloud.telemetry.tracing.add_gcp_telemetry')
def test_add_firebase_telemetry_calls_gcp_telemetry(mock_add_gcp: MagicMock) -> None:
"""Test add_firebase_telemetry delegates to GCP telemetry."""
add_firebase_telemetry()
Expand Down
Loading