You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have some healthcheck functions that produce spans from sqlalchemy instrumentation we would like to suppress.
In order to do that, I guess it is best practice to use the suppress_instrumentation method from opentelemetry.instrumentations.util module. However, the SQLAlchemy instrumentation does not respect this and still produces spans and metrics.
Steps to Reproduce
using uv you can simply run this as is with uv run reproduce.py
reproduce.py:
# /// script# requires-python = ">=3.12"# dependencies = [# "opentelemetry-api",# "opentelemetry-instrumentation-sqlalchemy",# "opentelemetry-sdk",# "sqlalchemy",# ]# ///fromopentelemetryimporttracefromopentelemetry.instrumentation.sqlalchemyimportSQLAlchemyInstrumentorfromopentelemetry.instrumentation.utilsimportsuppress_instrumentationfromopentelemetry.sdk.traceimportTracerProviderfromopentelemetry.sdk.trace.exportimportBatchSpanProcessor, ConsoleSpanExporterfromsqlalchemyimportcreate_engineexporter=ConsoleSpanExporter()
provider=TracerProvider()
provider.add_span_processor(BatchSpanProcessor(exporter))
trace.set_tracer_provider(provider)
engine=create_engine("sqlite:///:memory:")
SQLAlchemyInstrumentor().instrument(engine=engine)
withengine.connect(): # produces spanspasswithsuppress_instrumentation(), engine.connect(): # should not produce spans but doespass
Expected Result
OTEL signals should not be produced when suppress_instrumentation is used.
Actual Result
OTEL signals are produced when suppress_instrumentation is used
Additional context
A fix can be implemented by using the is_instrumentation_enabled from opentelemetry.instrumentation.utils module everywhere in the engine.py module, i.e.:
Describe your environment
MacOS
python 3.12
opentelemetry-instrumentation-sqlalchemy v0.53b1
opentelemetry-api v1.32.1
opentelemetry-instrumentation v0.53b1
opentelemetry-semantic-conventions v0.53b1
What happened?
We have some healthcheck functions that produce spans from sqlalchemy instrumentation we would like to suppress.
In order to do that, I guess it is best practice to use the
suppress_instrumentation
method fromopentelemetry.instrumentations.util
module. However, the SQLAlchemy instrumentation does not respect this and still produces spans and metrics.Steps to Reproduce
using uv you can simply run this as is with
uv run reproduce.py
reproduce.py:
Expected Result
OTEL signals should not be produced when suppress_instrumentation is used.
Actual Result
OTEL signals are produced when suppress_instrumentation is used
Additional context
A fix can be implemented by using the
is_instrumentation_enabled
fromopentelemetry.instrumentation.utils
module everywhere in the engine.py module, i.e.:engine.py
If i use the code above and the reproduction script, I get the expected result where only 1 span is produced.
Would you like to implement a fix?
Yes
The text was updated successfully, but these errors were encountered: