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

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

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

**uv**

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

**pip**

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

```python title="psycopg_tracing.py"
from judgeval import Tracer
from opentelemetry.instrumentation.psycopg import PsycopgInstrumentor

Tracer.init(project_name="psycopg_app")
Tracer.registerOTELInstrumentation(PsycopgInstrumentor())

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