Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -60,6 +60,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#4068](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4068))
- `opentelemetry-instrumentation-mysqlclient`: Replace SpanAttributes with semconv constants
([#4067](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4067))
- `opentelemetry-instrumentation-tortoiseorm`: Replace SpanAttributes with semconv constants
([#4080](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4080))
- `opentelemetry-instrumentation-asgi`: Replace SpanAttributes with semconv constants
([#4081](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4081))
- `opentelemetry-instrumentation-system-metrics`: Use proper numeric `cpython.gc.generation` attribute in CPython metrics, out of spec `generation` attribute is deprecated and will be removed in the future
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@
from opentelemetry.instrumentation.tortoiseorm.package import _instruments
from opentelemetry.instrumentation.tortoiseorm.version import __version__
from opentelemetry.instrumentation.utils import unwrap
from opentelemetry.semconv.trace import DbSystemValues, SpanAttributes
from opentelemetry.semconv._incubating.attributes.db_attributes import (
DB_NAME,
DB_STATEMENT,
DB_SYSTEM,
DB_USER,
DbSystemValues,
)
from opentelemetry.semconv._incubating.attributes.net_attributes import (
NET_PEER_NAME,
NET_PEER_PORT,
)
from opentelemetry.trace import SpanKind
from opentelemetry.trace.status import Status, StatusCode

Expand Down Expand Up @@ -230,34 +240,28 @@ def _hydrate_span_from_args(self, connection, query, parameters) -> dict:
capabilities = getattr(connection, "capabilities", None)
if capabilities is not None:
if capabilities.dialect == "sqlite":
span_attributes[SpanAttributes.DB_SYSTEM] = (
DbSystemValues.SQLITE.value
)
span_attributes[DB_SYSTEM] = DbSystemValues.SQLITE.value
elif capabilities.dialect == "postgres":
span_attributes[SpanAttributes.DB_SYSTEM] = (
DbSystemValues.POSTGRESQL.value
)
span_attributes[DB_SYSTEM] = DbSystemValues.POSTGRESQL.value
elif capabilities.dialect == "mysql":
span_attributes[SpanAttributes.DB_SYSTEM] = (
DbSystemValues.MYSQL.value
)
span_attributes[DB_SYSTEM] = DbSystemValues.MYSQL.value
dbname = getattr(connection, "filename", None)
if dbname:
span_attributes[SpanAttributes.DB_NAME] = dbname
span_attributes[DB_NAME] = dbname
dbname = getattr(connection, "database", None)
if dbname:
span_attributes[SpanAttributes.DB_NAME] = dbname
span_attributes[DB_NAME] = dbname
if query is not None:
span_attributes[SpanAttributes.DB_STATEMENT] = query
span_attributes[DB_STATEMENT] = query
user = getattr(connection, "user", None)
if user:
span_attributes[SpanAttributes.DB_USER] = user
span_attributes[DB_USER] = user
host = getattr(connection, "host", None)
if host:
span_attributes[SpanAttributes.NET_PEER_NAME] = host
span_attributes[NET_PEER_NAME] = host
port = getattr(connection, "port", None)
if port:
span_attributes[SpanAttributes.NET_PEER_PORT] = port
span_attributes[NET_PEER_PORT] = port

if self.capture_parameters:
if parameters is not None and len(parameters) > 0:
Expand Down