GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: add updated span events + trace more methods by odeke-em · Pull Request #1259 · googleapis/python-spanner

This repository was archived by the owner on Jun 8, 2026. It is now read-only.

Conversation

@odeke-em

@odeke-em odeke-em commented Dec 6, 2024

Copy link
Copy Markdown
Contributor

This change carves out parts of PR #1241 in smaller pieces to ease with smaller reviews.
This change adds more span events, updates important spans to make them more distinct like changing:

"CloudSpanner.ReadWriteTransaction" to more direct and more pointed spans like:

  • CloudSpanner.Transaction.execute_streaming_sql

Also added important spans:

  • CloudSpanner.Database.run_in_transaction
  • CloudSpanner.Session.run_in_transaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@odeke-em
odeke-em requested review from a team December 6, 2024 15:03
@product-auto-label product-auto-label Bot added size: l Pull request size is large. api: spanner Issues related to the googleapis/python-spanner API. labels Dec 6, 2024
@blunderbuss-gcf blunderbuss-gcf Bot assigned olavloite Dec 6, 2024
@harshachinta harshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 6, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 6, 2024
@odeke-em
odeke-em force-pushed the trace-update-trace_call-with-db_name-retrieval branch 2 times, most recently from b0d9a6c to f437955 Compare December 7, 2024 03:09
@odeke-em

odeke-em commented Dec 7, 2024

Copy link
Copy Markdown
Contributor Author

@sakthivelmanii @harshachinta kindly help me run the bots. Thank you

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@harshachinta harshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 7, 2024
@harshachinta harshachinta assigned harshachinta and unassigned olavloite Dec 7, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 7, 2024
harshachinta
harshachinta reviewed Dec 9, 2024
View reviewed changes
Comment thread google/cloud/spanner_v1/_opentelemetry_tracing.py Outdated
yield None
return

if session:

@harshachinta harshachinta Dec 9, 2024

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@odeke-em
We should move this latest change of updating session last use time to beginning of this function, otherwise when opentlemetry is not installed then that update will never happen.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@harshachinta harshachinta Dec 10, 2024

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@odeke-em
this is not yet addresses.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@odeke-em odeke-em Dec 10, 2024

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed that @harshachinta as it is from the bigger PR and I don't think we shall need it anymore once some tests are sent in the other PR. I deleted it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@harshachinta harshachinta Dec 10, 2024

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not from your PR, this was added by us to handle one case. Don't remove that
I am talking about this code. We need this to know when was a session last used to avoid making a backend call to verify session existence.

    if session:
        session._last_use_time = datetime.now()

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/cloud/spanner_v1/_opentelemetry_tracing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/spanner_v1/_opentelemetry_tracing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/spanner_v1/_opentelemetry_tracing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/spanner_v1/batch.py Outdated
:param values: Values to be modified.
"""
self._mutations.append(Mutation(insert=_make_write_pb(table, columns, values)))
add_event_on_current_span(

@harshachinta harshachinta Dec 9, 2024

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this requirement was bought out when we met last time.
Thinking out loud.

Cloud spanner has a mutation limit of 40000 in one request.
So lets say a customer adds mutations in a loop, then this will print 40,000 events on the span.
Is this a good user experience? Also this could add up to the storage cost on customer end?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@odeke-em odeke-em Dec 10, 2024

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great question but it won't be a problem because:

  • spans have a default event limit of 128 https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#span-limits
  • storage costs not really as pricing on telemetry data is by span count rather than span data count unless perhps they have their own storage system but that's unlikely for those who'd be storing tens of thousands of span events

What we can do is perhaps document how to change span event limits and also document that we add events for span mutations.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@harshachinta harshachinta Dec 16, 2024

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sakthivelmanii
I’d like to get your thoughts on this.

In my opinion, adding a separate event for every mutation could clutter the trace spans with too many events. Instead, I’d suggest avoiding one event per mutation. We already track the num_mutations attribute in the Commit request (here), which effectively provides customers with insights into the number of mutations in a commit.

Let me know what you think.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/cloud/spanner_v1/session.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/spanner_v1/session.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/spanner_v1/session.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/spanner_v1/session.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/spanner_v1/session.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

harshachinta
harshachinta reviewed Dec 9, 2024
View reviewed changes
Comment thread google/cloud/spanner_v1/session.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

harshachinta
harshachinta reviewed Dec 9, 2024
View reviewed changes
Comment thread tests/_helpers.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/system/test_session_api.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/spanner_v1/snapshot.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/test_pool.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/test_pool.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/test_pool.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/test_pool.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/system/test_session_api.py Outdated
Comment on lines +797 to +802
"CloudSpanner.CreateSession",
"CloudSpanner.Transaction.execute_streaming_sql",
"CloudSpanner.Transaction.execute_streaming_sql",
"CloudSpanner.Transaction.commit",
"CloudSpanner.Session.run_in_transaction",
"CloudSpanner.Database.run_in_transaction",

@harshachinta harshachinta Dec 9, 2024

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some mistake in ordering here. Can you check?
Ideally the order should be,

        "CloudSpanner.Database.run_in_transaction",
        "CloudSpanner.CreateSession",
        "CloudSpanner.Session.run_in_transaction",
        "CloudSpanner.Transaction.execute_streaming_sql",
        "CloudSpanner.Transaction.execute_streaming_sql",
        "CloudSpanner.Transaction.commit",
        ```

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@odeke-em odeke-em Dec 10, 2024

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't a mistake though but rather the order in which spans are ended @harshachinta.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread tests/system/test_session_api.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/system/test_session_api.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@odeke-em
odeke-em force-pushed the trace-update-trace_call-with-db_name-retrieval branch 3 times, most recently from 992d6c9 to 6d6b30a Compare December 10, 2024 10:25
@harshachinta harshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 10, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 10, 2024
@odeke-em
odeke-em requested a review from harshachinta December 10, 2024 12:25
@odeke-em odeke-em changed the title observability: add updated span events + traace more methods observability: add updated span events + trace more methods Dec 16, 2024
harshachinta
harshachinta reviewed Dec 16, 2024
View reviewed changes
Comment thread google/cloud/spanner_v1/_opentelemetry_tracing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/spanner_v1/batch.py Outdated
:param values: Values to be modified.
"""
self._mutations.append(Mutation(insert=_make_write_pb(table, columns, values)))
add_event_on_current_span(

@harshachinta harshachinta Dec 16, 2024

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sakthivelmanii
I’d like to get your thoughts on this.

In my opinion, adding a separate event for every mutation could clutter the trace spans with too many events. Instead, I’d suggest avoiding one event per mutation. We already track the num_mutations attribute in the Commit request (here), which effectively provides customers with insights into the number of mutations in a commit.

Let me know what you think.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread tests/unit/test_pool.py
Comment on lines +364 to +380
"exception",
{
"exception.type": "IndexError",
"exception.message": "pop from empty list",
"exception.stacktrace": "EPHEMERAL",
"exception.escaped": "False",
},

@harshachinta harshachinta Dec 16, 2024

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there a repeation of exception event?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@odeke-em odeke-em Dec 16, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So given that we have a direct invocation of with trace_call("testBind") per

        try: 
            with trace_call("testBind", fauxSession):
                pool.bind(database)
        except Exception:
            pass 

that then invokes code internally where an exception happens. With the exception re-raised and unhandled until the highest parent, OpenTelemetry records the exception even on the parent. If we swallowed the exception internally we wouldn't

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread tests/system/test_observability_options.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@odeke-em
odeke-em force-pushed the trace-update-trace_call-with-db_name-retrieval branch 2 times, most recently from 20fe353 to a69a4dc Compare December 16, 2024 08:54
@harshachinta harshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 16, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 16, 2024
harshachinta
harshachinta approved these changes Dec 16, 2024
View reviewed changes
@harshachinta harshachinta changed the title observability: add updated span events + trace more methods feat: add updated span events + trace more methods Dec 16, 2024
@harshachinta harshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 16, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 16, 2024
odeke-em added 10 commits December 16, 2024 04:17
@odeke-em
observability: add updated span events + traace more methods
b238181
This change carves out parts of PR googleapis#1241 in smaller pieces to
ease with smaller reviews.
This change adds more span events, updates important spans
to make them more distinct like changing:

"CloudSpanner.ReadWriteTransaction" to more direct and more
pointed spans like:
* CloudSpanner.Transaction.execute_streaming_sql

Also added important spans:
* CloudSpanner.Database.run_in_transaction
* CloudSpanner.Session.run_in_transaction
@odeke-em
all: update review comments + show type for BeginTransaction + remove…
6e5f6bd
… prints
@odeke-em
Remove requested span event "Using Transaction"
e82367b
@odeke-em
Move attempts into try block
e920466
@odeke-em
Transform Session.run_in_transaction retry exceptions into events
02c084a
@odeke-em
More comprehensive test for events and attributes for pool.get
ae20acc
@odeke-em
Add test guards against Python3.7 for which OpenTelemetry is unavaila…
fa7d5e8
…ble + address test feedback
@odeke-em
Remove span event per mutation in favour of future TODO
5fa1c00
Referencing issue #1269, this update removes adding
a span event per mutation, in favour of a future TODO.
@odeke-em
Sort system-test.test_transaction_abort_then_retry_spans spans by cre…
ca50fc9
…ate time
@odeke-em
Delint tests
37594f7
@odeke-em
odeke-em force-pushed the trace-update-trace_call-with-db_name-retrieval branch from 5208f8e to 37594f7 Compare December 16, 2024 12:21
@harshachinta harshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 16, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 16, 2024
@harshachinta
harshachinta merged commit ad69c48 into googleapis:main Dec 17, 2024
@release-please release-please Bot mentioned this pull request Dec 17, 2024
chore(main): release 3.52.0 #1258
Merged
aakashanandg pushed a commit to aakashanandg/python-spanner that referenced this pull request Jan 2, 2025
@odeke-em @aakashanandg
feat: add updated span events + trace more methods (googleapis#1259)
b63b49e
* observability: add updated span events + traace more methods

This change carves out parts of PR googleapis#1241 in smaller pieces to
ease with smaller reviews.
This change adds more span events, updates important spans
to make them more distinct like changing:

"CloudSpanner.ReadWriteTransaction" to more direct and more
pointed spans like:
* CloudSpanner.Transaction.execute_streaming_sql

Also added important spans:
* CloudSpanner.Database.run_in_transaction
* CloudSpanner.Session.run_in_transaction

* all: update review comments + show type for BeginTransaction + remove prints

* Remove requested span event "Using Transaction"

* Move attempts into try block

* Transform Session.run_in_transaction retry exceptions into events

* More comprehensive test for events and attributes for pool.get

* Add test guards against Python3.7 for which OpenTelemetry is unavailable + address test feedback

* Remove span event per mutation in favour of future TODO

Referencing issue #1269, this update removes adding
a span event per mutation, in favour of a future TODO.

* Sort system-test.test_transaction_abort_then_retry_spans spans by create time

* Delint tests
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

1 more reviewer
@harshachinta harshachinta harshachinta approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@harshachinta harshachinta

Labels

api: spanner Issues related to the googleapis/python-spanner API. size: l Pull request size is large.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@odeke-em @harshachinta @olavloite @yoshi-kokoro
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.