Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
40 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
28fa922
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi May 4, 2026
4bd25b4
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi May 5, 2026
e6a6a33
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi May 6, 2026
9c72bae
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi May 8, 2026
c3080db
Back to pass
tammy-baylis-swi May 8, 2026
4730fc4
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi May 8, 2026
e8bfec3
Merge branch 'main' into dbapi-semconv-opt-in
herin049 May 9, 2026
7ef25fd
Merge branch 'main' into dbapi-semconv-opt-in
tammy-baylis-swi May 11, 2026
3c14331
Opt-in mode Database and/or HTTP
tammy-baylis-swi May 11, 2026
800ff5f
Add schema_url test asserts
tammy-baylis-swi May 11, 2026
123575e
contextlib for optin test modes
tammy-baylis-swi May 11, 2026
060d1c6
Nit
tammy-baylis-swi May 11, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#3980](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3980))
- `opentelemetry-instrumentation`: add database stability attribute setters in `_semconv` utilities
([#4108](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4108))
- `opentelemetry-instrumentation-dbapi`: implement new semantic convention opt-in migration
([#4109](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4109))

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,23 +177,24 @@
from wrapt import wrap_function_wrapper

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 @@ -428,6 +429,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(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to consider HTTP signals as well for sem conv optin cus we have attributes like _set_http_net_peer_name_client

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya good point I'll change it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 3c14331 and also changed PR description

_OpenTelemetryStabilitySignalType.DATABASE,
)

if connection_attributes is None:
self.connection_attributes = {
"database": "database",
Expand All @@ -443,7 +450,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),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think _get_schema_url is hardcoded to return https://opentelemetry.io/schemas/1.21.0 regardless of signal type. Is this correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_get_schema_url returns 1.11.0 if passed mode is "legacy", else it'll return 1.21.0. Here, DB-API instrumentation init passes configured/default mode for DB.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes in 3c14331 for 3 different versions now, so added more test asserts in 800ff5f

)
self.capture_parameters = capture_parameters
self.enable_commenter = enable_commenter
Expand Down Expand Up @@ -556,13 +563,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
Expand Down Expand Up @@ -676,9 +691,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():
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use set_attributes here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 060d1c6

span.set_attribute(attribute_key, attribute_value)

for (
attribute_key,
Expand Down
Loading