diff --git a/dbt-bigquery/.changes/unreleased/Features-20250904-153341.yaml b/dbt-bigquery/.changes/unreleased/Features-20250904-153341.yaml new file mode 100644 index 000000000..753e5d48b --- /dev/null +++ b/dbt-bigquery/.changes/unreleased/Features-20250904-153341.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Inject invocation_id into user agent string +time: 2025-09-04T15:33:41.438521+12:00 +custom: + Author: jeremyyeo + Issue: "1280" diff --git a/dbt-bigquery/src/dbt/adapters/bigquery/clients.py b/dbt-bigquery/src/dbt/adapters/bigquery/clients.py index f151e87eb..2c52f64a0 100644 --- a/dbt-bigquery/src/dbt/adapters/bigquery/clients.py +++ b/dbt-bigquery/src/dbt/adapters/bigquery/clients.py @@ -9,6 +9,7 @@ from google.cloud.storage import Client as StorageClient from google.cloud.storage.retry import DEFAULT_RETRY as GCS_DEFAULT_RETRY from google.oauth2.credentials import Credentials as GoogleCredentials +from dbt_common.invocation import get_invocation_id from dbt.adapters.events.logging import AdapterLogger @@ -64,7 +65,9 @@ def _create_bigquery_client(credentials: BigQueryCredentials) -> BigQueryClient: credentials.execution_project, create_google_credentials(credentials), location=getattr(credentials, "location", None), - client_info=ClientInfo(user_agent=f"dbt-bigquery-{dbt_version.version}"), + client_info=ClientInfo( + user_agent=f"dbt-bigquery-{dbt_version.version} dbt-invocation-id/{get_invocation_id()}" + ), client_options=ClientOptions( quota_project_id=credentials.quota_project, api_endpoint=credentials.api_endpoint ), diff --git a/dbt-bigquery/tests/unit/test_bigquery_adapter.py b/dbt-bigquery/tests/unit/test_bigquery_adapter.py index 5edcb9416..fb89633e8 100644 --- a/dbt-bigquery/tests/unit/test_bigquery_adapter.py +++ b/dbt-bigquery/tests/unit/test_bigquery_adapter.py @@ -24,6 +24,7 @@ from dbt.contracts.files import FileHash from dbt.contracts.graph.manifest import ManifestStateCheck from dbt.context.providers import RuntimeConfigObject, generate_runtime_macro_context +from dbt_common.invocation import get_invocation_id from google.cloud.bigquery import AccessEntry @@ -471,7 +472,9 @@ def test_api_endpoint_settable(self, MockClient, mock_auth_default, MockClientOp class HasUserAgent: - PAT = re.compile(r"dbt-bigquery-\d+\.\d+\.\d+((a|b|rc)\d+)?") + PAT = re.compile( + r"dbt-bigquery-\d+\.\d+\.\d+((a|b|rc)\d+)? dbt-invocation-id/" + get_invocation_id() + ) def __eq__(self, other): compare = getattr(other, "user_agent", "")