Skip to content

Commit a467449

Browse files
committed
Add docstring and comments
1 parent 5a7615b commit a467449

File tree

1 file changed

+6
-0
lines changed
  • instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg

1 file changed

+6
-0
lines changed

instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@
4949

5050

5151
def _hydrate_span_from_args(connection, query, parameters) -> dict:
52+
"""Get network and database attributes from connection."""
5253
span_attributes = {"db.system": "postgresql"}
5354

55+
# connection contains _params attribute which is a namedtuple ConnectionParameters.
56+
# https://github.com/MagicStack/asyncpg/blob/master/asyncpg/connection.py#L68
57+
5458
params = getattr(connection, "_params", None)
5559
dbname = getattr(params, "database", None)
5660
if dbname:
@@ -59,6 +63,8 @@ def _hydrate_span_from_args(connection, query, parameters) -> dict:
5963
if user:
6064
span_attributes["db.user"] = user
6165

66+
# connection contains _addr attribute which is either a host/port tuple, or unix socket string
67+
# https://magicstack.github.io/asyncpg/current/_modules/asyncpg/connection.html
6268
addr = getattr(connection, "_addr", None)
6369
if isinstance(addr, tuple):
6470
span_attributes["net.peer.name"] = addr[0]

0 commit comments

Comments
 (0)