Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit bb081d0

Browse files
committed
moved contextvar into ActiveOperationMetric
1 parent 199a162 commit bb081d0

3 files changed

Lines changed: 4 additions & 7 deletions

File tree

google/cloud/bigtable/data/_async/metrics_interceptor.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ class AsyncBigtableMetricsInterceptor(
9696
An async gRPC interceptor to add client metadata and print server metadata.
9797
"""
9898

99-
_routing_cookie_context: ClassVar[
100-
contextvars.ContextVar[dict[str, str|bytes]]
101-
] = contextvars.ContextVar("routing_cooke_context")
102-
103-
10499
@CrossSync.convert
105100
@_with_active_operation
106101
async def intercept_unary_unary(
@@ -136,7 +131,7 @@ async def intercept_unary_stream(
136131
- SampleRowKeys
137132
"""
138133
try:
139-
for k,v in self._routing_cookie_context.get({}).items():
134+
for k,v in operation.routing_cookie.items():
140135
client_call_details.metadata.add(k, v)
141136
return self._streaming_generator_wrapper(
142137
operation, await continuation(client_call_details, request)

google/cloud/bigtable/data/_metrics/data_model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ class ActiveOperationMetric:
172172
first_response_latency_ns: int | None = None
173173
# time waiting on flow control, in nanoseconds
174174
flow_throttling_time_ns: int = 0
175+
# routing cookie, passed in between retry attempts
176+
routing_cookie: dict[str, str|bytes] = field(default_factory=dict)
175177

176178
_active_operation_context: ClassVar[
177179
contextvars.ContextVar[ActiveOperationMetric]

google/cloud/bigtable/data/_metrics/tracked_retry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def wrapper(exc: Exception) -> None:
6464
# check for routing cookie:
6565
cookie_headers = {k:v for k,v in metadata_dict.items() if k.startswith("x-goog-cbt-cookie")}
6666
if cookie_headers:
67-
AsyncBigtableMetricsInterceptor._routing_cookie_context.set(cookie_headers)
67+
operation.routing_cookie = cookie_headers
6868
except Exception:
6969
# ignore errors in metadata collection
7070
pass

0 commit comments

Comments
 (0)