Skip to content

fix: respect supress_instrumentation functionality in sqlalchemy instrumentation #3477

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

Merged
merged 7 commits into from
May 30, 2025

Conversation

marcm-ml
Copy link
Contributor

@marcm-ml marcm-ml commented May 8, 2025

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes #3454

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Run this file via uv with my changes, i.e. uv sync && uv run reproduce.py

# /// script
# requires-python = ">=3.12"
# dependencies = [
#     "opentelemetry-api",
#     "opentelemetry-sdk",
#     "sqlalchemy",
# ]
# ///

from sqlalchemy import create_engine

from opentelemetry import trace
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
from opentelemetry.instrumentation.utils import suppress_instrumentation
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
    ConsoleSpanExporter,
    SimpleSpanProcessor,
)

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

tracer = trace.get_tracer(__name__)

engine = create_engine("sqlite:///:memory:")
SQLAlchemyInstrumentor().instrument(engine=engine)

# creates span
with engine.connect():
    pass

# no span
with suppress_instrumentation(), engine.connect():
    pass

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • 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 (no need)

Copy link

linux-foundation-easycla bot commented May 8, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@github-actions github-actions bot requested a review from shalevr May 8, 2025 09:44
@marcm-ml marcm-ml requested a review from a team as a code owner May 8, 2025 09:44
@marcm-ml
Copy link
Contributor Author

I have updated the changelog after release. Can you re-review?

Copy link
Contributor

@tammy-baylis-swi tammy-baylis-swi left a comment

Choose a reason for hiding this comment

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

Thanks again!

@marcm-ml
Copy link
Contributor Author

marcm-ml commented May 29, 2025

@shalevr give me a ping here if we are able to merge this, then I (or you) will update the changelog conflicts.

@xrmx xrmx enabled auto-merge (squash) May 30, 2025 15:50
@xrmx xrmx merged commit 77325aa into open-telemetry:main May 30, 2025
624 of 625 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQLAlchemy instrumentation does not respect suppress_instrumentation functionality
5 participants