OpenTelemetry Database API integration¶
The trace integration with Database API supports libraries following the specification.
Usage¶
import mysql.connector
import pyodbc
from opentelemetry.ext.dbapi import trace_integration
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.trace import tracer_provider
trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)
# Ex: mysql.connector
trace_integration(tracer_provider(), mysql.connector, "connect", "mysql", "sql")
# Ex: pyodbc
trace_integration(tracer_provider(), pyodbc, "Connection", "odbc", "sql")
References¶
Module contents¶
The opentelemetry-ext-dbapi package allows tracing queries made by the ibraries following Ptyhon Database API specification: https://www.python.org/dev/peps/pep-0249/
-
opentelemetry.ext.dbapi.
trace_integration
(tracer, connect_module, connect_method_name, database_component, database_type='', connection_attributes=None)[source]¶ Integrate with DB API library. https://www.python.org/dev/peps/pep-0249/ :type tracer:
Tracer
:param tracer: TheTracer
to use. :type connect_module:Callable
[…,any
] :param connect_module: Module name where connect method is available. :type connect_method_name:str
:param connect_method_name: The connect method name. :type database_component:str
:param database_component: Database driver name or database name “JDBI”, “jdbc”, “odbc”, “postgreSQL”. :type database_type:str
:param database_type: The Database type. For any SQL database, “sql”. :type connection_attributes:Optional
[Dict
] :param connection_attributes: Attribute names for database, port, host and user in Connection object.
-
class
opentelemetry.ext.dbapi.
DatabaseApiIntegration
(tracer, database_component, database_type='sql', connection_attributes=None)[source]¶ Bases:
object
-
class
opentelemetry.ext.dbapi.
TracedConnectionProxy
(connection, db_api_integration, *args, **kwargs)[source]¶ Bases:
ObjectProxy