-
Notifications
You must be signed in to change notification settings - Fork 945
DB semantic convention stability migration for DB-API and 7 inheriting db client instrumentors #4109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
DB semantic convention stability migration for DB-API and 7 inheriting db client instrumentors #4109
Changes from 8 commits
df17c09
c41c5b2
d067840
21a7087
76e2da6
4852d10
c262ab2
d7fc6ac
a14da5e
b489f69
9579bf6
f577861
641b31f
b659d98
f8f57c9
33d682d
de1757d
db6851d
9285e69
d4cdd5e
36944ac
fe58f80
e8d87e4
5fd257c
002b3e5
0e22a60
bd608f0
e2040ef
28fa922
4bd25b4
e6a6a33
9c72bae
c3080db
4730fc4
e8bfec3
7ef25fd
3c14331
800ff5f
123575e
060d1c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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( | ||
| _OpenTelemetryStabilitySignalType.DATABASE, | ||
| ) | ||
|
|
||
| if connection_attributes is None: | ||
| self.connection_attributes = { | ||
| "database": "database", | ||
|
|
@@ -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), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) | ||
| self.capture_parameters = capture_parameters | ||
| self.enable_commenter = enable_commenter | ||
|
|
@@ -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 | ||
|
|
@@ -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(): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
|
||
There was a problem hiding this comment.
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_clientThere was a problem hiding this comment.
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
There was a problem hiding this comment.
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