Skip to content

fix: Add Firebase dashboard resource attributes for Python telemetry visibility#4654

Open
zarinn3pal wants to merge 2 commits intofirebase:mainfrom
zarinn3pal:fix/firebase-dashboard
Open

fix: Add Firebase dashboard resource attributes for Python telemetry visibility#4654
zarinn3pal wants to merge 2 commits intofirebase:mainfrom
zarinn3pal:fix/firebase-dashboard

Conversation

@zarinn3pal
Copy link
Contributor

This PR adds dashboard resource attributes so that AIM dashboard gets populated

@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 enhances the Python telemetry setup by integrating Firebase-compatible resource attributes. This ensures that telemetry data from Python applications is correctly recognized and displayed within the Firebase Genkit monitoring dashboard, aligning its behavior with existing JavaScript and Go implementations.

Highlights

  • Firebase-compatible Resource Attributes: Introduced SERVICE_VERSION and GENKIT_VERSION imports to enable versioning in telemetry resources, crucial for Firebase dashboard compatibility.
  • Standardized Resource Creation: Implemented a new private method, _create_firebase_resource, to generate OpenTelemetry resources with specific attributes required for Firebase dashboard compatibility, including SERVICE_NAME, SERVICE_VERSION, SERVICE_INSTANCE_ID, type, source, and sourceVersion.
  • Unified Resource Attribution: Refactored _configure_tracing and _configure_metrics to utilize the new _create_firebase_resource method, ensuring consistent resource attribution across both tracing and metrics.
  • Exporter Resource Parameter: Modified the GenkitGCPExporter to accept an optional resource parameter, allowing for custom resource attribution during trace export.
  • Updated Test Coverage: Adjusted a test case (test_add_gcp_telemetry_disable_metrics) to confirm that resource detection still occurs for tracing even when metrics collection is explicitly disabled, which is crucial for dashboard visibility.

🧠 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/google-cloud/src/genkit/plugins/google_cloud/telemetry/config.py
    • Imported SERVICE_VERSION from opentelemetry.sdk.resources and GENKIT_VERSION from genkit.core.
    • Added a new private method _create_firebase_resource to construct OpenTelemetry resources with Firebase-specific attributes, merging them with GCP resource detection.
    • Modified _configure_tracing to call _create_firebase_resource and pass the resulting resource to the GenkitGCPExporter.
    • Updated _configure_metrics to use the _create_firebase_resource method for metric resource creation, replacing the previous inline resource definition.
  • py/plugins/google-cloud/src/genkit/plugins/google_cloud/telemetry/trace_exporter.py
    • Imported Resource from opentelemetry.sdk.resources.
    • Added an optional resource parameter to the GenkitGCPExporter constructor.
    • Stored the provided resource as an instance variable within the GenkitGCPExporter.
  • py/plugins/google-cloud/tests/tracing_test.py
    • Updated the docstring for test_add_gcp_telemetry_disable_metrics to clarify that resource detection still occurs for traces.
    • Added assertions to test_add_gcp_telemetry_disable_metrics to verify that GoogleCloudResourceDetector is called once for trace resource detection, even when metrics are disabled.
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 aims to add Firebase-compatible resource attributes to telemetry data for better visibility in dashboards. The changes include refactoring resource creation into a shared method, which is a good improvement for code reuse and consistency. The resource attributes are correctly applied to metrics. However, there is a critical issue where the new resource attributes are not applied to traces due to an incomplete implementation in the trace exporter. This means the primary goal of the PR is not fully achieved for tracing. Additionally, the related test case should be strengthened to verify that the resource attributes are correctly attached to exported spans.

error_handler: Optional callback invoked when export errors occur.
resource: Optional OpenTelemetry resource for consistent attribution.
"""
self.resource = resource
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The resource parameter is stored in self.resource but it's never used. This means the Firebase-compatible resource attributes will not be applied to traces, and they won't appear correctly in the Firebase dashboard. The resource needs to be attached to the spans before they are exported.

The standard OpenTelemetry approach is to configure the TracerProvider with a Resource. However, Genkit's tracing initialization seems to make this difficult to do from a plugin.

A possible fix within this exporter would be to wrap the span and override its resource property before exporting. This would involve creating a custom ReadableSpan wrapper that merges self.resource with the span's existing resource.

This is a significant issue that prevents the PR from working as intended for traces.

Comment on lines +216 to +218
# Verify resource detection was called for traces (Firebase dashboard needs this)
mock_detector.assert_called_once_with(raise_on_error=True)
mock_detector.return_value.detect.assert_called_once()
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This test correctly verifies that resource detection is performed. However, it doesn't verify that the detected and created resource is actually applied to the exported traces. As noted in another comment, the resource object is currently not being used by the trace exporter, which is a critical bug.

The test should be extended to assert that the exported spans contain the merged resource attributes. This could be done by inspecting the spans passed to the mocked GenkitGCPExporter.export method.

@huangjeff5
Copy link
Contributor

Hmm this doesn't seem right. I was able to get some stuff to show in AIM dashboard just by fixing the logging pattern.

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

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants