From 8d613ee5fe9c42eda2a96fa7a9f9abfc097b74dd Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Wed, 20 Nov 2024 04:00:15 -0800 Subject: [PATCH] fix tests --- google/cloud/spanner_v1/_opentelemetry_tracing.py | 2 +- google/cloud/spanner_v1/session.py | 7 ++++--- tests/system/test_session_api.py | 7 ++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/google/cloud/spanner_v1/_opentelemetry_tracing.py b/google/cloud/spanner_v1/_opentelemetry_tracing.py index 3b6ddebd3c..f134a7ab9a 100644 --- a/google/cloud/spanner_v1/_opentelemetry_tracing.py +++ b/google/cloud/spanner_v1/_opentelemetry_tracing.py @@ -77,7 +77,7 @@ def trace_call(name, session, extra_attributes=None, observability_options=None) enable_extended_tracing = observability_options.get( "enable_extended_tracing", enable_extended_tracing ) - db_name = observability_options.get("db_name", db_name) + db_name = observability_options["db_name"] tracer = get_tracer(tracer_provider) diff --git a/google/cloud/spanner_v1/session.py b/google/cloud/spanner_v1/session.py index 31792b141f..71b36619a7 100644 --- a/google/cloud/spanner_v1/session.py +++ b/google/cloud/spanner_v1/session.py @@ -439,7 +439,8 @@ def run_in_transaction(self, func, *args, **kw): attempts += 1 - span_attributes = {"transaction.id": txn.id, "attempt": attempts} + txn_id = getattr(txn, "_transaction_id", None) or "" + span_attributes = {"transaction.id": txn_id, "attempt": attempts} if span: span.add_event("Using Transaction", span_attributes) @@ -448,7 +449,7 @@ def run_in_transaction(self, func, *args, **kw): except Aborted as exc: del self._transaction if span: - delay_seconds = _get_retry_delay(exc, attempts) + delay_seconds = _get_retry_delay(exc.errors[0], attempts) attributes = dict(delay_seconds=delay_seconds) attributes.update(span_attributes) span.add_event("Transaction was aborted, retrying", attributes) @@ -481,7 +482,7 @@ def run_in_transaction(self, func, *args, **kw): except Aborted as exc: del self._transaction if span: - delay_seconds = _get_retry_delay(exc, attempts) + delay_seconds = _get_retry_delay(exc.errors[0], attempts) attributes = dict(delay_seconds=delay_seconds) attributes.update(span_attributes) span.add_event( diff --git a/tests/system/test_session_api.py b/tests/system/test_session_api.py index 599144e230..0a578f200a 100644 --- a/tests/system/test_session_api.py +++ b/tests/system/test_session_api.py @@ -1194,11 +1194,8 @@ def unit_of_work(transaction): ] assert [span.name for span in span_list] == expected_span_names for span in span_list[2:-2]: - assert ( - span.get_span_context().trace_id - == span_list[-1].get_span_context().trace_id - ) - assert span.parent.span_id == span_list[-2].get_span_context().span_id + assert span.context.trace_id == span_list[-2].context.trace_id + assert span.parent.span_id == span_list[-2].context.span_id def test_execute_partitioned_dml(