Skip to content
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

set db.query.text OpenTelemetry attribute #2061

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions google/cloud/bigquery/opentelemetry_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,8 @@ def _set_job_attributes(job_ref):
if total_bytes_processed is not None:
job_attributes["total_bytes_processed"] = total_bytes_processed

query = getattr(job_ref, "query", None)
if query is not None:
job_attributes["db.query.text"] = query
Comment on lines +164 to +166
Copy link
Author

Choose a reason for hiding this comment

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

"query" is only available when the job is a QueryJob.


return job_attributes
3 changes: 2 additions & 1 deletion tests/unit/test_opentelemetry_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
TEST_SPAN_ATTRIBUTES = {"foo": "baz"}


@pytest.mark.skipif(opentelemetry is None, reason="Require `opentelemetry`")
Copy link
Author

Choose a reason for hiding this comment

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

It's not possible to add marks to fixtures, this was wrong.

@pytest.fixture
def setup():
importlib.reload(opentelemetry_tracing)
Expand Down Expand Up @@ -132,6 +131,7 @@ def test_default_job_attributes(setup):
expected_attributes = {
"db.system": "BigQuery",
"db.name": "test_project_id",
"db.query.text": "SELECT 1",
"location": "test_location",
"num_child_jobs": "0",
"job_id": "test_job_id",
Expand All @@ -149,6 +149,7 @@ def test_default_job_attributes(setup):
test_job_ref.job_id = "test_job_id"
test_job_ref.location = "test_location"
test_job_ref.project = "test_project_id"
test_job_ref.query = "SELECT 1"
test_job_ref.num_child_jobs = "0"
test_job_ref.parent_job_id = "parent_job_id"
test_job_ref.created = time_created
Expand Down