Skip to content

Commit 8d613ee

Browse files
committed
fix tests
1 parent 0c9bff3 commit 8d613ee

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

google/cloud/spanner_v1/_opentelemetry_tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def trace_call(name, session, extra_attributes=None, observability_options=None)
7777
enable_extended_tracing = observability_options.get(
7878
"enable_extended_tracing", enable_extended_tracing
7979
)
80-
db_name = observability_options.get("db_name", db_name)
80+
db_name = observability_options["db_name"]
8181

8282
tracer = get_tracer(tracer_provider)
8383

google/cloud/spanner_v1/session.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ def run_in_transaction(self, func, *args, **kw):
439439

440440
attempts += 1
441441

442-
span_attributes = {"transaction.id": txn.id, "attempt": attempts}
442+
txn_id = getattr(txn, "_transaction_id", None) or ""
443+
span_attributes = {"transaction.id": txn_id, "attempt": attempts}
443444
if span:
444445
span.add_event("Using Transaction", span_attributes)
445446

@@ -448,7 +449,7 @@ def run_in_transaction(self, func, *args, **kw):
448449
except Aborted as exc:
449450
del self._transaction
450451
if span:
451-
delay_seconds = _get_retry_delay(exc, attempts)
452+
delay_seconds = _get_retry_delay(exc.errors[0], attempts)
452453
attributes = dict(delay_seconds=delay_seconds)
453454
attributes.update(span_attributes)
454455
span.add_event("Transaction was aborted, retrying", attributes)
@@ -481,7 +482,7 @@ def run_in_transaction(self, func, *args, **kw):
481482
except Aborted as exc:
482483
del self._transaction
483484
if span:
484-
delay_seconds = _get_retry_delay(exc, attempts)
485+
delay_seconds = _get_retry_delay(exc.errors[0], attempts)
485486
attributes = dict(delay_seconds=delay_seconds)
486487
attributes.update(span_attributes)
487488
span.add_event(

tests/system/test_session_api.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,11 +1194,8 @@ def unit_of_work(transaction):
11941194
]
11951195
assert [span.name for span in span_list] == expected_span_names
11961196
for span in span_list[2:-2]:
1197-
assert (
1198-
span.get_span_context().trace_id
1199-
== span_list[-1].get_span_context().trace_id
1200-
)
1201-
assert span.parent.span_id == span_list[-2].get_span_context().span_id
1197+
assert span.context.trace_id == span_list[-2].context.trace_id
1198+
assert span.parent.span_id == span_list[-2].context.span_id
12021199

12031200

12041201
def test_execute_partitioned_dml(

0 commit comments

Comments
 (0)