opentelemetry-instrumentation-dbapi: instrument commit and rollback#4519
opentelemetry-instrumentation-dbapi: instrument commit and rollback#4519bmwalters wants to merge 4 commits intoopen-telemetry:mainfrom
Conversation
|
Are these Span names a part of the Spec? Quickly glancing at the spec it doesn't seem like it is, in which case we probably don't want to support adding changes that aren't spec compliant. |
Aligns transaction spans with the OTel semconv db attribute that names the operation. The span name (COMMIT/ROLLBACK) was previously the only way for a backend to know what operation produced the span; the attribute makes it queryable. Assisted-by: Claude Opus 4.7
The OTel DB semconv spec is silent on transaction lifecycle operations (commit/rollback). Java's JDBC instrumentation gates the same behavior behind an experimental opt-in flag; matching that posture here while the spec is unsettled. Existing tests opt in explicitly; CHANGELOG entry consolidated and marked experimental. Assisted-by: Claude Opus 4.7
|
@herin049 Good question. The DB semconv spec (database-spans.md, sql.md) doesn't model txn operations (only query spans), and a prior proposal open-telemetry/semantic-conventions#1134 was closed by the reporter without any action. That said, Coming back to Python, this PR also matches Based on this investigation, I did make two follow-up commits just now:
Wdyt? |
I am not sure what stance the OpenTelemetry Java community has on this, but the stance that Python takes is that we should only add spec compliant signals. I would recommend raising an issue in semantic-conventions first, and then we can discuss adding these to the Python instrumentation libraries. |
Description
Adds instrumentation for database
commit()androllback()transaction operations across all DB-API instrumentations.Re-open of #3964, which was auto-closed by the stale bot.
Type of change
Changes
commit()androllback()span instrumentation todbapimoduleenable_transaction_spansconfiguration flag (noted experimental; default:False)AsyncTracedConnectionProxyfor async connections (psycopg)How Has This Been Tested?
test_dbapi_integration.pytest_psycopg_integration.pytest_pymysql_functional.pyExported trace example
From a fresh clone, with sqlcommenter fully on and
enable_transaction_spans=True(the new opt-in):INSERT:
{ "name": "INSERT", "kind": "SpanKind.CLIENT", "attributes": { "db.system": "sqlite", "db.name": "", "db.statement": "INSERT INTO t VALUES (1) /*db_driver='sqlite3%%3Aunknown',dbapi_level='2.0',dbapi_threadsafety=3,driver_paramstyle='qmark',traceparent='00-39e356b6a8e6adb68f0e712bf67a14f4-fad576ffcb92787c-01'*/" } }COMMIT:
{ "name": "COMMIT", "kind": "SpanKind.CLIENT", "attributes": { "db.system": "sqlite", "db.name": "", "db.operation.name": "COMMIT" } }ROLLBACK:
{ "name": "ROLLBACK", "kind": "SpanKind.CLIENT", "attributes": { "db.system": "sqlite", "db.name": "", "db.operation.name": "ROLLBACK" } }Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.