From 5cb4dab36499985ccf79d30b19dcdfc286d8c261 Mon Sep 17 00:00:00 2001 From: Nick Nicolini <106278816+nicknicolini@users.noreply.github.com> Date: Mon, 22 Apr 2024 17:04:20 -0600 Subject: [PATCH] Use sqlalchemy version in sqlalchemy commenter instead of opentelemetry library version (#2404) * Use sqlalchemy version in sqlalchemy commenter instead of opentelemetry library version The SqlAlchemy commenter is currently using the library version in the comment it emits, e.g.: ``` { 'db_driver': 'psycopg2', 'db_framework': 'sqlalchemy:0.45b0' } ``` We should instead be using the sqlalchemy version here, as SqlCommenter did before * Fix lint * Fix lint * Add CHANGELOG entry --------- Co-authored-by: Diego Hurtado --- CHANGELOG.md | 3 +++ .../src/opentelemetry/instrumentation/sqlalchemy/engine.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b2ff4c176..ed7658fe87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- Use sqlalchemy version in sqlalchemy commenter instead of opentelemetry library version + ([#2404](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2404)) + ### Added - `opentelemetry-instrumentation-pika` Instrumentation for `channel.consume()` (supported diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py index 0632d71faf..a810aedc38 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py @@ -15,13 +15,13 @@ import re import weakref +import sqlalchemy from sqlalchemy.event import ( # pylint: disable=no-name-in-module listen, remove, ) from opentelemetry import trace -from opentelemetry.instrumentation.sqlalchemy.version import __version__ from opentelemetry.instrumentation.sqlcommenter_utils import _add_sql_comment from opentelemetry.instrumentation.utils import _get_opentelemetry_values from opentelemetry.semconv.trace import NetTransportValues, SpanAttributes @@ -227,7 +227,7 @@ def _before_cur_exec( commenter_data = { "db_driver": conn.engine.driver, # Driver/framework centric information. - "db_framework": f"sqlalchemy:{__version__}", + "db_framework": f"sqlalchemy:{sqlalchemy.__version__}", } if self.commenter_options.get("opentelemetry_values", True):