fix(psycopg2): avoid IndexError in get_operation_name for comment/whitespace-only statements - #4942
Open
Atishyy27 wants to merge 3 commits into
Open
Conversation
Atishyy27
added a commit
to Atishyy27/opentelemetry-python-contrib
that referenced
this pull request
Aug 10, 2026
Signed-off-by: Atishyy27 <142108881+Atishyy27@users.noreply.github.com>
Pull request dashboard statusWaiting on maintainers · refreshed 2026-08-21 09:56 UTC Merge when ready. Status above doesn't look right?
|
xrmx
requested changes
Aug 17, 2026
Atishyy27
added a commit
to Atishyy27/opentelemetry-python-contrib
that referenced
this pull request
Aug 17, 2026
…only statements Per xrmx's review on open-telemetry#4942: the regression test only checked that a comment-only or whitespace-only statement produces spans without crashing, not what those spans are actually named. Asserts the fallback ('postgresql', the db vendor, per this test's MockConnection fixture) instead of just span count.
…tespace-only statements A statement that is truthy but has no tokens after leading-comment or whitespace stripping made .split()[0] raise IndexError in the psycopg2 instrumentation's get_operation_name override. Guard it like the dbapi base does. Adds a regression test. Follow-up to open-telemetry#4934. Signed-off-by: Atishyy27 <142108881+Atishyy27@users.noreply.github.com>
Signed-off-by: Atishyy27 <142108881+Atishyy27@users.noreply.github.com>
…only statements Per xrmx's review on open-telemetry#4942: the regression test only checked that a comment-only or whitespace-only statement produces spans without crashing, not what those spans are actually named. Asserts the fallback ('postgresql', the db vendor, per this test's MockConnection fixture) instead of just span count.
Atishyy27
force-pushed
the
fix/psycopg2-operation-name-empty-tokens
branch
from
August 20, 2026 23:57
f6e0667 to
13471a3
Compare
xrmx
approved these changes
Aug 21, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Same class as #4934, in the psycopg2 instrumentation's
get_operation_name: a comment-only / whitespace-only statement is truthy but has no tokens after leading-comment stripping, so.split()[0]raisesIndexError. Guards it like the dbapi base does. Extends the empty-string handling from #2643 to this case.Type of change: Bug fix (non-breaking)
How Has This Been Tested? Added
test_span_name_comment_or_whitespace_only(comment-only + whitespace-only statements no longer raise); existing tests still pass. Verified locally.Does This PR Require a Core Repo Change? No.