diff --git a/google/cloud/bigquery/opentelemetry_tracing.py b/google/cloud/bigquery/opentelemetry_tracing.py index b5f6bf991..5192fb807 100644 --- a/google/cloud/bigquery/opentelemetry_tracing.py +++ b/google/cloud/bigquery/opentelemetry_tracing.py @@ -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 + return job_attributes diff --git a/tests/unit/test_opentelemetry_tracing.py b/tests/unit/test_opentelemetry_tracing.py index 546cc02bd..c6117d240 100644 --- a/tests/unit/test_opentelemetry_tracing.py +++ b/tests/unit/test_opentelemetry_tracing.py @@ -42,7 +42,6 @@ TEST_SPAN_ATTRIBUTES = {"foo": "baz"} -@pytest.mark.skipif(opentelemetry is None, reason="Require `opentelemetry`") @pytest.fixture def setup(): importlib.reload(opentelemetry_tracing) @@ -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", @@ -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