Skip to content

Commit 88078a0

Browse files
authored
feat(core,cloudflare,deno): Add instrumentPostgresJsSql instrumentation (#19566)
This PR extracts parts from `@sentry/node`'s `PostgresJsInstrumentation` to `@sentry/core` and exposes it as a callable `instrumentPostgresJsSql` helper that can be used in SDKs that aren't based on OpenTelemetry. It is currently exposed in `@sentry/cloudflare` and `@sentry/deno` as these two SDKs are not based on OpenTelemetry under the hood. `@sentry/node` imports and reuses as much as possible from it. Closes #19567 (added automatically)
1 parent 43be7b0 commit 88078a0

File tree

7 files changed

+1090
-313
lines changed

7 files changed

+1090
-313
lines changed

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@
66

77
### Important Changes
88

9+
- **feat(core,cloudflare,deno): Add `instrumentPostgresJsSql` instrumentation**
10+
11+
Added a new instrumentation helper for the [`postgres`](https://github.com/porsager/postgres) (postgres.js) library, designed for
12+
SDKs that are not based on OpenTelemetry (e.g. Cloudflare, Deno). This wraps a postgres.js `sql` tagged template instance so that
13+
all queries automatically create Sentry spans.
14+
15+
```javascript
16+
import postgres from 'postgres';
17+
import * as Sentry from '@sentry/cloudflare'; // or '@sentry/deno'
18+
19+
export default Sentry.withSentry(env => ({ dsn: '__DSN__' }), {
20+
async fetch(request, env, ctx) {
21+
const sql = Sentry.instrumentPostgresJsSql(postgres(env.DATABASE_URL));
22+
23+
// All queries now create Sentry spans
24+
const users = await sql`SELECT * FROM users WHERE id = ${userId}`;
25+
return Response.json(users);
26+
},
27+
});
28+
```
29+
30+
The instrumentation is available in `@sentry/core`, `@sentry/cloudflare`, and `@sentry/deno`.
31+
932
- **feat(nextjs): Add Turbopack support for `thirdPartyErrorFilterIntegration` ([#19542](https://github.com/getsentry/sentry-javascript/pull/19542))**
1033

1134
We added experimental support for the `thirdPartyErrorFilterIntegration` with Turbopack builds.

packages/cloudflare/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export {
8585
moduleMetadataIntegration,
8686
supabaseIntegration,
8787
instrumentSupabaseClient,
88+
instrumentPostgresJsSql,
8889
zodErrorsIntegration,
8990
consoleIntegration,
9091
SEMANTIC_ATTRIBUTE_SENTRY_OP,

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export { dedupeIntegration } from './integrations/dedupe';
120120
export { extraErrorDataIntegration } from './integrations/extraerrordata';
121121
export { rewriteFramesIntegration } from './integrations/rewriteframes';
122122
export { supabaseIntegration, instrumentSupabaseClient } from './integrations/supabase';
123+
export { instrumentPostgresJsSql } from './integrations/postgresjs';
123124
export { zodErrorsIntegration } from './integrations/zoderrors';
124125
export { thirdPartyErrorFilterIntegration } from './integrations/third-party-errors-filter';
125126
export { consoleIntegration } from './integrations/console';

0 commit comments

Comments
 (0)