OpenTelemetry PyMySQL Instrumentation

The integration with PyMySQL supports the PyMySQL library and can be enabled by using PyMySQLInstrumentor.

Usage

import pymysql
from opentelemetry import trace
from opentelemetry.instrumentation.pymysql import PyMySQLInstrumentor
from opentelemetry.sdk.trace import TracerProvider

trace.set_tracer_provider(TracerProvider())

PyMySQLInstrumentor().instrument()

cnx = pymysql.connect(database="MySQL_Database")
cursor = cnx.cursor()
cursor.execute("INSERT INTO test (testField) VALUES (123)"
cnx.commit()
cursor.close()
cnx.close()

API

class opentelemetry.instrumentation.pymysql.PyMySQLInstrumentor[source]

Bases: opentelemetry.instrumentation.instrumentor.BaseInstrumentor

instrument_connection(connection)[source]

Enable instrumentation in a PyMySQL connection.

Parameters

connection – The connection to instrument.

Returns

An instrumented connection.

uninstrument_connection(connection)[source]

Disable instrumentation in a PyMySQL connection.

Parameters

connection – The connection to uninstrument.

Returns

An uninstrumented connection.