Skip to content

DB semantic convention stability migration for DB-API and 7 inheriting db client instrumentors#4109

Merged
lzchen merged 42 commits into
open-telemetry:mainfrom
tammy-baylis-swi:dbapi-semconv-opt-in
May 12, 2026
Merged

DB semantic convention stability migration for DB-API and 7 inheriting db client instrumentors#4109
lzchen merged 42 commits into
open-telemetry:mainfrom
tammy-baylis-swi:dbapi-semconv-opt-in

Conversation

@tammy-baylis-swi

@tammy-baylis-swi tammy-baylis-swi commented Jan 20, 2026

Copy link
Copy Markdown
Contributor

Description

Add DB-API instrumentor support for when OTEL_SEMCONV_STABILITY_OPT_IN includes

  • "database" or "database/dup"
  • "http" or "http/dup"

This changes the SQLComment in span attribute feature if opted in. Inclusion of sqlcomment on query span would be on db.statement and/or db.query.text attribute if default, "database", or "database/dup".

These instrumentors inherit DB-API's wrap_connect and/or instrument_connection, and therefore also gain support for semconv migration automatically:

  1. mysql
  2. mysqlclient
  3. psycopg2
  4. psycopg
  5. pymssql
  6. pymysql
  7. sqlite3

Fixes #2929 #2678 #2928 #2931 #2932 #2933 #2934

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Added unit tests

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@tammy-baylis-swi tammy-baylis-swi marked this pull request as ready for review January 22, 2026 21:43
@tammy-baylis-swi tammy-baylis-swi requested a review from a team as a code owner January 22, 2026 21:43
@tammy-baylis-swi tammy-baylis-swi changed the title DB semantic convention stability migration for DB-API DB semantic convention stability migration for DB-API and 7 inheriting db client instrumentors Jan 23, 2026
@tammy-baylis-swi tammy-baylis-swi requested a review from lzchen May 12, 2026 00:02
@tammy-baylis-swi tammy-baylis-swi moved this from Ready for review to Approved PRs in Python PR digest May 12, 2026
@lzchen lzchen merged commit 85a51e6 into open-telemetry:main May 12, 2026
752 checks passed
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Python PR digest May 12, 2026
bmwalters added a commit to bmwalters/opentelemetry-python-contrib that referenced this pull request May 13, 2026
Migrates the new transaction-span code to the semconv stability pattern

introduced on main in open-telemetry#4109:

- Replace direct DB_OPERATION / DB_SYSTEM / DB_NAME imports with the

  _set_db_operation / _set_db_system / _set_db_name helpers from

  opentelemetry.instrumentation._semconv, so transaction spans emit

  db.operation or db.operation.name (and equivalents) based on

  OTEL_SEMCONV_STABILITY_OPT_IN.

- Gate error.type on _report_new(sem_conv_mode), matching requests/urllib.

- Add new_semconv / both_semconv variants for the transaction tests in

  test_dbapi_integration.py to cover the migration matrix.

- Drop the pre-semconv ERROR_TYPE failure-test assertions in psycopg,

  since ERROR_TYPE is now gated to new semconv mode and the dbapi-level

  new_semconv tests cover the gating behavior.

Assisted-by: Claude Opus 4.7
xrmx added a commit that referenced this pull request May 18, 2026
… in wrapped_connection (#4592)

* fix(pymssql): use semconv helpers for host/port/user attributes

The pymssql instrumentation's wrapped_connection() was setting
net.peer.name, net.peer.port, and db.user using hardcoded legacy
attribute keys, bypassing the semconv stability helpers introduced
in #4109.

Replace hardcoded keys with _set_db_user, _set_http_net_peer_name_client,
and _set_http_peer_port_client so that OTEL_SEMCONV_STABILITY_OPT_IN
correctly emits stable attributes (server.address, server.port, etc.).

Also updates existing test assertions for net.peer.port from string
to int, matching the behavior of set_int_attribute used by the helper.

* Update instrumentation/opentelemetry-instrumentation-pymssql/tests/test_pymssql_integration.py

Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>

* Update instrumentation/opentelemetry-instrumentation-pymssql/tests/test_pymssql_integration.py

Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>

* Add changelog fragment for #4592

* Fix linting and add changelog fragment

---------

Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com>
liustve added a commit to aws-observability/aws-otel-python-instrumentation that referenced this pull request Jun 16, 2026
mysqlclient 2.2.7 (PyMySQL/mysqlclient#752, 2025-01) added Python-level
self.db / self.database attributes in Connection.__init__ for OTel
instrumentation to read. The contract test was pinned at 2.2.4 where
those attributes didn't exist, so dbapi's getattr(conn, "db") returned
None and the upstream dbapi instrumentation's empty-string default landed
on the span.

The 0.62b0 dbapi semantic-convention migration
(open-telemetry/opentelemetry-python-contrib#4109) added an `if value:`
filter in _set_db_name, so the empty string is now dropped entirely
and the test's `db.name == ""` assertion fails with "key not found".

Bump the contract-test pin to 2.2.8 (current latest) so conn.db
returns the actual database name, and update the assertion to expect
DATABASE_NAME instead of the empty placeholder.

Verified locally against MySQL 8: mysqlclient 2.2.4 -> conn.db is None,
mysqlclient 2.2.7+ -> conn.db == "testdb".
liustve added a commit to aws-observability/aws-otel-python-instrumentation that referenced this pull request Jun 17, 2026
Automated update of OpenTelemetry dependencies.

**Build Status:** ❌
[failure](https://github.com/aws-observability/aws-otel-python-instrumentation/actions/runs/27184408784)

**Updated versions:**
- [OpenTelemetry
Python](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.42.1):
1.42.1
- [OpenTelemetry
Contrib](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.63b1):
0.63b1
-
[opentelemetry-sdk-extension-aws](https://pypi.org/project/opentelemetry-sdk-extension-aws/2.1.0/):
2.1.0
-
[opentelemetry-propagator-aws-xray](https://pypi.org/project/opentelemetry-propagator-aws-xray/1.0.2/):
1.0.2

**Upstream releases with breaking changes:**
Note: the mechanism to detect upstream breaking changes is not perfect.
Be sure to check all new releases and understand if any additional
changes need to be addressed.


**opentelemetry-python-contrib:**
- [Version
1.41.0/0.62b0](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.62b0)

*Description of changes:*

- Drops the `opentelemetry-instrumentation-boto` runtime dependency
(legacy boto2 instrumentation), removed entirely upstream in:
open-telemetry/opentelemetry-python-contrib#4303

- Drops Python 3.9 support to match upstream's new minimum (Python
≥3.10): open-telemetry/opentelemetry-python#5076
(core) and
open-telemetry/opentelemetry-python-contrib#4412
(contrib)

- Switches `from importlib_metadata import version` to stdlib `from
importlib.metadata import version` after upstream dropped the
third-party `importlib-metadata` package from `opentelemetry-api`:
open-telemetry/opentelemetry-python#3234

- Refactors the botocore patches (`_botocore_patches.py`) to use the new
`ExtensionRegistry` API. Upstream split `_KNOWN_EXTENSIONS` into
`_BOTOCORE_EXTENSIONS` + `_AIOBOTOCORE_EXTENSIONS`, removed
`_find_extension`, and moved `_safe_invoke` to
`opentelemetry.instrumentation.botocore.utils` as part of adding
aiobotocore instrumentation:
open-telemetry/opentelemetry-python-contrib#4049

- Removes the Starlette ASGI `suppress_http_instrumentation` patch
(which the existing ADOT TODO already flagged) since the ASGI middleware
now natively honors `suppress_http_instrumentation` upstream:
open-telemetry/opentelemetry-python-contrib#4375

- Adapts the configurator tests to upstream's renamed
`BaggageSpanProcessor._baggage_key_predicate` → `_predicates` (now a
list of callables, after the constructor was reworked to accept either a
single predicate or a sequence):
open-telemetry/opentelemetry-python-contrib#4371

- Adapts `test_otlp_attribute_vs_body_types` to upstream's
`_VALID_ANY_VALUE_TYPES` switching `typing.Mapping`/`typing.Sequence` to
`collections.abc.Mapping`/`collections.abc.Sequence`:
open-telemetry/opentelemetry-python#5133

- Bumps the mysqlclient contract-test pin from `2.2.4` to `2.2.8` and
updates the matching `db.name` assertion. The 0.62b0 dbapi
semantic-convention migration
(open-telemetry/opentelemetry-python-contrib#4109)
added an empty-string filter inside `_set_db_name`, which exposed a
latent gap: mysqlclient < 2.2.7 didn't expose a Python-level `conn.db`
attribute (added upstream in
PyMySQL/mysqlclient#752, shipped in mysqlclient
2.2.7), so OTel's dbapi instrumentation defaulted `database` to `""` and
the empty value used to land on the span unconditionally. After 0.62b0
the empty value is dropped, so the assertion `db.name == ""` now fails
with "key not found". Bumping mysqlclient lets `conn.db` flow through as
the actual database name (`testdb`) so the assertion becomes meaningful.


By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Steve Liu <liustve@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

opentelemetry-instrumentation-dbapi: semantic convention stability migration

4 participants