Skip to content

feat(bigquery): add default_attributes config to BigQueryAgentAnalyticsPlugin#4207

Open
andrewrfitz wants to merge 2 commits intogoogle:mainfrom
andrewrfitz:feat/bigquery-default-attributes
Open

feat(bigquery): add default_attributes config to BigQueryAgentAnalyticsPlugin#4207
andrewrfitz wants to merge 2 commits intogoogle:mainfrom
andrewrfitz:feat/bigquery-default-attributes

Conversation

@andrewrfitz
Copy link

@andrewrfitz andrewrfitz commented Jan 20, 2026

Summary

This PR adds a new default_attributes configuration option to BigQueryLoggerConfig that allows users to inject static key-value pairs into every logged event's attributes field.

Use case: When deploying ADK-based services, it's useful to include deployment metadata (service version, environment, commit SHA, etc.) in analytics events for filtering and debugging in BigQuery.

Closes #4212

Changes

  • Added default_attributes: Optional[dict[str, Any]] = None to BigQueryLoggerConfig
  • Modified _log_event() to merge default attributes with event-specific attributes
  • Event-specific attributes override defaults when there are key conflicts
  • Fully backward compatible (defaults to None)

Example Usage

config = BigQueryLoggerConfig(
    default_attributes={
        "service_version": "1.2.3",
        "environment": "production",
        "commit_sha": "abc123",
    }
)
plugin = BigQueryAgentAnalyticsPlugin(
    project_id="my-project",
    dataset_id="adk_analytics", 
    config=config,
)

All events logged by this plugin will now include these attributes in the attributes JSON column.

Testing Plan

Unit Tests

Added 3 new unit tests:

  • test_default_attributes_included_in_events - verifies default attributes appear in logged events
  • test_default_attributes_overridden_by_event_attributes - verifies event-specific attributes take precedence
  • test_default_attributes_none_does_not_affect_events - verifies backward compatibility

Test Results

pytest tests/unittests/plugins/test_bigquery_agent_analytics_plugin.py -v
======================== 46 passed, 1 warning in 8.76s =========================

All existing tests continue to pass.

@google-cla
Copy link

google-cla bot commented Jan 20, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @andrewrfitz, 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 BigQuery analytics plugin by providing a mechanism to automatically enrich all logged events with predefined, static metadata. This capability simplifies the process of adding consistent contextual information, such as deployment details, to analytics data, which is invaluable for subsequent filtering, analysis, and debugging within BigQuery without requiring manual inclusion in every event.

Highlights

  • New Configuration Option: Introduced a default_attributes configuration option to BigQueryLoggerConfig.
  • Static Metadata Injection: This new option allows users to inject static key-value pairs into every logged event's attributes field, useful for deployment metadata like service version or environment.
  • Attribute Merging Logic: Implemented logic to merge default_attributes with event-specific attributes, ensuring that event-specific attributes take precedence in case of key conflicts.
  • Backward Compatibility: The feature is fully backward compatible, as default_attributes defaults to None.
  • Unit Test Coverage: Added three new unit tests to verify the inclusion of default attributes, the override behavior by event-specific attributes, and proper functionality when default_attributes is None.

🧠 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.

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.

@adk-bot adk-bot added the services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc label Jan 20, 2026
@adk-bot
Copy link
Collaborator

adk-bot commented Jan 20, 2026

Response from ADK Triaging Agent

Hello @andrewrfitz, thank you for your contribution!

Before we can merge this PR, could you please:

This will help us to track the work and review your PR more efficiently. Thanks!

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 introduces a default_attributes configuration option to the BigQueryAgentAnalyticsPlugin, allowing for the injection of static key-value pairs into every logged event. This is a valuable feature for enriching analytics data with deployment metadata. The implementation correctly merges default and event-specific attributes, prioritizing the latter in case of conflicts. The changes are well-documented, and the accompanying unit tests are comprehensive, covering all key aspects of the new functionality including attribute inclusion, overriding, and backward compatibility. The code quality is high, and I have no concerns with the proposed changes.

@andrewrfitz
Copy link
Author

@ryanaiagent I've followed the steps for CLA as a 'Corporate signer', I'm in the google group and signed the CLA, but it's still failing the git action. Can you provide an guidance here?

@ryanaiagent ryanaiagent added request clarification [Status] The maintainer need clarification or more information from the author bq [Component] This issue is related to Big Query integration and removed services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc labels Jan 22, 2026
@ryanaiagent
Copy link
Collaborator

@andrewrfitz
Copy link
Author

Hi @andrewrfitz , try https://cla.developers.google.com/ .

99be03e Author: @andrewrfitz <and******tz​@bilt.com>

I've signed the CLA, and this email is in the google group associated, but the check is still failing. Not sure if there's anything else I can try?

@ryanaiagent
Copy link
Collaborator

Hi @andrewrfitz , maybe try the following the steps mentioned in the link below for googlers and TVC.

@andrewrfitz andrewrfitz force-pushed the feat/bigquery-default-attributes branch from 99be03e to 34fea3e Compare January 27, 2026 04:47
…csPlugin

Add a new `default_attributes` configuration option to BigQueryLoggerConfig
that allows users to inject static key-value pairs into every logged event's
attributes field. This is useful for adding deployment metadata like service
version, environment, or commit SHA to all analytics events.

Features:
- New `default_attributes: Optional[dict[str, Any]]` config field
- Default attributes are merged into every event's attributes
- Event-specific attributes override defaults when there are conflicts
- Fully backward compatible (None by default)

Example usage:
```python
config = BigQueryLoggerConfig(
    default_attributes={
        "service_version": "1.2.3",
        "environment": "production",
    }
)
plugin = BigQueryAgentAnalyticsPlugin(
    project_id, dataset_id, config=config
)
```
@andrewrfitz andrewrfitz force-pushed the feat/bigquery-default-attributes branch from 34fea3e to 9e2355f Compare January 27, 2026 04:48
@andrewrfitz
Copy link
Author

Hi @andrewrfitz , maybe try the following the steps mentioned in the link below for googlers and TVC.

I've tried everything, still not working :/

My public email is in our corporate CLA, its the same one attached to my commit

@andrewrfitz
Copy link
Author

@ryanaiagent finally got it working! ready for review now, thank you for your help 🙏

@ryanaiagent ryanaiagent removed the request clarification [Status] The maintainer need clarification or more information from the author label Feb 2, 2026
@ryanaiagent
Copy link
Collaborator

Hi @Jacksunwei , can you please review this.

@ryanaiagent ryanaiagent added the needs review [Status] The PR/issue is awaiting review from the maintainer label Feb 2, 2026
@andrewrfitz andrewrfitz force-pushed the feat/bigquery-default-attributes branch from 2fa9b88 to f4acc63 Compare February 4, 2026 14:44
Resolves merge conflicts by keeping both features:
- default_attributes config option (this branch)
- log_session_metadata and custom_tags config options (main)
@andrewrfitz andrewrfitz force-pushed the feat/bigquery-default-attributes branch from f4acc63 to a22ce47 Compare February 4, 2026 14:47
@caohy1988
Copy link

Recommended Solution: Use custom_tags

Technically, the existing custom_tags configuration already solves the core problem: injecting static metadata into every analytics event.

Instead of waiting for a new default_attributes feature, you can configure your BigQueryLoggerConfig right now like this:

config = BigQueryLoggerConfig(
    # ... other config ...
    custom_tags={
        "service_version": os.getenv("SERVICE_VERSION", "unknown"),
        "environment": os.getenv("ENVIRONMENT", "development"),
        "commit_sha": os.getenv("COMMIT_SHA", "unknown"),
        "deployment_id": os.getenv("DEPLOYMENT_ID"),
    }
)

This approach avoids waiting for a new release and keeps your deployment metadata cleanly separated from other dynamic event attributes.

Querying Metadata

The only user-facing difference between custom_tags and the proposed default_attributes feature is the JSON path in BigQuery. Your metadata will be nested under a custom_tags key within the attributes JSON column (rather than being at the root).

You can query it easily using JSON functions:

Feature Query Syntax
default_attributes (Proposed) WHERE JSON_VALUE(attributes, '$.environment') = 'production'
custom_tags (Existing) WHERE JSON_VALUE(attributes, '$.custom_tags.environment') = 'production'

Example queries:

-- Query events by environment
SELECT *
FROM `your_project.your_dataset.agent_events_v2`
WHERE JSON_VALUE(attributes, '$.custom_tags.environment') = 'production'

-- Debug specific commits
SELECT *
FROM `your_project.your_dataset.agent_events_v2`
WHERE JSON_VALUE(attributes, '$.custom_tags.commit_sha') = 'abc123';

Recommendation

Unless you have a strict requirement for "root-level" attributes (e.g., for compatibility with existing queries or downstream pipelines that expect a flat schema), we recommend using custom_tags.

Using custom_tags keeps the API surface smaller and cleaner. It also neatly namespaces "deployment/environment" metadata away from "runtime/event" metadata, which is arguably a better practice anyway.

We suggest closing this feature request as "Working as Intended" by leveraging the existing custom_tags functionality.

@andrewrfitz
Copy link
Author

Recommended Solution: Use custom_tags

Technically, the existing custom_tags configuration already solves the core problem: injecting static metadata into every analytics event.

Instead of waiting for a new default_attributes feature, you can configure your BigQueryLoggerConfig right now like this:

config = BigQueryLoggerConfig(
    # ... other config ...
    custom_tags={
        "service_version": os.getenv("SERVICE_VERSION", "unknown"),
        "environment": os.getenv("ENVIRONMENT", "development"),
        "commit_sha": os.getenv("COMMIT_SHA", "unknown"),
        "deployment_id": os.getenv("DEPLOYMENT_ID"),
    }
)

This approach avoids waiting for a new release and keeps your deployment metadata cleanly separated from other dynamic event attributes.

Querying Metadata

The only user-facing difference between custom_tags and the proposed default_attributes feature is the JSON path in BigQuery. Your metadata will be nested under a custom_tags key within the attributes JSON column (rather than being at the root).

You can query it easily using JSON functions:

Feature Query Syntax
default_attributes (Proposed) WHERE JSON_VALUE(attributes, '$.environment') = 'production'
custom_tags (Existing) WHERE JSON_VALUE(attributes, '$.custom_tags.environment') = 'production'
Example queries:

-- Query events by environment
SELECT *
FROM `your_project.your_dataset.agent_events_v2`
WHERE JSON_VALUE(attributes, '$.custom_tags.environment') = 'production'

-- Debug specific commits
SELECT *
FROM `your_project.your_dataset.agent_events_v2`
WHERE JSON_VALUE(attributes, '$.custom_tags.commit_sha') = 'abc123';

Recommendation

Unless you have a strict requirement for "root-level" attributes (e.g., for compatibility with existing queries or downstream pipelines that expect a flat schema), we recommend using custom_tags.

Using custom_tags keeps the API surface smaller and cleaner. It also neatly namespaces "deployment/environment" metadata away from "runtime/event" metadata, which is arguably a better practice anyway.

We suggest closing this feature request as "Working as Intended" by leveraging the existing custom_tags functionality.

Thanks for the detailed response @caohy1988! You're right that custom_tags covers the static deployment metadata use case I described in this PR.

However, my broader goal is actually per-session dynamic metadata in BigQuery events, not just static deployment tags. For example, attaching session-specific context to every event row so I can filter/debug in BigQuery at the session level.

custom_tags can't solve this since it's set once at plugin construction time and stamped identically on every event across all sessions.

Thoughts on this?

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

Labels

bq [Component] This issue is related to Big Query integration needs review [Status] The PR/issue is awaiting review from the maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add default_attributes config to BigQueryAgentAnalyticsPlugin for deployment metadata

4 participants