---
title: "Postgres.js"
description: "Adds instrumentation for the postgres (postgres.js) library."
url: https://docs.sentry.io/platforms/javascript/guides/deno/configuration/integrations/postgresjs/
---

# Postgres.js | Sentry for Deno

Available since: `v10.41.0`

*Import name: `Sentry.instrumentPostgresJsSql`*

The `instrumentPostgresJsSql` helper adds instrumentation for the [`postgres`](https://github.com/porsager/postgres) (postgres.js) library to capture spans by wrapping a postgres.js `sql` tagged-template instance. You need to manually wrap your `sql` instance with this helper:

## [Usage](https://docs.sentry.io/platforms/javascript/guides/deno/configuration/integrations/postgresjs.md#usage)

```javascript
import * as Sentry from "npm:@sentry/deno";
import postgres from "npm:postgres";

const sql = Sentry.instrumentPostgresJsSql(
  postgres("postgres://user:pass@localhost/mydb"),
);

// All queries now create Sentry spans
const users = await sql`SELECT * FROM users WHERE id = ${userId}`;
```

## [Options](https://docs.sentry.io/platforms/javascript/guides/deno/configuration/integrations/postgresjs.md#options)

### [`requireParentSpan`](https://docs.sentry.io/platforms/javascript/guides/deno/configuration/integrations/postgresjs.md#requireparentspan)

*Type: `boolean`*

Whether the instrumentation requires a parent span to create child spans. When set to `true`, spans are only created if there is an active parent span in the current scope.

Default: `true`

### [`requestHook`](https://docs.sentry.io/platforms/javascript/guides/deno/configuration/integrations/postgresjs.md#requesthook)

*Type: `(span: Span, sanitizedSqlQuery: string, postgresConnectionContext?: PostgresConnectionContext) => void`*

A hook called before each span is started. Use it to set additional attributes or modify the span.

```javascript
const sql = Sentry.instrumentPostgresJsSql(postgres(env.DATABASE_URL), {
  requestHook(span, query) {
    span.setAttribute("custom.query", query);
  },
});
```
