Files
opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-asyncpg
Stephan Klein 1623dc0e71 fixed: asyncpg connection params are a namedtuple (#3253)
Follow-up on the apparently abbandonned https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2114.

The asyncpg instrumentation attempts to fall back on using the database
name as the span name in case the first argument to the instrumented
method is falsey.

This has probably never worked since asyncpg defines the `_params`
attribute as an instance of `ConnectionParams`
(https://github.com/MagicStack/asyncpg/blob/master/asyncpg/connection.py#L62)
which is a NamedTuple instance and thus don't define `get`. The proper
way of safely accessing properties on a NamedTuple is using `getattr`.

The only case that I've actually found which triggers this branch is if
the supplied query is an empty string. This is something that causes an
`AttributeError` for `Connection.execute` but is fine for `fetch()`,
`fetchval()`, `fetchrow()` and `executemany()`.

The tests have been expanded to check these cases. Also, more status
code validation has been added where it was missing.

Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
2025-02-14 08:59:21 +00:00
..

OpenTelemetry asyncpg Instrumentation
=====================================

|pypi|

.. |pypi| image:: https://badge.fury.io/py/opentelemetry-instrumentation-asyncpg.svg
   :target: https://pypi.org/project/opentelemetry-instrumentation-asyncpg/

This library allows tracing PostgreSQL queries made by the
`asyncpg <https://magicstack.github.io/asyncpg/current/>`_ library.

Installation
------------

::

     pip install opentelemetry-instrumentation-asyncpg

References
----------

* `OpenTelemetry asyncpg Instrumentation <https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/asyncpg/asyncpg.html>`_
* `OpenTelemetry Project <https://opentelemetry.io/>`_
* `OpenTelemetry Python Examples <https://github.com/open-telemetry/opentelemetry-python/tree/main/docs/examples>`_