Skip to content

feat: respect supress_instrumentation functionality in dbapi instrumentation #3460

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
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Fixed
- `opentelemetry-instrumentation-dbapi` Respect suppress_instrumentation functionality ([#3460](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3460))

### Breaking changes

- `opentelemetry-instrumentation-botocore` Use `cloud.region` instead of `aws.region` span attribute as per semantic conventions.
([#3474](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3474))


## Version 1.33.0/0.54b0 (2025-05-09)

### Added
Expand Down Expand Up @@ -44,7 +46,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `opentelemetry-instrumentation-botocore` Capture server attributes for botocore API calls
([#3448](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3448))


## Version 1.32.0/0.53b0 (2025-04-10)

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from opentelemetry.instrumentation.sqlcommenter_utils import _add_sql_comment
from opentelemetry.instrumentation.utils import (
_get_opentelemetry_values,
is_instrumentation_enabled,
unwrap,
)
from opentelemetry.semconv.trace import SpanAttributes
Expand Down Expand Up @@ -561,6 +562,9 @@ def traced_execution(
*args: tuple[Any, ...],
**kwargs: dict[Any, Any],
):
if not is_instrumentation_enabled():
return query_method(*args, **kwargs)

name = self.get_operation_name(cursor, args)
if not name:
name = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from opentelemetry import context
from opentelemetry import trace as trace_api
from opentelemetry.instrumentation import dbapi
from opentelemetry.instrumentation.utils import suppress_instrumentation
from opentelemetry.sdk import resources
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.test.test_base import TestBase
Expand Down Expand Up @@ -243,6 +244,21 @@ def test_no_op_tracer_provider(self):
spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 0)

def test_suppress_instrumentation(self):
db_integration = dbapi.DatabaseApiIntegration(
"instrumenting_module_test_name",
"testcomponent",
)
mock_connection = db_integration.wrapped_connection(
mock_connect, {}, {}
)
with suppress_instrumentation():
cursor = mock_connection.cursor()
cursor.execute("Test query", ("param1Value", False))

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 0)

def test_executemany(self):
db_integration = dbapi.DatabaseApiIntegration(
"instrumenting_module_test_name", "testcomponent"
Expand Down