opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentati...
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
..
src/opentelemetry/instrumentation/asyncpg fixed: asyncpg connection params are a namedtuple (#3253) 2025-02-14 08:59:21 +00:00
tests fix #991 audit asyncpg instrumentation with nooptracerprovider (#3144) 2025-01-09 14:51:23 -08:00
LICENSE fix: revert modifications to Apache license (#2429) 2024-04-22 13:23:38 -05:00
README.rst Added link to examples folder in each instrumentation (#438) 2021-04-13 14:56:30 -07:00
pyproject.toml Update version to 1.31.0.dev/0.52b0.dev (#3233) 2025-02-04 12:55:11 -08:00
test-requirements.txt asyncpg: bump version in test-requirements (#3146) 2024-12-23 17:47:09 +00:00

README.rst

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>`_