Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
df17c09
Add _semconv set_db fns
tammy-baylis-swi Jan 20, 2026
c41c5b2
lint
tammy-baylis-swi Jan 20, 2026
d067840
Changelog
tammy-baylis-swi Jan 20, 2026
21a7087
semconv opt-in for DB-API instr
tammy-baylis-swi Jan 20, 2026
76e2da6
Changelog
tammy-baylis-swi Jan 20, 2026
4852d10
set_int_attribute account for mocks
tammy-baylis-swi Jan 20, 2026
c262ab2
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Jan 22, 2026
d7fc6ac
simplify
tammy-baylis-swi Jan 22, 2026
a14da5e
Update dbapi docs about enable_commenter_attribute with semconv migra…
tammy-baylis-swi Jan 22, 2026
b489f69
Add migration status
tammy-baylis-swi Jan 23, 2026
9579bf6
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Jan 23, 2026
f577861
Update package, attr docs for all db-api inheritors
tammy-baylis-swi Jan 23, 2026
641b31f
generate
tammy-baylis-swi Jan 23, 2026
b659d98
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Jan 26, 2026
f8f57c9
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Jan 27, 2026
33d682d
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Feb 18, 2026
de1757d
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Feb 24, 2026
db6851d
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Feb 27, 2026
9285e69
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Mar 5, 2026
d4cdd5e
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Mar 19, 2026
36944ac
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Mar 25, 2026
fe58f80
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Mar 27, 2026
e8d87e4
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Apr 2, 2026
5fd257c
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Apr 6, 2026
002b3e5
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Apr 7, 2026
0e22a60
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Apr 13, 2026
bd608f0
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Apr 17, 2026
e2040ef
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi Apr 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `opentelemetry-instrumentation-boto`: Remove instrumentation
([#4303](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4303))

### Added

- `opentelemetry-instrumentation-dbapi`: implement new semantic convention opt-in migration
([#4109](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4109))

## Version 1.40.0/0.61b0 (2026-03-04)

### Added
Expand Down
16 changes: 8 additions & 8 deletions instrumentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
| [opentelemetry-instrumentation-celery](./opentelemetry-instrumentation-celery) | celery >= 4.0, < 6.0 | No | development
| [opentelemetry-instrumentation-click](./opentelemetry-instrumentation-click) | click >= 8.1.3, < 9.0.0 | No | development
| [opentelemetry-instrumentation-confluent-kafka](./opentelemetry-instrumentation-confluent-kafka) | confluent-kafka >= 1.8.2, < 3.0.0 | No | development
| [opentelemetry-instrumentation-dbapi](./opentelemetry-instrumentation-dbapi) | dbapi | No | development
| [opentelemetry-instrumentation-dbapi](./opentelemetry-instrumentation-dbapi) | dbapi | No | migration
| [opentelemetry-instrumentation-django](./opentelemetry-instrumentation-django) | django >= 2.0 | Yes | development
| [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 6.0 | No | development
| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 1.4.1, < 5.0.0 | Yes | migration
Expand All @@ -28,21 +28,21 @@
| [opentelemetry-instrumentation-jinja2](./opentelemetry-instrumentation-jinja2) | jinja2 >= 2.7, < 4.0 | No | development
| [opentelemetry-instrumentation-kafka-python](./opentelemetry-instrumentation-kafka-python) | kafka-python >= 2.0, < 3.0,kafka-python-ng >= 2.0, < 3.0 | No | development
| [opentelemetry-instrumentation-logging](./opentelemetry-instrumentation-logging) | logging | No | development
| [opentelemetry-instrumentation-mysql](./opentelemetry-instrumentation-mysql) | mysql-connector-python >= 8.0, < 10.0 | No | development
| [opentelemetry-instrumentation-mysqlclient](./opentelemetry-instrumentation-mysqlclient) | mysqlclient < 3 | No | development
| [opentelemetry-instrumentation-mysql](./opentelemetry-instrumentation-mysql) | mysql-connector-python >= 8.0, < 10.0 | No | migration
| [opentelemetry-instrumentation-mysqlclient](./opentelemetry-instrumentation-mysqlclient) | mysqlclient < 3 | No | migration
| [opentelemetry-instrumentation-pika](./opentelemetry-instrumentation-pika) | pika >= 0.12.0 | No | development
| [opentelemetry-instrumentation-psycopg](./opentelemetry-instrumentation-psycopg) | psycopg >= 3.1.0 | No | development
| [opentelemetry-instrumentation-psycopg2](./opentelemetry-instrumentation-psycopg2) | psycopg2 >= 2.7.3.1,psycopg2-binary >= 2.7.3.1 | No | development
| [opentelemetry-instrumentation-psycopg](./opentelemetry-instrumentation-psycopg) | psycopg >= 3.1.0 | No | migration
| [opentelemetry-instrumentation-psycopg2](./opentelemetry-instrumentation-psycopg2) | psycopg2 >= 2.7.3.1,psycopg2-binary >= 2.7.3.1 | No | migration
| [opentelemetry-instrumentation-pymemcache](./opentelemetry-instrumentation-pymemcache) | pymemcache >= 1.3.5, < 5 | No | development
| [opentelemetry-instrumentation-pymongo](./opentelemetry-instrumentation-pymongo) | pymongo >= 3.1, < 5.0 | No | development
| [opentelemetry-instrumentation-pymssql](./opentelemetry-instrumentation-pymssql) | pymssql >= 2.1.5, < 3 | No | development
| [opentelemetry-instrumentation-pymysql](./opentelemetry-instrumentation-pymysql) | PyMySQL < 2 | No | development
| [opentelemetry-instrumentation-pymssql](./opentelemetry-instrumentation-pymssql) | pymssql >= 2.1.5, < 3 | No | migration
| [opentelemetry-instrumentation-pymysql](./opentelemetry-instrumentation-pymysql) | PyMySQL < 2 | No | migration
| [opentelemetry-instrumentation-pyramid](./opentelemetry-instrumentation-pyramid) | pyramid >= 1.7 | Yes | migration
| [opentelemetry-instrumentation-redis](./opentelemetry-instrumentation-redis) | redis >= 2.6 | No | development
| [opentelemetry-instrumentation-remoulade](./opentelemetry-instrumentation-remoulade) | remoulade >= 0.50 | No | development
| [opentelemetry-instrumentation-requests](./opentelemetry-instrumentation-requests) | requests ~= 2.0 | Yes | migration
| [opentelemetry-instrumentation-sqlalchemy](./opentelemetry-instrumentation-sqlalchemy) | sqlalchemy >= 1.0.0, < 2.1.0 | Yes | migration
| [opentelemetry-instrumentation-sqlite3](./opentelemetry-instrumentation-sqlite3) | sqlite3 | No | development
| [opentelemetry-instrumentation-sqlite3](./opentelemetry-instrumentation-sqlite3) | sqlite3 | No | migration
| [opentelemetry-instrumentation-starlette](./opentelemetry-instrumentation-starlette) | starlette >= 0.13 | Yes | development
| [opentelemetry-instrumentation-system-metrics](./opentelemetry-instrumentation-system-metrics) | psutil >= 5 | No | development
| [opentelemetry-instrumentation-threading](./opentelemetry-instrumentation-threading) | threading | No | development
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@
SQLComment in span attribute
****************************
If sqlcommenter is enabled, you can opt into the inclusion of sqlcomment in
the query span ``db.statement`` attribute for your needs. If ``commenter_options``
have been set, the span attribute comment will also be configured by this
setting.
the query span ``db.statement`` and/or ``db.query.text`` attribute for your
needs. If ``commenter_options`` have been set, the span attribute comment
will also be configured by this setting.

.. code:: python

Expand All @@ -151,7 +151,7 @@


# Opts into sqlcomment for MySQL trace integration.
# Opts into sqlcomment for `db.statement` span attribute.
# Opts into sqlcomment for `db.statement` and/or `db.query.text` span attribute.
wrap_connect(
__name__,
mysql.connector,
Expand Down Expand Up @@ -186,23 +186,24 @@
from wrapt import ObjectProxy as BaseObjectProxy

from opentelemetry import trace as trace_api
from opentelemetry.instrumentation._semconv import (
_get_schema_url,
_OpenTelemetrySemanticConventionStability,
_OpenTelemetryStabilitySignalType,
_set_db_name,
_set_db_statement,
_set_db_system,
_set_db_user,
_set_http_net_peer_name_client,
_set_http_peer_port_client,
)
from opentelemetry.instrumentation.dbapi.version import __version__
from opentelemetry.instrumentation.sqlcommenter_utils import _add_sql_comment
from opentelemetry.instrumentation.utils import (
_get_opentelemetry_values,
is_instrumentation_enabled,
unwrap,
)
from opentelemetry.semconv._incubating.attributes.db_attributes import (
DB_NAME,
DB_STATEMENT,
DB_SYSTEM,
DB_USER,
)
from opentelemetry.semconv._incubating.attributes.net_attributes import (
NET_PEER_NAME,
NET_PEER_PORT,
)
from opentelemetry.trace import SpanKind, TracerProvider, get_tracer
from opentelemetry.util._importlib_metadata import version as util_version

Expand Down Expand Up @@ -244,7 +245,7 @@ def trace_integration(
enable_commenter: Flag to enable/disable sqlcommenter.
db_api_integration_factory: The `DatabaseApiIntegration` to use. If none is passed the
default one is used.
enable_attribute_commenter: Flag to enable/disable sqlcomment inclusion in `db.statement` span attribute. Only available if enable_commenter=True.
enable_attribute_commenter: Flag to enable/disable sqlcomment inclusion in `db.statement` and/or `db.query.text` span attribute. Only available if enable_commenter=True.
commenter_options: Configurations for tags to be appended at the sql query.
"""
wrap_connect(
Expand Down Expand Up @@ -294,7 +295,7 @@ def wrap_connect(
db_api_integration_factory: The `DatabaseApiIntegration` to use. If none is passed the
default one is used.
commenter_options: Configurations for tags to be appended at the sql query.
enable_attribute_commenter: Flag to enable/disable sqlcomment inclusion in `db.statement` span attribute. Only available if enable_commenter=True.
enable_attribute_commenter: Flag to enable/disable sqlcomment inclusion in `db.statement` and/or `db.query.text` span attribute. Only available if enable_commenter=True.

"""
db_api_integration_factory = (
Expand Down Expand Up @@ -372,7 +373,7 @@ def instrument_connection(
enable_commenter: Flag to enable/disable sqlcommenter.
commenter_options: Configurations for tags to be appended at the sql query.
connect_module: Module name where connect method is available.
enable_attribute_commenter: Flag to enable/disable sqlcomment inclusion in `db.statement` span attribute. Only available if enable_commenter=True.
enable_attribute_commenter: Flag to enable/disable sqlcomment inclusion in `db.statement` and/or `db.query.text` span attribute. Only available if enable_commenter=True.
db_api_integration_factory: A class or factory function to use as a
replacement for :class:`DatabaseApiIntegration`. Can be used to
obtain connection attributes from the connect method instead of
Expand Down Expand Up @@ -437,6 +438,12 @@ def __init__(
connect_module: Callable[..., Any] | None = None,
enable_attribute_commenter: bool = False,
):
# Initialize semantic conventions opt-in if needed
_OpenTelemetrySemanticConventionStability._initialize()
self._sem_conv_opt_in_mode = _OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
_OpenTelemetryStabilitySignalType.DATABASE,
)

if connection_attributes is None:
self.connection_attributes = {
"database": "database",
Expand All @@ -452,7 +459,7 @@ def __init__(
self._name,
instrumenting_library_version=self._version,
tracer_provider=tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
schema_url=_get_schema_url(self._sem_conv_opt_in_mode),
)
self.capture_parameters = capture_parameters
self.enable_commenter = enable_commenter
Expand Down Expand Up @@ -565,13 +572,21 @@ def get_connection_attributes(self, connection: object) -> None:
if user and isinstance(user, bytes):
user = user.decode()
if user is not None:
self.span_attributes[DB_USER] = str(user)
_set_db_user(
self.span_attributes, str(user), self._sem_conv_opt_in_mode
)
host = self.connection_props.get("host")
if host is not None:
self.span_attributes[NET_PEER_NAME] = host
_set_http_net_peer_name_client(
self.span_attributes,
host,
self._sem_conv_opt_in_mode,
)
port = self.connection_props.get("port")
if port is not None:
self.span_attributes[NET_PEER_PORT] = port
_set_http_peer_port_client(
self.span_attributes, port, self._sem_conv_opt_in_mode
)


# pylint: disable=abstract-method,no-member
Expand Down Expand Up @@ -699,9 +714,24 @@ def _populate_span(
if not span.is_recording():
return
statement = self.get_statement(cursor, args)
span.set_attribute(DB_SYSTEM, self._db_api_integration.database_system)
span.set_attribute(DB_NAME, self._db_api_integration.database)
span.set_attribute(DB_STATEMENT, statement)
sem_conv_mode = self._db_api_integration._sem_conv_opt_in_mode
span_attrs = {}

_set_db_system(
span_attrs,
self._db_api_integration.database_system,
sem_conv_mode,
)
_set_db_name(
span_attrs,
self._db_api_integration.database,
sem_conv_mode,
)
_set_db_statement(span_attrs, statement, sem_conv_mode)

# Set all collected attributes
for attribute_key, attribute_value in span_attrs.items():
span.set_attribute(attribute_key, attribute_value)

for (
attribute_key,
Expand Down Expand Up @@ -752,14 +782,14 @@ def traced_execution(
if span.is_recording():
if args and self._commenter_enabled:
if self._enable_attribute_commenter:
# sqlcomment is added to executed query and db.statement span attribute
# sqlcomment is added to executed query and db.statement and/or db.query.text span attribute
args = self._update_args_with_added_sql_comment(
args, cursor
)
self._populate_span(span, cursor, *args)
else:
# sqlcomment is only added to executed query
# so db.statement is set before add_sql_comment
# so db.statement and/or db.query.text are set before add_sql_comment
self._populate_span(span, cursor, *args)
args = self._update_args_with_added_sql_comment(
args, cursor
Expand Down Expand Up @@ -790,14 +820,14 @@ async def traced_execution_async(
if span.is_recording():
if args and self._commenter_enabled:
if self._enable_attribute_commenter:
# sqlcomment is added to executed query and db.statement span attribute
# sqlcomment is added to executed query and db.statement and/or db.query.text span attribute
args = self._update_args_with_added_sql_comment(
args, cursor
)
self._populate_span(span, cursor, *args)
else:
# sqlcomment is only added to executed query
# so db.statement is set before add_sql_comment
# so db.statement and/or db.query.text are set before add_sql_comment
self._populate_span(span, cursor, *args)
args = self._update_args_with_added_sql_comment(
args, cursor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@


_instruments = tuple()

_semconv_status = "migration"
Loading
Loading