Skip to content

Conversation

@eliasecchig
Copy link
Collaborator

Summary

  • Enable automatic GenAI event telemetry for all agent types (ADK, LangGraph, CrewAI)
  • Add service namespace and version tracking to telemetry events
  • Update log filters to capture gen_ai.* events by namespace

Changes

Environment variables added:

  • GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY=true - enables telemetry collection
  • OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true - captures GenAI events
  • OTEL_RESOURCE_ATTRIBUTES - includes service.namespace (project name) and service.version (commit SHA)
  • ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS=false - ADK-specific (disables span content)

Files modified:

  • agent_engine_app.py - runtime env vars for Agent Engine
  • fast_api_app.py - runtime env vars for Cloud Run
  • deploy.py - UI-visible env vars for Agent Engine deployment
  • variables.tf - updated telemetry log filter to logName=~"gen_ai\\." AND resource.labels.namespace=PROJECT_NAME

Impact

  • All new projects will capture GenAI events by default
  • Version tracking via COMMIT_SHA (defaults to "dev" for local)
  • Breaking change: new log filter replaces previous telemetry filters
  • Only affects new template-generated projects

Add environment variables to capture GenAI events (user messages, system
prompts, model completions) for all agent types across both deployment targets.

Changes:
- Set OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true for all agents
- Add service.namespace and service.version to OTEL_RESOURCE_ATTRIBUTES
- Update telemetry log filter to capture gen_ai.* logs by namespace
- Configure Agent Engine telemetry via deploy.py environment variables

This enables automatic telemetry collection for:
- ADK agents (with span content capture disabled)
- LangGraph agents
- CrewAI agents
- Both Agent Engine and Cloud Run deployments

Version tracking uses COMMIT_SHA environment variable (defaults to "dev").
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @eliasecchig, 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 introduces a standardized approach to enable and configure GenAI event telemetry across all agent types within the system. By setting essential environment variables and updating log filters, it ensures that new projects automatically capture detailed GenAI interaction events, along with critical service context like namespace and version. This enhancement significantly improves the system's observability and provides a clearer understanding of AI-powered application behavior.

Highlights

  • GenAI Telemetry Enabled: Automatic GenAI event capture is now enabled by default for all agent types, including ADK, LangGraph, and CrewAI, ensuring comprehensive observability.
  • Service Context Tracking: Telemetry events now include crucial context such as service.namespace (representing the project name) and service.version (derived from the commit SHA) for enhanced traceability and debugging.
  • Updated Log Filters: The default log filter for telemetry has been refined to specifically target and capture gen_ai.* events based on their namespace, replacing previous generic filtering mechanisms.
  • Standardized Environment Variables: Key environment variables like GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY, OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, OTEL_RESOURCE_ATTRIBUTES, and ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS are now consistently set to control and configure telemetry behavior across different deployment targets.
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 enables GenAI event telemetry by default for all agent types, which is a great step towards better observability. The changes include updating the telemetry log filter in Terraform to capture gen_ai.* events and setting several environment variables in the agent applications to enable and configure the telemetry capture, including service namespace and version tracking. My review focuses on improving code maintainability by reducing duplication and adhering to Python's standard coding style. I've left a few comments suggesting how to refactor the duplicated telemetry setup logic and correct the placement of an import statement.

Comment on lines +164 to +175
# Enable GenAI event capture for telemetry
os.environ.setdefault("GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY", "true")
{%- if cookiecutter.is_adk %}
os.environ.setdefault("ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS", "false")
{%- endif %}
os.environ.setdefault("OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT", "true")
# Set resource attributes with service namespace and commit SHA for version tracking
commit_sha = os.environ.get("COMMIT_SHA", "dev")
os.environ.setdefault(
"OTEL_RESOURCE_ATTRIBUTES",
f"service.namespace={{cookiecutter.project_name}},service.version={commit_sha}",
)
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 block of code for setting up telemetry environment variables is duplicated later in this file (lines 206-214). To improve maintainability and avoid duplication, consider extracting this logic into a shared utility function. This function could be called from both places where this setup is needed.

Comment on lines +42 to +53
# Enable GenAI event capture for telemetry
import os

os.environ.setdefault("GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY", "true")
os.environ.setdefault("ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS", "false")
os.environ.setdefault("OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT", "true")
# Set resource attributes with service namespace and commit SHA for version tracking
commit_sha = os.environ.get("COMMIT_SHA", "dev")
os.environ.setdefault(
"OTEL_RESOURCE_ATTRIBUTES",
f"service.namespace={{cookiecutter.project_name}},service.version={commit_sha}",
)
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 block of code for setting up telemetry is duplicated multiple times in this file (e.g., lines 346-357 and 473-481). To adhere to the DRY (Don't Repeat Yourself) principle and improve maintainability, I recommend extracting this logic into a single, reusable function in a utility module. This function can then be called from all the places where this setup is required.

from .app_utils.typing import Feedback

# Enable GenAI event capture for telemetry
import os
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

According to PEP 8, imports should be grouped at the top of the file. import os is a standard library import and should be placed with other standard library imports at the beginning of the file (or at the beginning of the template block, in this case, around line 15), before third-party and local application imports.1

Style Guide References

Footnotes

  1. PEP 8: Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants. Imports should be grouped in the following order: 1. Standard library imports. 2. Related third party imports. 3. Local application/library specific imports.

Add Terraform resources to control access to GenAI telemetry logs:
- Log view on _Default bucket filtered to GenAI events
- Optional log exclusion to hide GenAI logs from default bucket views
- IAM binding example for granting view-specific access
- Documentation explaining access control approach

New variable `exclude_genai_logs_from_default_bucket` (default: false):
- When true: GenAI logs excluded from _Default bucket, only in BigQuery
- When false: GenAI logs visible via log view to authorized users

This enables role-based access control for sensitive GenAI telemetry data.
@eliasecchig eliasecchig marked this pull request as draft November 12, 2025 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants