Skip to content

Commit 5af3519

Browse files
authored
fix aiopg version (#1473)
1 parent 7f8fe69 commit 5af3519

File tree

8 files changed

+90
-13
lines changed

8 files changed

+90
-13
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## Fixed
11+
12+
- Fix aiopg instrumentation to work with aiopg < 2.0.0
13+
([#1473](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1473))
1014
- `opentelemetry-instrumentation-aws-lambda` Adds an option to configure `disable_aws_context_propagation` by
1115
environment variable: `OTEL_LAMBDA_DISABLE_AWS_CONTEXT_PROPAGATION`
1216
([#1507](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1507))
1317

18+
1419
## Version 1.15.0/0.36b0 (2022-12-10)
1520

1621
- Add uninstrument test for sqlalchemy

instrumentation/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
| --------------- | ------------------ | --------------- |
44
| [opentelemetry-instrumentation-aio-pika](./opentelemetry-instrumentation-aio-pika) | aio_pika ~= 7.2.0 | No
55
| [opentelemetry-instrumentation-aiohttp-client](./opentelemetry-instrumentation-aiohttp-client) | aiohttp ~= 3.0 | No
6-
| [opentelemetry-instrumentation-aiopg](./opentelemetry-instrumentation-aiopg) | aiopg >= 0.13.0, < 1.3.0 | No
6+
| [opentelemetry-instrumentation-aiopg](./opentelemetry-instrumentation-aiopg) | aiopg >= 0.13.0, < 2.0.0 | No
77
| [opentelemetry-instrumentation-asgi](./opentelemetry-instrumentation-asgi) | asgiref ~= 3.0 | No
88
| [opentelemetry-instrumentation-asyncpg](./opentelemetry-instrumentation-asyncpg) | asyncpg >= 0.12.0 | No
99
| [opentelemetry-instrumentation-aws-lambda](./opentelemetry-instrumentation-aws-lambda) | aws_lambda | No

instrumentation/opentelemetry-instrumentation-aiopg/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dependencies = [
3333

3434
[project.optional-dependencies]
3535
instruments = [
36-
"aiopg >= 0.13.0, < 1.3.0",
36+
"aiopg >= 0.13.0, < 2.0.0",
3737
]
3838
test = [
3939
"opentelemetry-instrumentation-aiopg[instruments]",

instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py

+77-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import asyncio
12
import typing
3+
from collections.abc import Coroutine
24

35
import wrapt
4-
from aiopg.utils import _ContextManager, _PoolAcquireContextManager
56

67
from opentelemetry.instrumentation.dbapi import (
78
CursorTracer,
@@ -150,3 +151,78 @@ async def callproc(self, *args, **kwargs):
150151
return result
151152

152153
return AsyncCursorTracerProxy(cursor, *args, **kwargs)
154+
155+
156+
class _ContextManager(Coroutine):
157+
__slots__ = ("_coro", "_obj")
158+
159+
def __init__(self, coro):
160+
self._coro = coro
161+
self._obj = None
162+
163+
def send(self, value):
164+
return self._coro.send(value)
165+
166+
def throw(self, typ, val=None, tb=None):
167+
if val is None:
168+
return self._coro.throw(typ)
169+
if tb is None:
170+
return self._coro.throw(typ, val)
171+
return self._coro.throw(typ, val, tb)
172+
173+
def close(self):
174+
return self._coro.close()
175+
176+
@property
177+
def gi_frame(self):
178+
return self._coro.gi_frame
179+
180+
@property
181+
def gi_running(self):
182+
return self._coro.gi_running
183+
184+
@property
185+
def gi_code(self):
186+
return self._coro.gi_code
187+
188+
def __next__(self):
189+
return self.send(None)
190+
191+
def __await__(self):
192+
resp = self._coro.__await__()
193+
return resp
194+
195+
async def __aenter__(self):
196+
self._obj = await self._coro
197+
return self._obj
198+
199+
async def __aexit__(self, exc_type, exc, t_b):
200+
try:
201+
if asyncio.iscoroutinefunction(self._obj.close):
202+
await self._obj.close()
203+
else:
204+
self._obj.close()
205+
finally:
206+
self._obj = None
207+
208+
209+
class _PoolContextManager(_ContextManager):
210+
__slots__ = ()
211+
212+
async def __aexit__(self, exc_type, exc, tb):
213+
self._obj.close()
214+
await self._obj.wait_closed()
215+
self._obj = None
216+
217+
218+
class _PoolAcquireContextManager(_ContextManager):
219+
__slots__ = ("_coro", "_obj", "_pool")
220+
221+
def __init__(self, coro, pool):
222+
super().__init__(coro)
223+
self._pool = pool
224+
225+
async def __aexit__(self, exc_type, exc, tb):
226+
await self._pool.release(self._obj)
227+
self._pool = None
228+
self._obj = None

instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/package.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# limitations under the License.
1414

1515

16-
_instruments = ("aiopg >= 0.13.0, < 1.3.0",)
16+
_instruments = ("aiopg >= 0.13.0, < 2.0.0",)

instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/wrappers.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@
3434

3535
import aiopg
3636
import wrapt
37-
from aiopg.utils import ( # pylint: disable=no-name-in-module
38-
_ContextManager,
39-
_PoolContextManager,
40-
)
4137

4238
from opentelemetry.instrumentation.aiopg.aiopg_integration import (
4339
AiopgIntegration,
4440
AsyncProxyObject,
41+
_ContextManager,
42+
_PoolContextManager,
4543
get_traced_connection_proxy,
4644
)
4745
from opentelemetry.instrumentation.aiopg.version import __version__

instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@
1717
from unittest.mock import MagicMock
1818

1919
import aiopg
20-
from aiopg.utils import ( # pylint: disable=no-name-in-module
21-
_ContextManager,
22-
_PoolAcquireContextManager,
23-
)
2420

2521
import opentelemetry.instrumentation.aiopg
2622
from opentelemetry import trace as trace_api
2723
from opentelemetry.instrumentation.aiopg import AiopgInstrumentor, wrappers
2824
from opentelemetry.instrumentation.aiopg.aiopg_integration import (
2925
AiopgIntegration,
26+
_ContextManager,
27+
_PoolAcquireContextManager,
3028
)
3129
from opentelemetry.sdk import resources
3230
from opentelemetry.semconv.trace import SpanAttributes

opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"instrumentation": "opentelemetry-instrumentation-aiohttp-client==0.37b0.dev",
2626
},
2727
"aiopg": {
28-
"library": "aiopg >= 0.13.0, < 1.3.0",
28+
"library": "aiopg >= 0.13.0, < 2.0.0",
2929
"instrumentation": "opentelemetry-instrumentation-aiopg==0.37b0.dev",
3030
},
3131
"asgiref": {

0 commit comments

Comments
 (0)