Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(node): Rewrite knex instrumentation to orchestrion tracing channels#22237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { knexChannelIntegration } from '@sentry/server-utils/orchestrion'; | ||
| import type { Integration, IntegrationFn } from '@sentry/core'; | ||
| import { defineIntegration, extendIntegration } from '@sentry/core'; | ||
| import { setAsyncLocalStorageAsyncContextStrategy } from '../async'; | ||
| const INTEGRATION_NAME = 'DenoKnex' as const; | ||
| /** | ||
| * Create spans for `knex` queries under Deno. | ||
| * | ||
| * `knex` channels are injected by the orchestrion runtime hook at load time. | ||
| * The `@sentry/deno/import` loader must be active for this integration to | ||
| * record anything. | ||
| * | ||
| * The channel-subscription logic is shared with the other server runtimes in | ||
| * `@sentry/server-utils`. This just installs Deno's | ||
| * `AsyncLocalStorage` context strategy (so spans nest under the active | ||
| * span and survive knex's internal callback dispatch) before delegating. | ||
| */ | ||
| const _denoKnexIntegration = (() => { | ||
| const inner = knexChannelIntegration(); | ||
| return extendIntegration(inner, { | ||
| name: INTEGRATION_NAME, | ||
| setupOnce() { | ||
| setAsyncLocalStorageAsyncContextStrategy(); | ||
| }, | ||
| }); | ||
| }) satisfies IntegrationFn; | ||
| export const denoKnexIntegration = defineIntegration(_denoKnexIntegration) as () => Integration & { | ||
| name: 'DenoKnex'; | ||
| setupOnce: () => void; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,6 +2,7 @@ import { KnexInstrumentation } from './vendored/instrumentation'; | ||
| import type { IntegrationFn } from '@sentry/core'; | ||
| import { defineIntegration } from '@sentry/core'; | ||
| import { generateInstrumentOnce } from '@sentry/node-core'; | ||
| import { isOrchestrionInjected, knexChannelIntegration } from '@sentry/server-utils/orchestrion'; | ||
| const INTEGRATION_NAME = 'Knex' as const; | ||
| @@ -11,7 +12,14 @@ const _knexIntegration = (() => { | ||
| return { | ||
| name: INTEGRATION_NAME, | ||
| setupOnce() { | ||
| instrumentKnex(); | ||
| // Prefer the diagnostics-channel subscriber when orchestrion injected its channels; otherwise | ||
| // fall back to the vendored OTel instrumentation. `isOrchestrionInjected()` is only reliable by | ||
| // `setupOnce` (the runtime injection runs during `Sentry.init()`, after integrations are built). | ||
| if (isOrchestrionInjected()) { | ||
| knexChannelIntegration().setupOnce?.(); | ||
cursor[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } else { | ||
| instrumentKnex(); | ||
| } | ||
| }, | ||
| }; | ||
| }) satisfies IntegrationFn; | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.