Skip to content
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

fix aiopg version #1473

Merged
merged 18 commits into from
Dec 20, 2022
Merged
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: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## Fixed

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


## Version 1.15.0/0.36b0 (2022-12-10)

- Add uninstrument test for sqlalchemy
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
| --------------- | ------------------ | --------------- |
| [opentelemetry-instrumentation-aio-pika](./opentelemetry-instrumentation-aio-pika) | aio_pika ~= 7.2.0 | No
| [opentelemetry-instrumentation-aiohttp-client](./opentelemetry-instrumentation-aiohttp-client) | aiohttp ~= 3.0 | No
| [opentelemetry-instrumentation-aiopg](./opentelemetry-instrumentation-aiopg) | aiopg >= 0.13.0, < 1.3.0 | No
| [opentelemetry-instrumentation-aiopg](./opentelemetry-instrumentation-aiopg) | aiopg >= 0.13.0, < 2.0.0 | No
| [opentelemetry-instrumentation-asgi](./opentelemetry-instrumentation-asgi) | asgiref ~= 3.0 | No
| [opentelemetry-instrumentation-asyncpg](./opentelemetry-instrumentation-asyncpg) | asyncpg >= 0.12.0 | No
| [opentelemetry-instrumentation-aws-lambda](./opentelemetry-instrumentation-aws-lambda) | aws_lambda | No
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies = [

[project.optional-dependencies]
instruments = [
"aiopg >= 0.13.0, < 1.3.0",
"aiopg >= 0.13.0, < 2.0.0",
]
test = [
"opentelemetry-instrumentation-aiopg[instruments]",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import asyncio
import typing
from collections.abc import Coroutine

import wrapt
from aiopg.utils import _ContextManager, _PoolAcquireContextManager

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

return AsyncCursorTracerProxy(cursor, *args, **kwargs)


class _ContextManager(Coroutine):
__slots__ = ("_coro", "_obj")

def __init__(self, coro):
self._coro = coro
self._obj = None

def send(self, value):
return self._coro.send(value)

def throw(self, typ, val=None, tb=None):
if val is None:
return self._coro.throw(typ)
if tb is None:
return self._coro.throw(typ, val)
return self._coro.throw(typ, val, tb)

def close(self):
return self._coro.close()

@property
def gi_frame(self):
return self._coro.gi_frame

@property
def gi_running(self):
return self._coro.gi_running

@property
def gi_code(self):
return self._coro.gi_code

def __next__(self):
return self.send(None)

def __await__(self):
resp = self._coro.__await__()
return resp

async def __aenter__(self):
self._obj = await self._coro
return self._obj

async def __aexit__(self, exc_type, exc, t_b):
try:
if asyncio.iscoroutinefunction(self._obj.close):
await self._obj.close()
else:
self._obj.close()
finally:
self._obj = None


class _PoolContextManager(_ContextManager):
__slots__ = ()

async def __aexit__(self, exc_type, exc, tb):
self._obj.close()
await self._obj.wait_closed()
self._obj = None


class _PoolAcquireContextManager(_ContextManager):
__slots__ = ("_coro", "_obj", "_pool")

def __init__(self, coro, pool):
super().__init__(coro)
self._pool = pool

async def __aexit__(self, exc_type, exc, tb):
await self._pool.release(self._obj)
self._pool = None
self._obj = None
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# limitations under the License.


_instruments = ("aiopg >= 0.13.0, < 1.3.0",)
_instruments = ("aiopg >= 0.13.0, < 2.0.0",)
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@

import aiopg
import wrapt
from aiopg.utils import ( # pylint: disable=no-name-in-module
_ContextManager,
_PoolContextManager,
)

from opentelemetry.instrumentation.aiopg.aiopg_integration import (
AiopgIntegration,
AsyncProxyObject,
_ContextManager,
_PoolContextManager,
get_traced_connection_proxy,
)
from opentelemetry.instrumentation.aiopg.version import __version__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@
from unittest.mock import MagicMock

import aiopg
from aiopg.utils import ( # pylint: disable=no-name-in-module
_ContextManager,
_PoolAcquireContextManager,
)

import opentelemetry.instrumentation.aiopg
from opentelemetry import trace as trace_api
from opentelemetry.instrumentation.aiopg import AiopgInstrumentor, wrappers
from opentelemetry.instrumentation.aiopg.aiopg_integration import (
AiopgIntegration,
_ContextManager,
_PoolAcquireContextManager,
)
from opentelemetry.sdk import resources
from opentelemetry.semconv.trace import SpanAttributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"instrumentation": "opentelemetry-instrumentation-aiohttp-client==0.37b0.dev",
},
"aiopg": {
"library": "aiopg >= 0.13.0, < 1.3.0",
"library": "aiopg >= 0.13.0, < 2.0.0",
"instrumentation": "opentelemetry-instrumentation-aiopg==0.37b0.dev",
},
"asgiref": {
Expand Down