Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
odeke-em committed Nov 20, 2024
1 parent 0c9bff3 commit 8d613ee
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion google/cloud/spanner_v1/_opentelemetry_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions google/cloud/spanner_v1/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
7 changes: 2 additions & 5 deletions tests/system/test_session_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 8d613ee

Please sign in to comment.