This repository was archived by the owner on Apr 1, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
google/cloud/bigtable/data Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616from typing import Sequence
1717
1818import time
19+ import contextvars
1920from functools import wraps
2021
2122from google .cloud .bigtable .data ._metrics .data_model import ActiveOperationMetric
@@ -95,6 +96,11 @@ class AsyncBigtableMetricsInterceptor(
9596 An async gRPC interceptor to add client metadata and print server metadata.
9697 """
9798
99+ _routing_cookie_context : ClassVar [
100+ contextvars .ContextVar [dict [str , str | bytes ]]
101+ ] = contextvars .ContextVar ("routing_cooke_context" )
102+
103+
98104 @CrossSync .convert
99105 @_with_active_operation
100106 async def intercept_unary_unary (
@@ -130,6 +136,8 @@ async def intercept_unary_stream(
130136 - SampleRowKeys
131137 """
132138 try :
139+ for k ,v in self ._routing_cookie_context .get ({}).items ():
140+ client_call_details .metadata .add (k , v )
133141 return self ._streaming_generator_wrapper (
134142 operation , await continuation (client_call_details , request )
135143 )
Original file line number Diff line number Diff line change 3030from google .cloud .bigtable .data ._helpers import _retry_exception_factory
3131from google .cloud .bigtable .data ._metrics import ActiveOperationMetric
3232from google .cloud .bigtable .data ._metrics import OperationState
33+ from google .cloud .bigtable .data ._async .metrics_interceptor import AsyncBigtableMetricsInterceptor
3334
3435
3536T = TypeVar ("T" )
@@ -58,7 +59,12 @@ def wrapper(exc: Exception) -> None:
5859 metadata = list (rpc_error .trailing_metadata ()) + list (
5960 rpc_error .initial_metadata ()
6061 )
61- operation .add_response_metadata ({k : v for k , v in metadata })
62+ metadata_dict = {k : v for k , v in metadata }
63+ operation .add_response_metadata (metadata_dict )
64+ # check for routing cookie:
65+ cookie_headers = {k :v for k ,v in metadata_dict .items () if k .startswith ("x-goog-cbt-cookie" )}
66+ if cookie_headers :
67+ AsyncBigtableMetricsInterceptor ._routing_cookie_context .set (cookie_headers )
6268 except Exception :
6369 # ignore errors in metadata collection
6470 pass
You can’t perform that action at this time.
0 commit comments