---
title: "Asyncpg Tracing"
description: "Trace Asyncpg PostgreSQL spans with Judgment."
sidebar:
  label: "Asyncpg"
seo:
  title: "Asyncpg Tracing with Judgment | Integration Docs"
  description: "Trace Asyncpg spans with Judgment to connect application behavior to production AI agent monitoring and evaluation."
---

Asyncpg tracing uses the standard OpenTelemetry Asyncpg instrumentation and
routes PostgreSQL spans through Judgment.

{/* @test-flow
  id: tracing-db-asyncpg
  lang: python
  env: JUDGMENT_API_KEY, JUDGMENT_ORG_ID
*/}

**uv**

```bash
uv add judgeval asyncpg opentelemetry-instrumentation-asyncpg
```

**pip**

```bash
pip install judgeval asyncpg opentelemetry-instrumentation-asyncpg
```

```python title="asyncpg_tracing.py"
from judgeval import Tracer
from opentelemetry.instrumentation.asyncpg import AsyncPGInstrumentor

Tracer.init(project_name="asyncpg_app")
Tracer.registerOTELInstrumentation(AsyncPGInstrumentor())

# Create connections normally after registration.
# conn = await asyncpg.connect("postgresql://user:password@localhost/db")
# await conn.execute("select 1")
```
