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

AiopgInstrumentor: aiopg.connect() failure with AttributeError: __aexit__ #1448

Closed
pocman opened this issue Dec 4, 2020 · 1 comment · Fixed by open-telemetry/opentelemetry-python-contrib#235
Labels
bug Something isn't working

Comments

@pocman
Copy link

pocman commented Dec 4, 2020

Describe your environment
Ubuntu, python 3.6, aiopg 1.0.0, opentelemetry 0.16b1

Steps to reproduce
On a working flask application using aiopg like here to https://github.com/miguelgrinberg/python-web-perf/blob/master/src/async_db.py

from opentelemetry import trace
from opentelemetry.exporter import zipkin
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
from opentelemetry.instrumentation.aiohttp_client import create_trace_config
from opentelemetry.instrumentation.aiopg import AiopgInstrumentor

asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
loop = asyncio.get_event_loop()

app = flask.Flask("python-web-perf")

# opentelemetry
trace.set_tracer_provider(TracerProvider())
zipkin_exporter = zipkin.ZipkinSpanExporter(
    service_name="app_asyncio_flask",
    url=f'http://{zipkin_host}:9411/api/v2/spans',
)
trace.get_tracer_provider().add_span_processor(
    BatchExportSpanProcessor(zipkin_exporter)
)

app = flask.Flask(__name__)
FlaskInstrumentor().instrument_app(app)
AiopgInstrumentor().instrument()

What is the expected behavior?
I expect the postgresql span to be available in zipkin.

What is the actual behavior?

The aiopg.connect call fail with the following exception.

Traceback (most recent call last):
  File "/home/tpocreau/.venv/web-perf/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/tpocreau/.venv/web-perf/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/tpocreau/.venv/web-perf/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/tpocreau/.venv/web-perf/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/tpocreau/.venv/web-perf/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/tpocreau/.venv/web-perf/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/tpocreau/wk/python-web-perf/src/app_asyncio_flask.py", line 76, in test
    fetch(feature_store_url),
  File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
  File "/home/tpocreau/wk/python-web-perf/src/async_db.py", line 11, in get_row
    async with aiopg.connect(database='test', user='test', password='test', host=pg_host) as conn:
AttributeError: __aexit__

Without the AiopgInstrumentor().instrument() line, the application is running as expected.

Additional context
I replaced aiopg by asyncpg, and everything is working as expected (span is available in zipkin).

image

async def get_row_asyncpg():
    conn = await asyncpg.connect(user='test', password='test',
                                 database='test', host=pg_host)
    index = random.randint(1, max_n)
    values = await conn.execute(
        f'select pg_sleep({delay}); select a, b from test where a = {index}'
    )
    await conn.close()
    return values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant