mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-30 13:43:03 +08:00
Fix dbapi connection instrument wrapper has no _sock member (#1424)
Fixes https://github.com/open-telemetry/opentelemetry-python-contrib/issues/1353 Also: Fix the check for the connection already being instrumented in instrument_connection() Add tests for commit() and rollback() Add a couple missing docstring items. Add basepython to docker-tests to fix running the tests on macOS.
This commit is contained in:
@ -7,10 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Added
|
||||
|
||||
- `opentelemetry-instrumentation-pymysql` Add tests for commit() and rollback().
|
||||
([#1424](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1424))
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix bug in Urllib instrumentation - add status code to span attributes only if the status code is not None.
|
||||
([#1430](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1430))
|
||||
- `opentelemetry-instrumentation-pymysql` Fix dbapi connection instrument wrapper has no _sock member.
|
||||
([#1424](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1424))
|
||||
- `opentelemetry-instrumentation-dbapi` Fix the check for the connection already being instrumented in instrument_connection().
|
||||
([#1424](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1424))
|
||||
|
||||
## Version 1.14.0/0.35b0 (2022-11-03)
|
||||
|
||||
|
@ -79,6 +79,9 @@ def trace_integration(
|
||||
tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
|
||||
use. If omitted the current configured one is used.
|
||||
capture_parameters: Configure if db.statement.parameters should be captured.
|
||||
enable_commenter: Flag to enable/disable sqlcommenter.
|
||||
db_api_integration_factory: The `DatabaseApiIntegration` to use. If none is passed the
|
||||
default one is used.
|
||||
"""
|
||||
wrap_connect(
|
||||
__name__,
|
||||
@ -121,6 +124,8 @@ def wrap_connect(
|
||||
use. If omitted the current configured one is used.
|
||||
capture_parameters: Configure if db.statement.parameters should be captured.
|
||||
enable_commenter: Flag to enable/disable sqlcommenter.
|
||||
db_api_integration_factory: The `DatabaseApiIntegration` to use. If none is passed the
|
||||
default one is used.
|
||||
commenter_options: Configurations for tags to be appended at the sql query.
|
||||
|
||||
"""
|
||||
@ -197,7 +202,7 @@ def instrument_connection(
|
||||
Returns:
|
||||
An instrumented connection.
|
||||
"""
|
||||
if isinstance(connection, wrapt.ObjectProxy):
|
||||
if isinstance(connection, _TracedConnectionProxy):
|
||||
_logger.warning("Connection already instrumented")
|
||||
return connection
|
||||
|
||||
@ -331,6 +336,14 @@ def get_traced_connection_proxy(
|
||||
object.__getattribute__(self, "_connection"), name
|
||||
)
|
||||
|
||||
def __getattribute__(self, name):
|
||||
if object.__getattribute__(self, name):
|
||||
return object.__getattribute__(self, name)
|
||||
|
||||
return object.__getattribute__(
|
||||
object.__getattribute__(self, "_connection"), name
|
||||
)
|
||||
|
||||
def cursor(self, *args, **kwargs):
|
||||
return get_traced_cursor_proxy(
|
||||
self._connection.cursor(*args, **kwargs), db_api_integration
|
||||
|
@ -109,3 +109,19 @@ class TestFunctionalPyMysql(TestBase):
|
||||
):
|
||||
self._cursor.callproc("test", ())
|
||||
self.validate_spans("test")
|
||||
|
||||
def test_commit(self):
|
||||
stmt = "INSERT INTO test (id) VALUES (%s)"
|
||||
with self._tracer.start_as_current_span("rootSpan"):
|
||||
data = (("4",), ("5",), ("6",))
|
||||
self._cursor.executemany(stmt, data)
|
||||
self._connection.commit()
|
||||
self.validate_spans("INSERT")
|
||||
|
||||
def test_rollback(self):
|
||||
stmt = "INSERT INTO test (id) VALUES (%s)"
|
||||
with self._tracer.start_as_current_span("rootSpan"):
|
||||
data = (("7",), ("8",), ("9",))
|
||||
self._cursor.executemany(stmt, data)
|
||||
self._connection.rollback()
|
||||
self.validate_spans("INSERT")
|
||||
|
Reference in New Issue
Block a user