Skip to content

py(firebase): add telemetry extra and lazy-load Google Cloud exporters#4475

Open
huangjeff5 wants to merge 1 commit intomainfrom
jh-firebase-plugin-change
Open

py(firebase): add telemetry extra and lazy-load Google Cloud exporters#4475
huangjeff5 wants to merge 1 commit intomainfrom
jh-firebase-plugin-change

Conversation

@huangjeff5
Copy link
Contributor

Add an optional telemetry extra to genkit-plugin-firebase so users can install Firebase telemetry dependencies with a single command, without forcing heavy Google Cloud/OpenTelemetry deps on Firestore-only installs.

@github-actions github-actions bot added docs Improvements or additions to documentation python Python config labels Feb 6, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @huangjeff5, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the dependency management for the genkit-plugin-firebase by making telemetry-related Google Cloud dependencies optional. By introducing a telemetry extra and implementing lazy loading for the Google Cloud exporters, users who only require Firestore functionalities can enjoy a lighter installation without unnecessary packages. This change improves the flexibility and efficiency of the plugin's dependency footprint.

Highlights

  • Optional Telemetry Dependencies: Introduced an optional telemetry extra for genkit-plugin-firebase, allowing users to install Google Cloud telemetry dependencies only when needed, avoiding heavy dependencies for Firestore-only installations.
  • Lazy Loading of Exporters: Implemented lazy loading for Google Cloud telemetry exporters (add_gcp_telemetry) within the add_firebase_telemetry function, ensuring that these dependencies are only imported if the telemetry feature is actively used.
  • Installation Instructions: Updated the README.md to clearly differentiate installation commands for basic Firestore integration versus telemetry-enabled installations using the new [telemetry] extra.
  • Dependency Management: Modified pyproject.toml to define the telemetry optional dependency, linking it to genkit-plugin-google-cloud.
  • Improved Error Handling: Added an ImportError catch in add_firebase_telemetry to provide a helpful message guiding users to install the telemetry extra if the necessary dependencies are missing.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • py/plugins/firebase/README.md
    • Added a new 'Install' section detailing how to install the plugin for Firestore integrations (no telemetry) and for telemetry export to Google Cloud Observability using the [telemetry] extra.
  • py/plugins/firebase/pyproject.toml
    • Added a [project.optional-dependencies] section to define the telemetry extra, which depends on genkit-plugin-google-cloud.
  • py/plugins/firebase/src/genkit/plugins/firebase/init.py
    • Removed the direct import of add_gcp_telemetry from genkit.plugins.google_cloud.telemetry.tracing.
    • Modified add_firebase_telemetry to lazily import add_gcp_telemetry and include an ImportError handler that suggests installing the telemetry extra if the dependency is not found.
  • py/plugins/firebase/src/genkit/plugins/firebase/tests/telemetry_test.py
    • Updated the @patch decorator for add_gcp_telemetry to reflect its new lazy-loaded import path within the google_cloud.telemetry.tracing module.
  • py/plugins/firebase/tests/firebase_plugin_test.py
    • Updated the @patch decorator for add_gcp_telemetry to reflect its new lazy-loaded import path within the google_cloud.telemetry.tracing module.
Activity
  • The pull request was created by huangjeff5 to introduce optional telemetry dependencies and lazy loading for Google Cloud exporters.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively introduces an optional telemetry dependency for genkit-plugin-firebase, allowing users to avoid installing heavy Google Cloud and OpenTelemetry dependencies if they only need Firestore functionality. The implementation correctly uses project.optional-dependencies and lazy-loads the telemetry module, providing a clear ImportError when the extra is not installed. The test mocks are also updated correctly. I have one suggestion to improve test coverage for the new error handling path, which will make the implementation more robust. Overall, this is a great enhancement to the plugin.

Comment on lines +199 to +203
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
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config docs Improvements or additions to documentation python Python

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant