You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was testing the recent implementation of stable semantic conventions for MSSQL (PR #4109) and found that OTEL_SEMCONV_STABILITY_OPT_IN is only partially effective for pymssql. The core db.* attributes (db.system.name, db.namespace, db.query.text) migrate correctly, but net.peer.name, net.peer.port, and db.user remain hardcoded as legacy keys regardless of the opt-in setting.
The root cause is that _PyMSSQLDatabaseApiIntegration.wrapped_connection() sets these attributes using hardcoded legacy keys, bypassing the semconv-aware helper functions introduced in #4109:
I did some research and it seems unlike other DB-API instrumentors (pymysql, psycopg2, etc.) that rely on the standard connection_attributes mapping, pymssql cannot read connection attributes from the connection object. Instead, it overrides wrapped_connection() to extract attributes from the connect() method arguments — but this override was not updated to use the semconv helpers.
For comparison, pymysql and psycopg2 emit fully correct stable attributes under the same configuration.
Additional observation: The stable db.system.name value is emitted as "mssql" but per the SQL Server semantic conventions, it MUST be "microsoft.sql_server". This appears to be an issue in the base dbapi layer's _set_db_system helper which passes through the raw value without mapping. This likely affects all DB instrumentors and may warrant a separate fix.
Would you like to implement a fix?
Yes
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.
Describe your environment
What happened?
I was testing the recent implementation of stable semantic conventions for MSSQL (PR #4109) and found that
OTEL_SEMCONV_STABILITY_OPT_INis only partially effective forpymssql. The coredb.*attributes (db.system.name,db.namespace,db.query.text) migrate correctly, butnet.peer.name,net.peer.port, anddb.userremain hardcoded as legacy keys regardless of the opt-in setting.The root cause is that
_PyMSSQLDatabaseApiIntegration.wrapped_connection()sets these attributes using hardcoded legacy keys, bypassing the semconv-aware helper functions introduced in #4109:I did some research and it seems unlike other DB-API instrumentors (pymysql, psycopg2, etc.) that rely on the standard
connection_attributesmapping,pymssqlcannot read connection attributes from the connection object. Instead, it overrideswrapped_connection()to extract attributes from theconnect()method arguments — but this override was not updated to use the semconv helpers.For comparison,
pymysqlandpsycopg2emit fully correct stable attributes under the same configuration.Steps to Reproduce
Expected Result
With
OTEL_SEMCONV_STABILITY_OPT_IN=database,http, spans should contain only stable attributes:{ "db.system.name": "mssql", "db.namespace": "master", "db.query.text": "SELECT @@VERSION", "server.address": "localhost", "server.port": 1433, "db.protocol.tds.version": "7.0" }No legacy attributes (
db.user,net.peer.name,net.peer.port) should be present — matching the behavior ofpymysqlandpsycopg2.Actual Result
Spans contain a mix of stable and legacy attributes:
{ "db.system.name": "mssql", "db.namespace": "master", "db.query.text": "SELECT @@VERSION", "db.user": "sa", "net.peer.name": "localhost", "net.peer.port": 1433, "db.protocol.tds.version": "7.0" }server.addressandserver.portare absent.db.user,net.peer.name, andnet.peer.portare still present despite opting into stable conventions.Additional context
The fix is straightforward — replace hardcoded attribute keys in
wrapped_connection()with the semconv-aware helpers:I have a fix ready with tests passing and will open a PR shortly.
Related:
Additional observation: The stable db.system.name value is emitted as "mssql" but per the SQL Server semantic conventions, it MUST be "microsoft.sql_server". This appears to be an issue in the base dbapi layer's _set_db_system helper which passes through the raw value without mapping. This likely affects all DB instrumentors and may warrant a separate fix.
Would you like to implement a fix?
Yes
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding
+1orme too, to help us triage it. Learn more here.