fix(psycopg): avoid IndexError in get_operation_name for comment/whitespace-only statements - #4936
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 8, 2026
Signed-off-by: Atishyy27 <142108881+Atishyy27@users.noreply.github.com>
6 tasks
Pull request dashboard statusWaiting on the author · refreshed 2026-08-27 19:18 UTC Investigate required status check failures. 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
Per xrmx's review on open-telemetry#4936: the regression test only checked that a comment-only Composed statement produces a span without crashing, not what that span is actually named. Asserts the observed fallback (empty string - instrument_connection's fixture has no db name/vendor populated to fall back to) instead of just span count.
…espace-only Composed statements A Composed statement that is truthy but has no tokens after leading-comment or whitespace stripping made `.split()[0]` raise IndexError in the psycopg instrumentation's get_operation_name override. Guard it the same way the dbapi base does, returning an empty operation name instead. 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>
Per xrmx's review on open-telemetry#4936: the regression test only checked that a comment-only Composed statement produces a span without crashing, not what that span is actually named. Asserts the observed fallback (empty string - instrument_connection's fixture has no db name/vendor populated to fall back to) instead of just span count.
Atishyy27
force-pushed
the
fix/psycopg-operation-name-empty-tokens
branch
from
August 20, 2026 23:57
6abaf06 to
72b251d
Compare
xrmx
approved these changes
Aug 21, 2026
tammy-baylis-swi
approved these changes
Aug 27, 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 psycopg instrumentation's
get_operation_nameoverride: a comment-only / whitespace-onlyComposedstatement is truthy but has no tokens left after leading-comment stripping, so.split()[0]raisesIndexError. This guards it the same way the dbapi base does (tokens[0] if tokens else "").Follow-up to #4934, kept as a separate PR per the single-logical-change discussion there.
Type of change: Bug fix (non-breaking)
How Has This Been Tested?
Added
test_instrument_connection_comment_only_composed_query(a comment-onlyComposedno longer raises); the existingtest_instrument_connection_composed_querystill passes. Verified locally.Does This PR Require a Core Repo Change? No.