Skip to content

Add ability to set custom User Agent #1082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
travischambers opened this issue Jun 6, 2024 · 1 comment · Fixed by #1100
Closed

Add ability to set custom User Agent #1082

travischambers opened this issue Jun 6, 2024 · 1 comment · Fixed by #1100
Labels
api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API.

Comments

@travischambers
Copy link

travischambers commented Jun 6, 2024

Is your feature request related to a problem? Please describe.
The Google Cloud Ready - BigQuery partnership program requires partners to set a custom UserAgent. This is so Google can correctly attribute usage. However, there is no built in way to set the UserAgent in this library. It's hardcoded to sqlalchemy right now.

def google_client_info():
user_agent = USER_AGENT_TEMPLATE.format(sqlalchemy.__version__)
return client_info.ClientInfo(user_agent=user_agent)
def create_bigquery_client(
credentials_info=None,
credentials_path=None,
credentials_base64=None,
default_query_job_config=None,
location=None,
project_id=None,
):
default_project = None
if credentials_base64:
credentials_info = json.loads(base64.b64decode(credentials_base64))
if credentials_path:
credentials = service_account.Credentials.from_service_account_file(
credentials_path
)
credentials = credentials.with_scopes(SCOPES)
default_project = credentials.project_id
elif credentials_info:
credentials = service_account.Credentials.from_service_account_info(
credentials_info
)
credentials = credentials.with_scopes(SCOPES)
default_project = credentials.project_id
else:
credentials, default_project = google.auth.default(scopes=SCOPES)
if project_id is None:
project_id = default_project
return bigquery.Client(
client_info=google_client_info(),
project=project_id,
credentials=credentials,
location=location,
default_query_job_config=default_query_job_config,
)

Describe the solution you'd like
The create_bigquery_engine method should also accept a user_agent and use that instead of the default sqlalchemy user_agent, if provided.

For now, as a workaround in my code, I'm reimplementing the create_bigquery_engine method myself and setting the client_info directly.

@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API. label Jun 6, 2024
@chalmerlowe
Copy link
Collaborator

@travischambers

This feature should work now. Let me know if you find any problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants