GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: add user-agent delegation telemetry for pandas-gbq by shuoweil · Pull Request #18184 · googleapis/google-cloud-python

Conversation

@shuoweil

@shuoweil shuoweil commented Aug 21, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Appends pandas-gbq/<version> to ClientInfo.user_agent when RowIterator.to_dataframe() or RowIterator.to_geodataframe() is executed and query delegation is supported by pandas-gbq.

This PR enables backend metrics and BigQuery audit logs to differentiate between direct client-side conversion and delegated conversions, without altering existing DataFrame results or runtime behavior.

Supersedes #17704.

Key Changes

  • google/cloud/bigquery/table.py: Injects pandas-gbq/<version> into client_info.user_agent with deduplication check when PANDAS_GBQ_VERSIONS.is_delegation_supported is True.
  • tests/unit/test_table.py: Adds unit tests for user-agent injection, deduplication, missing client_info/user_agent, and unsupported fallback behavior.

Fixes #<540939659> 🦕

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gemini-code-assist[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction
@shuoweil
feat(bigquery): inject user-agent telemetry for pandas-gbq delegation
e9dfcb7
@shuoweil
shuoweil requested review from a team as code owners August 21, 2026 00:03
@shuoweil
shuoweil requested review from tswast and removed request for a team August 21, 2026 00:03
gemini-code-assist[bot]
gemini-code-assist Bot reviewed Aug 21, 2026
View reviewed changes

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

Copy link
Copy Markdown
Contributor

There was a problem hiding this 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 updates the to_dataframe method in table.py to append pandas-gbq telemetry to the client's user agent when delegation is supported, and adds comprehensive unit tests to verify this behavior. The review feedback suggests wrapping the user-agent update logic in a try-except block to ensure robust defensive programming and prevent potential crashes. Additionally, it recommends mocking installed_version in the geodataframe tests to avoid import errors in environments where pandas-gbq is not installed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/google-cloud-bigquery/google/cloud/bigquery/table.py Outdated
Comment on lines +2994 to +3002
if _versions_helpers.PANDAS_GBQ_VERSIONS.is_delegation_supported:
client_info = getattr(
getattr(self.client, "_connection", None), "_client_info", None
)
if client_info:
ua = client_info.user_agent or ""
if "pandas-gbq" not in ua:
version = _versions_helpers.PANDAS_GBQ_VERSIONS.installed_version
client_info.user_agent = f"{ua} pandas-gbq/{version}".strip()

@gemini-code-assist gemini-code-assist Bot Aug 21, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

medium

Telemetry and user-agent updates should be treated as best-effort operations. If client_info is a mock, a custom read-only object, or lacks the user_agent attribute, accessing or modifying client_info.user_agent directly could raise an AttributeError or other exceptions, causing the core to_dataframe() call to crash.

To ensure robust defensive programming, we should wrap this telemetry update in a try-except block and use getattr to safely access user_agent. Avoid silently passing on exceptions; instead, log the exception using logger.warning to aid in debugging and prevent masking underlying issues.

        if _versions_helpers.PANDAS_GBQ_VERSIONS.is_delegation_supported:
            try:
                client_info = getattr(
                    getattr(self.client, "_connection", None), "_client_info", None
                )
                if client_info:
                    ua = getattr(client_info, "user_agent", None) or ""
                    if "pandas-gbq" not in ua:
                        version = _versions_helpers.PANDAS_GBQ_VERSIONS.installed_version
                        client_info.user_agent = f"{ua} pandas-gbq/{version}".strip()
            except Exception as exc:
                logger.warning("Failed to update telemetry user-agent: %s", exc)
References
  1. Avoid broad except Exception: blocks that silently return None. Instead, log the exception (e.g., using logger.warning) to aid in debugging and prevent masking underlying issues.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

shuoweil reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@shuoweil shuoweil Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

fixed

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/google-cloud-bigquery/tests/unit/test_table.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

shuoweil and others added 2 commits August 20, 2026 17:09
@shuoweil @gemini-code-assist
Update packages/google-cloud-bigquery/tests/unit/test_table.py
68f68bf
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@shuoweil
fix(bigquery): defensively update user-agent telemetry
f033e19
@shuoweil
shuoweil requested a review from sycai August 21, 2026 00:21
sycai
sycai reviewed Aug 21, 2026
View reviewed changes
Comment thread packages/google-cloud-bigquery/google/cloud/bigquery/table.py Outdated
)
client_info.user_agent = f"{ua} pandas-gbq/{version}".strip()
except Exception as exc:
_LOGGER.warning("Failed to update telemetry user-agent: %s", exc)

@sycai sycai Aug 21, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Do we need this logging? I think it would print unwanted contents on the user's terminal or notebook, right?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@shuoweil shuoweil Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Good point! Telemetry injection is best-effort and shouldn't emit user-facing warnings on terminals or notebooks if mutating client_info fails. I will downgrade _LOGGER.warning to _LOGGER.debug and update the corresponding unit test.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/google-cloud-bigquery/google/cloud/bigquery/table.py
Comment on lines 2995 to +2996

if _versions_helpers.PANDAS_GBQ_VERSIONS.is_delegation_supported:

@sycai sycai Aug 21, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Could you share the link to the code where pandas-gbq is used as the delegation?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@shuoweil shuoweil Aug 31, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

In Phase 1 (Storage Read MVP), delegation is implemented in google-cloud-bigquery-storage ReadRowsPage.to_arrow() (merged in PR #17938 / v2.40.0), which delegates row decoding directly to pandas_gbq.arrow.from_read_rows_response() (released in pandas-gbq v0.35.1 via PR #17958).

When RowIterator.to_dataframe() or to_geodataframe() runs, it calls self.to_arrow() using the Storage Read client, executing through this delegation path.

_versions_helpers.PANDAS_GBQ_VERSIONS.is_delegation_supported (merged in PR #17957) checks _internal_delegation_api_version to safely gate the pandas-gbq/{version} user-agent telemetry decoration so we can track delegated usage.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@shuoweil
fix(bigquery): downgrade telemetry failure log to debug
776a74f
@shuoweil
shuoweil requested a review from sycai September 1, 2026 19:15
sycai
sycai reviewed Sep 2, 2026
View reviewed changes
Comment thread packages/google-cloud-bigquery/tests/unit/test_table.py Outdated
False,
),
mock.patch.dict(sys.modules, {"pandas_gbq": mock_pandas_gbq}),
mock.patch("google.cloud.bigquery.table._LOGGER.debug") as mock_log,

@sycai sycai Sep 2, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Shall we use caplog for log content testing? https://bigframes-internal-review.git.corp.google.com/c/bigframes/+/3680

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@shuoweil shuoweil Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Updated! Used caplog via a fixture marker to test the log content.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@shuoweil shuoweil Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Follow-up: caplog failed in full CI test runs because Google client libraries disable log propagation to the root logger (logging.getLogger("google").propagate = False). In this case, root-level log capture fixtures like caplog receive empty records.

I switched to self.assertLogs("google.cloud.bigquery.table", level="DEBUG"), which tests log content by attaching directly to the logger (no propagation needed and native to unittest.TestCase).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
shuoweil added 2 commits September 2, 2026 20:09
@shuoweil
test(bigquery): use caplog for telemetry failure log test
6dd30d8
@shuoweil
test(bigquery): use assertLogs for telemetry log test
54d444a
sycai
sycai approved these changes Sep 2, 2026
View reviewed changes
@shuoweil
shuoweil merged commit 85ddfe5 into main Sep 2, 2026
46 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@shuoweil
shuoweil deleted the shuowei-gbq-delegation-telemetry-mvp branch September 2, 2026 20:53
@release-please release-please Bot mentioned this pull request Sep 2, 2026
chore: release main #18221
Merged
noahdietz pushed a commit that referenced this pull request Sep 3, 2026
@release-please
chore: release main (#18221)
ad2ef26
🤖 I have created a release *beep* *boop*
---


<details><summary>django-google-spanner: 5.1.0</summary>

##
[5.1.0](django-google-spanner-v5.0.1...django-google-spanner-v5.1.0)
(2026-09-03)


### Features

* **django-google-spanner:** support Django 6.0
([#18128](#18128))
([207d947](207d947))
</details>

<details><summary>google-ads-admanager: 0.10.3</summary>

##
[0.10.3](google-ads-admanager-v0.10.2...google-ads-admanager-v0.10.3)
(2026-09-03)


### Features

* update googleapis and regenerate
([#18229](#18229))
([d4f8a57](d4f8a57))
</details>

<details><summary>google-api-core: 2.36.0</summary>

##
[2.36.0](google-api-core-v2.35.0...google-api-core-v2.36.0)
(2026-09-03)


### Features

* **api-core:** add ClientInterceptor and apply_interceptors helper (A)
([#18236](#18236))
([b6db5a9](b6db5a9))
* **api-core:** add tracer_provider to ClientOptions for OTel support
([#18139](#18139))
([9ffebc2](9ffebc2))


### Bug Fixes

* **api-core:** handle list-shaped REST error payloads
([#18232](#18232))
([02d1fd8](02d1fd8))
* **api-core:** move http encoding into transcode method
([#18218](#18218))
([082a99a](082a99a))
</details>

<details><summary>google-cloud-batch: 0.22.3</summary>

##
[0.22.3](google-cloud-batch-v0.22.2...google-cloud-batch-v0.22.3)
(2026-09-03)


### Features

* update API sources and regenerate
([#18267](#18267))
([813a5c1](813a5c1))
</details>

<details><summary>google-cloud-biglake-hive: 0.3.3</summary>

##
[0.3.3](google-cloud-biglake-hive-v0.3.2...google-cloud-biglake-hive-v0.3.3)
(2026-09-03)


### Features

* **google/cloud/biglake/hive/v1:** onboard a new library
([#18172](#18172))
([97668d8](97668d8))
</details>

<details><summary>google-cloud-bigquery: 3.45.0</summary>

##
[3.45.0](google-cloud-bigquery-v3.44.0...google-cloud-bigquery-v3.45.0)
(2026-09-03)


### Features

* add user-agent delegation telemetry for pandas-gbq
([#18184](#18184))
([85ddfe5](85ddfe5))
</details>

<details><summary>google-cloud-bigquery-migration: 0.15.1</summary>

##
[0.15.1](google-cloud-bigquery-migration-v0.15.0...google-cloud-bigquery-migration-v0.15.1)
(2026-09-03)


### Features

* update API sources and regenerate
([#18267](#18267))
([813a5c1](813a5c1))
</details>

<details><summary>google-cloud-bigquery-reservation: 1.27.0</summary>

##
[1.27.0](google-cloud-bigquery-reservation-v1.26.0...google-cloud-bigquery-reservation-v1.27.0)
(2026-09-03)


### Features

* update googleapis and regenerate
([#18229](#18229))
([d4f8a57](d4f8a57))
</details>

<details><summary>google-cloud-bigtable: 2.44.0</summary>

##
[2.44.0](google-cloud-bigtable-v2.43.0...google-cloud-bigtable-v2.44.0)
(2026-09-03)


### Features

* **bigtable:** Rerouted CheckAndMutateRows and ReadModifyWriteRows to
data client
([#18190](#18190))
([990f86e](990f86e))
* **bigtable:** Rerouted DirectRow.commit to use mutate_row
([#18191](#18191))
([7126a54](7126a54))
* update API sources and regenerate
([#18267](#18267))
([813a5c1](813a5c1))
</details>

<details><summary>google-cloud-compute: 1.52.0</summary>

##
[1.52.0](google-cloud-compute-v1.51.0...google-cloud-compute-v1.52.0)
(2026-09-03)


### Features

* update googleapis and regenerate
([#18229](#18229))
([d4f8a57](d4f8a57))
</details>

<details><summary>google-cloud-compute-v1beta: 0.12.3</summary>

##
[0.12.3](google-cloud-compute-v1beta-v0.12.2...google-cloud-compute-v1beta-v0.12.3)
(2026-09-03)


### Features

* update googleapis and regenerate
([#18229](#18229))
([d4f8a57](d4f8a57))
</details>

<details><summary>google-cloud-confidentialcomputing: 0.11.1</summary>

##
[0.11.1](google-cloud-confidentialcomputing-v0.11.0...google-cloud-confidentialcomputing-v0.11.1)
(2026-09-03)


### Features

* update API sources and regenerate
([#18267](#18267))
([813a5c1](813a5c1))
</details>

<details><summary>google-cloud-config: 0.7.1</summary>

##
[0.7.1](google-cloud-config-v0.7.0...google-cloud-config-v0.7.1)
(2026-09-03)


### Features

* update googleapis and regenerate
([#18229](#18229))
([d4f8a57](d4f8a57))
</details>

<details><summary>google-cloud-container: 2.66.0</summary>

##
[2.66.0](google-cloud-container-v2.65.0...google-cloud-container-v2.66.0)
(2026-09-03)


### Features

* update googleapis and regenerate
([#18229](#18229))
([d4f8a57](d4f8a57))
</details>

<details><summary>google-cloud-discoveryengine: 0.20.3</summary>

##
[0.20.3](google-cloud-discoveryengine-v0.20.2...google-cloud-discoveryengine-v0.20.3)
(2026-09-03)


### Features

* update googleapis and regenerate
([#18229](#18229))
([d4f8a57](d4f8a57))
</details>

<details><summary>google-cloud-dlp: 3.39.0</summary>

##
[3.39.0](google-cloud-dlp-v3.38.0...google-cloud-dlp-v3.39.0)
(2026-09-03)


### Features

* update API sources and regenerate
([#18267](#18267))
([813a5c1](813a5c1))
</details>

<details><summary>google-cloud-firestore: 2.30.0</summary>

##
[2.30.0](google-cloud-firestore-v2.29.0...google-cloud-firestore-v2.30.0)
(2026-09-03)


### Features

* **firestore:** configure gRPC message length limits for large
documents
([#18220](#18220))
([6e0f1d9](6e0f1d9))
</details>

<details><summary>google-cloud-geminidataanalytics: 0.13.2</summary>

##
[0.13.2](google-cloud-geminidataanalytics-v0.13.1...google-cloud-geminidataanalytics-v0.13.2)
(2026-09-03)


### Features

* update API sources and regenerate
([#18267](#18267))
([813a5c1](813a5c1))
</details>

<details><summary>google-cloud-pubsub: 2.40.0</summary>

##
[2.40.0](google-cloud-pubsub-v2.39.2...google-cloud-pubsub-v2.40.0)
(2026-09-03)


### Features

* update googleapis and regenerate
([#18229](#18229))
([d4f8a57](d4f8a57))
</details>

<details><summary>google-cloud-spanner: 3.71.0</summary>

##
[3.71.0](google-cloud-spanner-v3.70.0...google-cloud-spanner-v3.71.0)
(2026-09-03)


### Features

* add send and ack mutations Cloud Spanner Queues
([#17728](#17728))
([182ff9f](182ff9f)),
refs
[#17727](#17727)
</details>

<details><summary>google-cloud-storage-control: 1.15.0</summary>

##
[1.15.0](google-cloud-storage-control-v1.14.0...google-cloud-storage-control-v1.15.0)
(2026-09-03)


### Features

* update googleapis and regenerate
([#18229](#18229))
([d4f8a57](d4f8a57))
</details>

<details><summary>google-developer-knowledge: 0.1.2</summary>

##
[0.1.2](google-developer-knowledge-v0.1.1...google-developer-knowledge-v0.1.2)
(2026-09-03)


### Features

* update API sources and regenerate
([#18267](#18267))
([813a5c1](813a5c1))
* update googleapis and regenerate
([#18229](#18229))
([d4f8a57](d4f8a57))
</details>

<details><summary>google-maps-areainsights: 0.5.1</summary>

##
[0.5.1](google-maps-areainsights-v0.5.0...google-maps-areainsights-v0.5.1)
(2026-09-03)


### Features

* update googleapis and regenerate
([#18229](#18229))
([d4f8a57](d4f8a57))
</details>

<details><summary>google-maps-mapmanagement: 0.1.1</summary>

##
[0.1.1](google-maps-mapmanagement-v0.1.0...google-maps-mapmanagement-v0.1.1)
(2026-09-03)


### Features

* **google/maps/mapmanagement/v2:** onboard a new library
([#18173](#18173))
([f0f214b](f0f214b))
</details>

<details><summary>google-maps-routing: 0.11.1</summary>

##
[0.11.1](google-maps-routing-v0.11.0...google-maps-routing-v0.11.1)
(2026-09-03)


### Features

* update googleapis and regenerate
([#18229](#18229))
([d4f8a57](d4f8a57))
</details>

<details><summary>googleapis-common-protos: 1.75.3</summary>

##
[1.75.3](googleapis-common-protos-v1.75.2...googleapis-common-protos-v1.75.3)
(2026-09-03)


### Bug Fixes

* **googleapis-common-protos:** remove deprecated license classifier
([#18242](#18242))
([6f0216a](6f0216a)),
refs
[#18235](#18235)
</details>

<details><summary>sqlalchemy-spanner: 1.20.1</summary>

##
[1.20.1](sqlalchemy-spanner-v1.20.0...sqlalchemy-spanner-v1.20.1)
(2026-09-03)


### Bug Fixes

* **sqlalchemy-spanner:** robust session-isolated test databases and
clean lifecycle management
([#18179](#18179))
([3e0bda4](3e0bda4))


### Documentation

* **sqlalchemy-spanner:** centralize CONTRIBUTING.rst pointers
([#18142](#18142))
([f55ae02](f55ae02))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
@tswast tswast mentioned this pull request Sep 14, 2026
Revert "feat: add user-agent delegation telemetry for pandas-gbq" #18364
Merged
sycai pushed a commit that referenced this pull request Sep 14, 2026
@tswast
Revert "feat: add user-agent delegation telemetry for pandas-gbq" (#1…
7a5666b
…8364)

Reverts #18184

I don't think we should have approved
#18184 At best it
does nothing, as it's trying to mutate client_info, which really isn't
supposed to happen. At worst case it's flagging all subsequent BigQuery
client usage as belonging to pandas-gbq, which isn't really accurate. In
either case, it doesn't do anything to create a distinction between
pandas-gbq usage and google-cloud-bigquery to_dataframe() usage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@sycai sycai sycai approved these changes
@tswast tswast Awaiting requested review from tswast tswast is a code owner automatically assigned from googleapis/bigquery-dataframe-team
+1 more reviewer
@gemini-code-assist gemini-code-assist[bot] gemini-code-assist[bot] left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@shuoweil @sycai
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.