FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

observability: annotate Session+SessionPool events by odeke-em · Pull Request #1207 · googleapis/python-spanner · GitHub

This repository was archived by the owner on Jun 8, 2026. It is now read-only.
/ python-spanner Public archive

observability: annotate Session+SessionPool events - #1207

Merged
harshachinta merged 1 commit into
googleapis:mainfrom
odeke-em:trace-annotation-SessionPools
Dec 6, 2024
Merged

observability: annotate Session+SessionPool events#1207
harshachinta merged 1 commit into
googleapis:mainfrom
odeke-em:trace-annotation-SessionPools

Conversation

odeke-em commented Sep 19, 2024
edited by harshachinta
Loading

Copy link
Copy Markdown
Contributor

This change adds annotations for session and session pool events to aid customers in debugging latency issues with session pool malevolence and also for maintainers to figure out which session pool type is the most appropriate.

Updates #1170

BEGIN_COMMIT_OVERRIDE
feat: add additional opentelemetry span events for session pool
END_COMMIT_OVERRIDE

odeke-em requested review from a team September 19, 2024 03:48
product-auto-label Bot added the size: m Pull request size is medium. label Sep 19, 2024
product-auto-label Bot added the api: spanner Issues related to the googleapis/python-spanner API. label Sep 19, 2024
odeke-em force-pushed the trace-annotation-SessionPools branch 3 times, most recently from 8d6f2b7 to 4bc937e Compare September 19, 2024 07:37

Copy link
Copy Markdown
Contributor Author

Exhibit

On running examples/grpc_instrumentation_enabled.py we get back these traces



Copy link
Copy Markdown
Contributor Author

cc @harshachinta

odeke-em force-pushed the trace-annotation-SessionPools branch from 4bc937e to 0d5bf26 Compare September 19, 2024 07:45
harshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 19, 2024
yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 19, 2024
odeke-em force-pushed the trace-annotation-SessionPools branch from 0d5bf26 to 3617921 Compare September 19, 2024 13:43
harshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 19, 2024
yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 19, 2024
odeke-em force-pushed the trace-annotation-SessionPools branch 2 times, most recently from f71d05c to eb9dd5a Compare September 20, 2024 01:27
harshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 20, 2024
yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 20, 2024
odeke-em force-pushed the trace-annotation-SessionPools branch from b1ea772 to ab23f09 Compare September 20, 2024 22:09

Copy link
Copy Markdown
Contributor Author

Kindly cc-ing you @harshachinta.

harshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 23, 2024
yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 23, 2024
Comment thread google/cloud/spanner_v1/pool.py Outdated
Comment thread google/cloud/spanner_v1/pool.py Outdated
Comment thread google/cloud/spanner_v1/pool.py Outdated
Comment thread google/cloud/spanner_v1/pool.py Outdated
Comment thread google/cloud/spanner_v1/session.py Outdated
Comment thread google/cloud/spanner_v1/session.py Outdated
Comment thread google/cloud/spanner_v1/session.py Outdated
odeke-em requested a review from harshachinta October 7, 2024 02:36

odeke-em commented Oct 7, 2024

Copy link
Copy Markdown
Contributor Author

Kindly please take another look @harshachinta, feedback addressed, thank you for the code review!

Comment thread google/cloud/spanner_v1/pool.py Outdated
Comment thread google/cloud/spanner_v1/pool.py Outdated
)

if requested_session_count > 0:
current_span.add_event(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

current_span is not initialized.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sheesh, sorry I had a bunch of benchmarks running locally and they interrupted my nox -s unit-3.8 tests so didn't see those but all fixed now.

odeke-em force-pushed the trace-annotation-SessionPools branch from e60b662 to 3a1611e Compare November 27, 2024 04:08
Comment thread google/cloud/spanner_v1/session.py Outdated
Comment thread google/cloud/spanner_v1/transaction.py Outdated
Comment on lines +286 to +287
if self._transaction_id is None and len(self._mutations) > 0:
self.begin()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
if self._transaction_id is None and len(self._mutations) > 0:
self.begin()

Why is this added here? This is already getting executed in the beginning of commit() call, so not needed

if self._transaction_id is None and len(self._mutations) > 0:

Comment thread google/cloud/spanner_v1/pool.py Outdated
)
session = self._sessions.get(block=True, timeout=timeout)
except queue.Empty as e:
add_span_event(current_span, "No session available", span_event_attributes)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
add_span_event(current_span, "No session available", span_event_attributes)
add_span_event(current_span, "No session available in the pool", span_event_attributes)

Comment thread google/cloud/spanner_v1/pool.py Outdated
Comment thread tests/unit/test_pool.py Outdated
Comment on lines +261 to +262
"exception",
"exception",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

why are there 2 exception events?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It is a quirk with opentelemetry-python; they add "exception" on every exit call whether or not you set your own, I'll file a bug later on but for now I'll just remove our explicit invocation of "span.record_exception" and instead add our comment.

Comment thread tests/unit/test_pool.py
Comment thread tests/unit/test_pool.py
Comment thread tests/unit/test_pool.py
Comment thread tests/unit/test_pool.py Outdated
harshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 28, 2024
yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 28, 2024

Copy link
Copy Markdown
Contributor Author

Thank you @harshachinta for the review, I've addressed the feedback. Please take a look again.

odeke-em force-pushed the trace-annotation-SessionPools branch from b6187d8 to e654029 Compare November 28, 2024 14:26
harshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 28, 2024
yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 28, 2024

Copy link
Copy Markdown
Contributor Author

@harshachinta kindly help me run the bots.

harshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 29, 2024
yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 29, 2024

harshachinta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please fix lint

yield span
except Exception as error:
span.set_status(Status(StatusCode.ERROR, str(error)))
span.record_exception(error)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Lets not remove this exception. We are not sure if there are any cases where the span will end up not recording an exception.
I would suggest adding this back here and let us discuss more during our demo.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Also I was wondering that this behavior of exception getting added twice was not seen earlier since this code exists from very long.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It's because OpenTelemetry was upgraded only recently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We do have locked tests to check for the exceptions to ensure that they are in there and from Span.enter. I had to dive back into OpenTelemetry-Python's code as it isn't even documented and in our demos it was very distracting to have mysteriously both errors. I think for the sake of our sanity and project stability let's leave that comment in and if anything happens it is a trivial one to add back @harshachinta

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hmm. But the opentelemetry documentation for Python guides to record exception for instrumentation libraries.
https://opentelemetry.io/docs/languages/python/instrumentation/#record-exceptions-in-spans

Can you share the code pointer on where the opentelemetry records exception by default when exiting?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@harshachinta it was the cause of us seeing 2 exceptions and took a ton of confusion and time for me to debug, they don't seem to document this condition.

harshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 2, 2024
yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 2, 2024
Comment thread tests/unit/test_pool.py

odeke-em commented Dec 2, 2024

Copy link
Copy Markdown
Contributor Author

@harshachinta kindly help me re-run the bots; all unit tests pass locally.

sakthivelmanii added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 2, 2024
yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 2, 2024
odeke-em force-pushed the trace-annotation-SessionPools branch from 498a70a to 060d17c Compare December 3, 2024 10:04
harshachinta added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 3, 2024
yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 3, 2024
odeke-em force-pushed the trace-annotation-SessionPools branch from 060d17c to b400718 Compare December 5, 2024 10:31
sakthivelmanii added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 5, 2024
yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 5, 2024
This change adds annotations for session and session pool
events to aid customers in debugging latency issues with
session pool malevolence and also for maintainers to
figure out which session pool type is the most appropriate.

Updates googleapis#1170
odeke-em force-pushed the trace-annotation-SessionPools branch from b400718 to 1d7e440 Compare December 6, 2024 07:54
rahul2393 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 6, 2024
yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 6, 2024
harshachinta merged commit a6811af into googleapis:main Dec 6, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants


Back | FazBrowse Home | New Git URL