-
Notifications
You must be signed in to change notification settings - Fork 805
Fix tracing of async cursors for psycopg #3324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
dbd1d23 to
ecea87a
Compare
|
@federicobond would love a review when you get a chance! |
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've validated that this indeed solves the problem. Only concern here is minor; The override of traced_execution changes the signature from sync to async, effectively also changing the return type. Another option is to extend CursorTracer with a traced_execution_async method, keeping it all in one class, but supporting both.
But as I said this works ✅
This copies the traced_execution of AsyncCursorTracer except query_method is awaited within the span. Fixes open-telemetry#2486
ecea87a to
71f50a7
Compare
Thanks for testing. Not sure I follow the return type concern, AFAIU the users of that |
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 think we are missing tests to avoid regressions in the future
|
@xrmx sorry for the delay here -- added a regression test. Please let me know if there's a better way to assert this behavior. |
instrumentation/opentelemetry-instrumentation-psycopg/tests/test_psycopg_integration.py
Show resolved
Hide resolved
.../opentelemetry-instrumentation-psycopg/src/opentelemetry/instrumentation/psycopg/__init__.py
Outdated
Show resolved
Hide resolved
|
@jwilm not ideal but I did publish the patched version to github, in our requirements.txt we use: |
Adds a test to check that the async tracer is actually awaiting cursor.execute. On my machine, with the bug present, the duration is 14000ns. With the bug patched the the duration is orders of magnitude larger.
2fcd49d to
0d8cd74
Compare
|
@xrmx fixed the formatting issue -- any chance this can get reviewed / merged? |
.../opentelemetry-instrumentation-psycopg/src/opentelemetry/instrumentation/psycopg/__init__.py
Outdated
Show resolved
Hide resolved
When you subclass, you need to maintain the method's signature (Liskov Substitution Principle). |
.../opentelemetry-instrumentation-psycopg/src/opentelemetry/instrumentation/psycopg/__init__.py
Outdated
Show resolved
Hide resolved
|
Thanks for using Logfire! ❤️ |
Description
This copies the traced_execution of AsyncCursorTracer except query_method is awaited within the span.
Fixes #2486
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
I ran this locally by making the corresponding changes in my site-packages folder. Then I checked logfire (what we're using for opentelemetry) to confirm that sql queries now had non-zero timings.
Also ran the
toxcommand to run tests.Happy to build and test the built package if you tell me how to build!
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.