Skip to content

Conversation

nao23
Copy link
Contributor

@nao23 nao23 commented May 3, 2025

Description

Fixes #3459

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

I tested by unit test and manual test.

  • Unit Test
  • Manual Test

Manual test is done by run a below script by uv run reproduce.py

# /// script
# requires-python = ">=3.12"
# dependencies = [
#     "opentelemetry-instrumentation-dbapi @ git+https://[email protected]/nao23/opentelemetry-python-contrib.git@feature/dbapi-instrument-respect-suppress-instrumentation#subdirectory=instrumentation/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()

Does This PR Require a Core Repo Change?

  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Copy link

linux-foundation-easycla bot commented May 3, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@emdneto emdneto moved this to Easy to review / merge / close in @xrmx's Python PR digest May 5, 2025
Copy link
Member

@emdneto emdneto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a changelog entry.

@nao23 nao23 requested a review from a team as a code owner May 5, 2025 16:29
@nao23
Copy link
Contributor Author

nao23 commented May 5, 2025

@emdneto Thank you for review! I updated a changelog.

@nao23
Copy link
Contributor Author

nao23 commented May 20, 2025

@open-telemetry/opentelemetry-python-contrib-approvers Could you take a look at this PR?

@nao23
Copy link
Contributor Author

nao23 commented May 23, 2025

fixed conflict.

@nao23
Copy link
Contributor Author

nao23 commented May 28, 2025

Any chance this could be merged ?

@nao23
Copy link
Contributor Author

nao23 commented May 29, 2025

fixed conflict.

@nao23
Copy link
Contributor Author

nao23 commented May 29, 2025

@open-telemetry/opentelemetry-python-contrib-maintainers Could you take a look at this PR?

@xrmx xrmx merged commit 6d8becf into open-telemetry:main May 30, 2025
625 checks passed
@github-project-automation github-project-automation bot moved this from Easy to review / merge / close to Done in @xrmx's Python PR digest May 30, 2025
devmonkey22 pushed a commit to devmonkey22/opentelemetry-python-contrib that referenced this pull request Aug 5, 2025
…ntation (open-telemetry#3460)

* respect supress_instrumentation

* update CHANGELOG

* fix link

* update CHANGELOG

---------

Co-authored-by: Emídio Neto <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Database API instrumentation does not respect suppress_instrumentation functionality
4 participants