Skip to content

Commit 38697fb

Browse files
authored
feat: adds billing to opentel (#1889)
1 parent 3634405 commit 38697fb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

google/cloud/bigquery/opentelemetry_tracing.py

+8
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,12 @@ def _set_job_attributes(job_ref):
153153
if job_ref.num_child_jobs is not None:
154154
job_attributes["num_child_jobs"] = job_ref.num_child_jobs
155155

156+
total_bytes_billed = getattr(job_ref, "total_bytes_billed", None)
157+
if total_bytes_billed is not None:
158+
job_attributes["total_bytes_billed"] = total_bytes_billed
159+
160+
total_bytes_processed = getattr(job_ref, "total_bytes_processed", None)
161+
if total_bytes_processed is not None:
162+
job_attributes["total_bytes_processed"] = total_bytes_processed
163+
156164
return job_attributes

tests/unit/test_opentelemetry_tracing.py

+6
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ def test_default_job_attributes(setup):
142142
"timeEnded": ended_time.isoformat(),
143143
"hasErrors": True,
144144
"state": "some_job_state",
145+
"total_bytes_billed": 42,
146+
"total_bytes_processed": 13,
145147
}
146148
with mock.patch("google.cloud.bigquery.job._AsyncJob") as test_job_ref:
147149
test_job_ref.job_id = "test_job_id"
@@ -154,6 +156,8 @@ def test_default_job_attributes(setup):
154156
test_job_ref.ended = ended_time
155157
test_job_ref.error_result = error_result
156158
test_job_ref.state = "some_job_state"
159+
test_job_ref.total_bytes_billed = 42
160+
test_job_ref.total_bytes_processed = 13
157161

158162
with opentelemetry_tracing.create_span(
159163
TEST_SPAN_NAME, attributes=TEST_SPAN_ATTRIBUTES, job_ref=test_job_ref
@@ -180,6 +184,8 @@ def test_optional_job_attributes(setup):
180184
test_job_ref.state = "some_job_state"
181185
test_job_ref.num_child_jobs = None
182186
test_job_ref.parent_job_id = None
187+
test_job_ref.total_bytes_billed = None
188+
test_job_ref.total_bytes_processed = None
183189

184190
with opentelemetry_tracing.create_span(
185191
TEST_SPAN_NAME, attributes=TEST_SPAN_ATTRIBUTES, job_ref=test_job_ref

0 commit comments

Comments
 (0)