OpenTelemetry Database API Instrumentation

The trace integration with Database API supports libraries that follow the Python Database API Specification v2.0. https://www.python.org/dev/peps/pep-0249/

Usage

import mysql.connector
import pyodbc

from opentelemetry.instrumentation.dbapi import trace_integration


# Ex: mysql.connector
trace_integration(mysql.connector, "connect", "mysql")
# Ex: pyodbc
trace_integration(pyodbc, "Connection", "odbc")

API

opentelemetry.instrumentation.dbapi.trace_integration(connect_module, connect_method_name, database_system, connection_attributes=None, tracer_provider=None, capture_parameters=False, db_api_integration_factory=None)[source]

Integrate with DB API library. https://www.python.org/dev/peps/pep-0249/

Parameters
  • connect_module (Callable[…, Any]) – Module name where connect method is available.

  • connect_method_name (str) – The connect method name.

  • database_system (str) – An identifier for the database management system (DBMS) product being used.

  • connection_attributes (Optional[Dict]) – Attribute names for database, port, host and user in Connection object.

  • tracer_provider (Optional[TracerProvider]) – The opentelemetry.trace.TracerProvider to use. If omitted the current configured one is used.

  • capture_parameters (bool) – Configure if db.statement.parameters should be captured.

opentelemetry.instrumentation.dbapi.wrap_connect(name, connect_module, connect_method_name, database_system, connection_attributes=None, version='', tracer_provider=None, capture_parameters=False, db_api_integration_factory=None)[source]

Integrate with DB API library. https://www.python.org/dev/peps/pep-0249/

Parameters
  • connect_module (Callable[…, Any]) – Module name where connect method is available.

  • connect_method_name (str) – The connect method name.

  • database_system (str) – An identifier for the database management system (DBMS) product being used.

  • connection_attributes (Optional[Dict]) – Attribute names for database, port, host and user in Connection object.

  • tracer_provider (Optional[TracerProvider]) – The opentelemetry.trace.TracerProvider to use. If omitted the current configured one is used.

  • capture_parameters (bool) – Configure if db.statement.parameters should be captured.

opentelemetry.instrumentation.dbapi.unwrap_connect(connect_module, connect_method_name)[source]

Disable integration with DB API library. https://www.python.org/dev/peps/pep-0249/

Parameters
  • connect_module (Callable[…, Any]) – Module name where the connect method is available.

  • connect_method_name (str) – The connect method name.

opentelemetry.instrumentation.dbapi.instrument_connection(name, connection, database_system, connection_attributes=None, version='', tracer_provider=None, capture_parameters=False)[source]

Enable instrumentation in a database connection.

Parameters
  • connection – The connection to instrument.

  • database_system (str) – An identifier for the database management system (DBMS) product being used.

  • connection_attributes (Optional[Dict]) – Attribute names for database, port, host and user in a connection object.

  • tracer_provider (Optional[TracerProvider]) – The opentelemetry.trace.TracerProvider to use. If omitted the current configured one is used.

  • capture_parameters – Configure if db.statement.parameters should be captured.

Returns

An instrumented connection.

opentelemetry.instrumentation.dbapi.uninstrument_connection(connection)[source]

Disable instrumentation in a database connection.

Parameters

connection – The connection to uninstrument.

Returns

An uninstrumented connection.

class opentelemetry.instrumentation.dbapi.DatabaseApiIntegration(name, database_system, connection_attributes=None, version='', tracer_provider=None, capture_parameters=False)[source]

Bases: object

wrapped_connection(connect_method, args, kwargs)[source]

Add object proxy to connection object.

get_connection_attributes(connection)[source]
opentelemetry.instrumentation.dbapi.get_traced_connection_proxy(connection, db_api_integration, *args, **kwargs)[source]
class opentelemetry.instrumentation.dbapi.CursorTracer(db_api_integration)[source]

Bases: object

get_operation_name(cursor, args)[source]
get_statement(cursor, args)[source]
traced_execution(cursor, query_method, *args, **kwargs)[source]
opentelemetry.instrumentation.dbapi.get_traced_cursor_proxy(cursor, db_api_integration, *args, **kwargs)[source]