Skip to content

Database API instrumentation does not respect suppress_instrumentation functionality #3459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nao23 opened this issue May 3, 2025 · 0 comments · May be fixed by #3460
Open

Database API instrumentation does not respect suppress_instrumentation functionality #3459

nao23 opened this issue May 3, 2025 · 0 comments · May be fixed by #3460
Labels
bug Something isn't working

Comments

@nao23
Copy link

nao23 commented May 3, 2025

Describe your environment

OS: macOS
Python version: 3.12
opentelemetry-api: 1.32.1
opentelemetry-sdk: 1.32.1
opentelemetry-instrumentation-dbapi: 0.53b.1

What happened?

Database API instrumentation does not respect opentelemetry.instrumentations.util.supress_instrumentation functionality.
Span is always produced even if we use supress_instrumentation.

Steps to Reproduce

You can reproduce by run a below script by uv run reproduce.py

# /// script
# requires-python = ">=3.12"
# dependencies = [
#     "opentelemetry-api",
#     "opentelemetry-sdk",
#     "opentelemetry-instrumentation-dbapi",
#     "mysql-connector-python",
#     "testcontainers[mysql]"
# ]
# ///

import mysql.connector
from opentelemetry import trace
from opentelemetry.instrumentation.dbapi import instrument_connection
from opentelemetry.instrumentation.utils import suppress_instrumentation
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
    ConsoleSpanExporter,
    SimpleSpanProcessor,
)
from testcontainers.mysql import MySqlContainer


tracer_provider = TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))
trace.set_tracer_provider(tracer_provider)

tracer = trace.get_tracer(__name__)


with MySqlContainer("mysql:8.0") as mysql_container:
    conn_attributes = {
        "host": mysql_container.get_container_host_ip(),
        "port": mysql_container.get_exposed_port(3306),
        "user": mysql_container.username,
        "password": mysql_container.password,
        "database": mysql_container.dbname
    }
    conn = instrument_connection(
        "reproduce.py",
        mysql.connector.connect(**conn_attributes),
        "mysql",
        conn_attributes,
        connect_module=mysql.connector
    )

    with suppress_instrumentation():
        cursor = conn.cursor()
        cursor.execute("SELECT 1;")
        cursor.fetchone()
        cursor.close()
        conn.close()

Expected Result

No span is produced.

Actual Result

Span is produced.

Additional context

No response

Would you like to implement a fix?

Yes

@nao23 nao23 added the bug Something isn't working label May 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant