Skip to content

fix(psycopg): avoid IndexError in get_operation_name for comment/whitespace-only statements - #4936

Open
Atishyy27 wants to merge 3 commits into
open-telemetry:mainfrom
Atishyy27:fix/psycopg-operation-name-empty-tokens
Open

fix(psycopg): avoid IndexError in get_operation_name for comment/whitespace-only statements#4936
Atishyy27 wants to merge 3 commits into
open-telemetry:mainfrom
Atishyy27:fix/psycopg-operation-name-empty-tokens

Conversation

@Atishyy27

Copy link
Copy Markdown

Same class as #4934, in the psycopg instrumentation's get_operation_name override: a comment-only / whitespace-only Composed statement is truthy but has no tokens left after leading-comment stripping, so .split()[0] raises IndexError. 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-only Composed no longer raises); the existing test_instrument_connection_composed_query still passes. Verified locally.

Does This PR Require a Core Repo Change? No.

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>
@Atishyy27
Atishyy27 requested a review from a team as a code owner August 8, 2026 19:41
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 14, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-08-27 19:18 UTC

Investigate required status check failures.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

@github-project-automation github-project-automation Bot moved this to Reviewed PRs that need fixes in Python PR digest 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
Atishyy27 force-pushed the fix/psycopg-operation-name-empty-tokens branch from 6abaf06 to 72b251d Compare August 20, 2026 23:57
@github-project-automation github-project-automation Bot moved this from Reviewed PRs that need fixes to Approved PRs in Python PR digest Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

3 participants