Skip to content

Commit 43ab220

Browse files
committed
opentelemetry-instrumentation-sqlalchemy: Fix exception on empty query
1 parent 21a35b6 commit 43ab220

File tree

2 files changed

+5
-3
lines changed
  • instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy

2 files changed

+5
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Fixed
1515

16+
- `opentelemetry-instrumentation-sqlalchemy`: Fix exception on empty query
17+
([#3860](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3860))
1618
- `opentelemetry-instrumentation-botocore`: migrate off the deprecated events API to use the logs API
1719
([#3624](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3624))
1820
- `opentelemetry-instrumentation-dbapi`: fix crash retrieving libpq version when enabling commenter with psycopg

instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ def _operation_name(self, db_name, statement):
239239
# For some very special cases it might not record the correct statement if the SQL
240240
# dialect is too weird but in any case it shouldn't break anything.
241241
# Strip leading comments so we get the operation name.
242-
parts.append(
243-
self._leading_comment_remover.sub("", statement).split()[0]
244-
)
242+
split_query = self._leading_comment_remover.sub("", statement).split()
243+
if split_query:
244+
parts.append(split_query[0])
245245
if db_name:
246246
parts.append(db_name)
247247
if not parts:

0 commit comments

Comments
 (0)