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

Commit 8179f97

Browse files
committed
fixed metric export
1 parent 011fd84 commit 8179f97

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,6 @@ def __init__(
214214
credentials = google.auth.credentials.AnonymousCredentials()
215215
if project is None:
216216
project = _DEFAULT_BIGTABLE_EMULATOR_CLIENT
217-
# create a metrics exporter using the same client configuration
218-
self._gcp_metrics_exporter = BigtableMetricsExporter(
219-
project_id=project,
220-
credentials=credentials,
221-
client_options=client_options,
222-
)
223217
self._metrics_interceptor = MetricInterceptorType()
224218
# initialize client
225219
ClientWithProject.__init__(
@@ -250,6 +244,12 @@ def __init__(
250244
"configured the universe domain explicitly, `googleapis.com` "
251245
"is the default."
252246
)
247+
# create a metrics exporter using the same client configuration
248+
self._gcp_metrics_exporter = BigtableMetricsExporter(
249+
project_id=self.project,
250+
credentials=credentials,
251+
client_options=client_options,
252+
)
253253
self._is_closed = CrossSync.Event()
254254
self.transport = cast(TransportType, self._gapic_client.transport)
255255
# keep track of active instances to for warmup on channel refresh

google/cloud/bigtable/data/_metrics/handlers/opentelemetry.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,15 @@ def on_operation_complete(self, op: CompletedOperationMetric) -> None:
175175
is_streaming = str(op.is_streaming)
176176

177177
self.otel.operation_latencies.record(
178-
op.duration_ms, {"streaming": is_streaming, **labels}
178+
op.duration_ns / 1e6, {"streaming": is_streaming, **labels}
179179
)
180+
if (
181+
op.op_type == OperationType.READ_ROWS
182+
and op.first_response_latency_ns is not None
183+
):
184+
self.otel.first_response_latencies.record(
185+
op.first_response_latency_ns / 1e6, labels
186+
)
180187
# only record completed attempts if there were retries
181188
if op.completed_attempts:
182189
self.otel.retry_count.add(len(op.completed_attempts) - 1, labels)
@@ -203,26 +210,19 @@ def on_attempt_complete(
203210
is_streaming = str(op.is_streaming)
204211

205212
self.otel.attempt_latencies.record(
206-
attempt.duration_ms, {"streaming": is_streaming, "status": status, **labels}
213+
attempt.duration_ns, {"streaming": is_streaming, "status": status, **labels}
207214
)
208-
combined_throttling = attempt.grpc_throttling_time_ms
215+
combined_throttling = attempt.grpc_throttling_time_ns / 1e6
209216
if not op.completed_attempts:
210217
# add flow control latency to first attempt's throttling latency
211-
combined_throttling += op.flow_throttling_time_ms
218+
combined_throttling += (op.flow_throttling_time_ns / 1e6 if op.flow_throttling_time_ns else 0)
212219
self.otel.throttling_latencies.record(combined_throttling, labels)
213220
self.otel.application_latencies.record(
214-
attempt.application_blocking_time_ms + attempt.backoff_before_attempt_ms, labels
221+
(attempt.application_blocking_time_ns + attempt.backoff_before_attempt_ns) / 1e6, labels
215222
)
216-
if (
217-
op.op_type == OperationType.READ_ROWS
218-
and attempt.first_response_latency_ms is not None
219-
):
220-
self.otel.first_response_latencies.record(
221-
attempt.first_response_latency_ms, {"status": status, **labels}
222-
)
223-
if attempt.gfe_latency_ms is not None:
223+
if attempt.gfe_latency_ns is not None:
224224
self.otel.server_latencies.record(
225-
attempt.gfe_latency_ms,
225+
attempt.gfe_latency_ns / 1e6,
226226
{"streaming": is_streaming, "status": status, **labels},
227227
)
228228
else:

0 commit comments

Comments
 (0)