Skip to content

Conversation

@zarinn3pal
Copy link
Contributor

This Pr extends the AIM telemetry support by adding all firebase supported options. There were a few failing tests encountered which were fixed.

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

Summary of Changes

Hello @zarinn3pal, 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 significantly refactors and enhances the Firebase telemetry support within the Genkit framework. By extracting core GCP telemetry logic into a dedicated configuration manager and introducing modular components for constants, exporters, and specific metric/trace adjustments, the implementation becomes more robust, configurable, and aligned with Google Cloud Observability patterns. This change provides users with more granular control over how telemetry data is collected and exported, while also addressing and resolving previously failing tests to ensure the stability and correctness of the new features.

Highlights

  • Refactored Telemetry Implementation: The core GCP telemetry logic has been extracted from tracing.py into a new config.py module, centralizing the management of tracing, metrics, and logging setup. This enhances modularity and maintainability.
  • Expanded Firebase Telemetry Options: The add_firebase_telemetry function now supports a comprehensive set of configuration options, including project_id, credentials, sampler, log_input_and_output, force_dev_export, disable_metrics, disable_traces, and metric export intervals, providing greater control over telemetry behavior.
  • New Modular Telemetry Components: Several new files have been introduced within genkit-plugin-google-cloud/telemetry to house specific functionalities: constants.py for shared values, exporters.py for centralized error handling, metrics_exporter.py for GCP-compatible metric adjustments, and trace_exporter.py for robust trace export with retry logic and time adjustments.
  • Improved GCP Compatibility for Metrics and Traces: The new GenkitMetricExporter adjusts metric start times to prevent data overlap in Google Cloud Monitoring, and TimeAdjustedSpan ensures that all spans have a non-zero duration, meeting GCP Trace requirements.
  • Fixed Failing Tests and Updated Documentation: Existing tests related to telemetry initialization have been updated and fixed to align with the new modular structure. The Firebase plugin's README.md has been updated to reflect the new telemetry configuration instructions.

🧠 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 detailed documentation for enabling and configuring Firebase telemetry, including new options like project_id, force_dev_export, log_input_and_output, disable_metrics, and disable_traces.
  • py/plugins/firebase/pyproject.toml
    • Added genkit-plugin-google-cloud as a new dependency.
  • py/plugins/firebase/src/genkit/plugins/firebase/init.py
    • Removed direct import of add_gcp_telemetry.
    • Imported add_firebase_telemetry from the newly created telemetry.py module.
    • Removed the old add_firebase_telemetry function definition, delegating its implementation to the new telemetry.py.
  • py/plugins/firebase/src/genkit/plugins/firebase/telemetry.py
    • New file added, implementing the add_firebase_telemetry function.
    • This function now utilizes the GcpTelemetry manager from genkit-plugin-google-cloud to configure Firebase-specific telemetry, including project ID resolution from environment variables.
  • py/plugins/firebase/src/genkit/plugins/firebase/tests/firebase_telemetry_test.py
    • Updated tests to mock the GcpTelemetry class instead of the old add_gcp_telemetry function.
    • Added new tests to verify that configuration options (e.g., project_id, log_input_and_output, force_dev_export, disable_metrics) are correctly passed to the GcpTelemetry manager.
  • py/plugins/firebase/tests/firebase_plugin_test.py
    • Updated tests to mock the GcpTelemetry class for add_firebase_telemetry.
  • py/plugins/google-cloud/src/genkit/plugins/google_cloud/telemetry/config.py
    • New file added, introducing the GcpTelemetry class.
    • The GcpTelemetry class centralizes the configuration and initialization of tracing, metrics, and logging for GCP.
    • Includes a resolve_project_id function for consistent project ID detection across various sources (parameters, environment variables, credentials).
    • Manages the setup of structlog for trace correlation, GcpAdjustingTraceExporter for tracing, and GenkitMetricExporter for metrics.
  • py/plugins/google-cloud/src/genkit/plugins/google_cloud/telemetry/constants.py
    • New file added, defining constants for metric export intervals, project ID environment variable priorities, trace retry configurations, and time adjustments for GCP span and metric requirements.
  • py/plugins/google-cloud/src/genkit/plugins/google_cloud/telemetry/exporters.py
    • New file added, providing a reusable ErrorHandler class and handle_tracing_error, handle_metric_error functions.
    • These functions ensure that detailed error messages for telemetry export failures (especially permission-related ones) are logged only once to prevent spam.
  • py/plugins/google-cloud/src/genkit/plugins/google_cloud/telemetry/metrics_exporter.py
    • New file added, implementing GenkitMetricExporter.
    • This exporter wraps the CloudMonitoringMetricsExporter to adjust metric start times by adding 1ms, preventing data overlap when GCP converts DELTA to CUMULATIVE aggregations.
  • py/plugins/google-cloud/src/genkit/plugins/google_cloud/telemetry/trace_exporter.py
    • New file added, implementing GenkitGCPExporter which extends CloudTraceSpanExporter with robust retry logic for transient failures.
    • Introduced TimeAdjustedSpan to ensure that all spans have an end_time greater than start_time, a requirement for Google Cloud Trace.
    • Implemented GcpAdjustingTraceExporter which extends AdjustingTraceExporter to add GCP-specific telemetry recording (metrics and logs) for each span, including feature, path, generate, action, and engagement telemetry.
  • py/plugins/google-cloud/src/genkit/plugins/google_cloud/telemetry/tracing.py
    • Refactored add_gcp_telemetry to delegate its responsibilities to the new GcpTelemetry manager.
    • Removed all previously defined classes and helper functions that were moved to the new modular telemetry files (config.py, constants.py, exporters.py, metrics_exporter.py, trace_exporter.py).
  • py/plugins/google-cloud/tests/tracing_test.py
    • Updated all test imports and mocks to point to the new modular telemetry components within genkit.plugins.google_cloud.telemetry.config.
    • Added a new test case to ensure add_gcp_telemetry is fail-safe and handles initialization errors gracefully.
  • py/plugins/observability/src/genkit/plugins/observability/init.py
    • Added a check within _inject_trace_context to ensure the event_dict is a dictionary or mapping before attempting to inject trace context, improving robustness.
  • py/samples/provider-xai-hello/pyproject.toml
    • Added genkit-plugin-firebase as a dependency.
    • Configured genkit-plugin-firebase as a workspace source.
  • py/samples/provider-xai-hello/src/main.py
    • Switched from importing and calling add_gcp_telemetry to add_firebase_telemetry.
    • Updated the telemetry configuration to use add_firebase_telemetry with force_dev_export=True and log_input_and_output=True.
Activity
  • The author zarinn3pal initiated a significant refactoring of the telemetry system, moving core logic into a new config.py and creating several new, specialized modules for constants, exporters, and metric/trace handling.
  • The add_firebase_telemetry function was updated to leverage this new modular structure, providing more comprehensive configuration options.
  • Extensive updates were made to existing test files to ensure compatibility and correctness with the refactored telemetry implementation.
  • Documentation for the Firebase plugin's telemetry features was updated to guide users on the new configuration options.
  • Dependency lists in pyproject.toml files were adjusted to reflect the new module structure and inter-plugin dependencies.
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 significantly refactors the telemetry implementation by centralizing the GCP telemetry configuration into a reusable GcpTelemetry class. This allows the Firebase plugin to easily extend its telemetry support with all available options. The changes are well-structured, moving logic into new, focused modules for better maintainability. I've identified a couple of areas for improvement: one regarding some redundant code in the new Firebase telemetry module, and another concerning a change in default behavior that could be a surprising breaking change for users. Overall, this is a solid refactoring that improves the telemetry architecture.

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 fix python Python refactor

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant