Skip to content

Commit 0fe09bf

Browse files
committed
feat(deno): Expose knex orchestrion integration
Add an opt-in `denoKnexIntegration` that reuses the shared knex channel subscriber from `@sentry/server-utils` and installs Deno's AsyncLocalStorage context strategy, mirroring the other Deno DB integrations. Exported but kept out of the default set, matching knex being opt-in on Node.
1 parent e722370 commit 0fe09bf

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

packages/deno/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export { denoMysqlIntegration } from './integrations/mysql';
115115
export { denoPostgresIntegration } from './integrations/postgres';
116116
export { denoAmqplibIntegration } from './integrations/amqplib';
117117
export { denoDataloaderIntegration } from './integrations/dataloader';
118+
export { denoKnexIntegration } from './integrations/knex';
118119
export { denoContextIntegration } from './integrations/context';
119120
export { globalHandlersIntegration } from './integrations/globalhandlers';
120121
export { normalizePathsIntegration } from './integrations/normalizepaths';
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { knexChannelIntegration } from '@sentry/server-utils/orchestrion';
2+
import type { Integration, IntegrationFn } from '@sentry/core';
3+
import { defineIntegration, extendIntegration } from '@sentry/core';
4+
import { setAsyncLocalStorageAsyncContextStrategy } from '../async';
5+
6+
const INTEGRATION_NAME = 'DenoKnex' as const;
7+
8+
/**
9+
* Create spans for `knex` queries under Deno.
10+
*
11+
* `knex` channels are injected by the orchestrion runtime hook at load time.
12+
* The `@sentry/deno/import` loader must be active for this integration to
13+
* record anything.
14+
*
15+
* The channel-subscription logic is shared with the other server runtimes in
16+
* `@sentry/server-utils`. This just installs Deno's
17+
* `AsyncLocalStorage` context strategy (so spans nest under the active
18+
* span and survive knex's internal callback dispatch) before delegating.
19+
*/
20+
const _denoKnexIntegration = (() => {
21+
const inner = knexChannelIntegration();
22+
23+
return extendIntegration(inner, {
24+
name: INTEGRATION_NAME,
25+
setupOnce() {
26+
setAsyncLocalStorageAsyncContextStrategy();
27+
},
28+
});
29+
}) satisfies IntegrationFn;
30+
31+
export const denoKnexIntegration = defineIntegration(_denoKnexIntegration) as () => Integration & {
32+
name: 'DenoKnex';
33+
setupOnce: () => void;
34+
};

0 commit comments

Comments
 (0)