-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(deno): add lruMemoizer integration #22453
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
Merged
isaacs
merged 1 commit into
isaacs/deno-orchestrion-integrations-genericpool
from
isaacs/deno-orchestrion-integrations-lrumemoizer
Jul 24, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
124 changes: 124 additions & 0 deletions
124
dev-packages/deno-integration-tests/suites/orchestrion-lru-memoizer/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| // <reference lib="deno.ns" /> | ||
|
|
||
| import { tracingChannel } from 'node:diagnostics_channel'; | ||
| import type { Span, TransactionEvent } from '@sentry/core'; | ||
| import type { DenoClient } from '@sentry/deno'; | ||
| import { | ||
| getActiveSpan, | ||
| getCurrentScope, | ||
| getGlobalScope, | ||
| getIsolationScope, | ||
| init, | ||
| startSpan, | ||
| startSpanManual, | ||
| } from '@sentry/deno'; | ||
| import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; | ||
| import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.ts'; | ||
| import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts'; | ||
|
|
||
| function resetGlobals(): void { | ||
| getCurrentScope().clear(); | ||
| getCurrentScope().setClient(undefined); | ||
| getIsolationScope().clear(); | ||
| getGlobalScope().clear(); | ||
| } | ||
|
|
||
| /** See deno-redis.test.ts — same sink shape, deduped for clarity. */ | ||
| function transactionSink(): { | ||
| beforeSendTransaction: (event: TransactionEvent) => null; | ||
| waitFor: (predicate: (event: TransactionEvent) => boolean) => Promise<TransactionEvent>; | ||
| } { | ||
| const transactions: TransactionEvent[] = []; | ||
| const waiters: { predicate: (e: TransactionEvent) => boolean; resolve: (e: TransactionEvent) => void }[] = []; | ||
| return { | ||
| beforeSendTransaction(event) { | ||
| transactions.push(event); | ||
| for (let i = waiters.length - 1; i >= 0; i--) { | ||
| const w = waiters[i]!; | ||
| if (w.predicate(event)) { | ||
| waiters.splice(i, 1); | ||
| w.resolve(event); | ||
| } | ||
| } | ||
| return null; | ||
| }, | ||
| waitFor(predicate) { | ||
| const already = transactions.find(predicate); | ||
| if (already) return Promise.resolve(already); | ||
| return new Promise<TransactionEvent>(resolve => { | ||
| waiters.push({ predicate, resolve }); | ||
| }); | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| function withTimeout<T>(p: Promise<T>, ms: number, what: string): Promise<T> { | ||
| let timer: ReturnType<typeof setTimeout> | undefined; | ||
| const timeout = new Promise<T>((_, reject) => { | ||
| timer = setTimeout(() => reject(new Error(`Timed out waiting for ${what} after ${ms}ms`)), ms); | ||
| }); | ||
| return Promise.race([p, timeout]).finally(() => { | ||
| if (timer !== undefined) clearTimeout(timer); | ||
| }); | ||
| } | ||
|
|
||
| Deno.test('lru-memoizer instrumentation: included in default integrations (Deno 2.8.0+)', () => { | ||
| resetGlobals(); | ||
| const client = init({ dsn: 'https://username@domain/123' }) as DenoClient; | ||
| const names = client.getOptions().integrations.map(i => i.name); | ||
| assert(names.includes('LruMemoizer'), `LruMemoizer should be in defaults, got ${names.join(', ')}`); | ||
| }); | ||
|
|
||
| // lru-memoizer creates no span of its own; it restores the caller's scope onto | ||
| // the memoized callback (which it fires from a detached `setImmediate`). We drive | ||
| // `start` while a parent span is active (capturing the caller's context), then | ||
| // drive `asyncStart` from a detached context where that span is NOT active — as | ||
| // happens when the callback fires later. Without the restore, work there starts a | ||
| // new trace; with it, the parent is active again and a span nests under it. | ||
| Deno.test('lru-memoizer instrumentation: restores the caller scope onto the memoized callback', async () => { | ||
| resetGlobals(); | ||
| const sink = transactionSink(); | ||
| init({ | ||
| dsn: 'https://username@domain/123', | ||
| tracesSampleRate: 1, | ||
| beforeSendTransaction: sink.beforeSendTransaction, | ||
| }); | ||
|
|
||
| const channel = tracingChannel('orchestrion:lru-memoizer:load'); | ||
| const ctx = { arguments: [] }; | ||
|
|
||
| let parentSpan: Span | undefined; | ||
| // `startSpanManual` leaves the span open after the callback but deactivates it, | ||
| // so the `asyncStart` below runs with no active span — a genuine detached context. | ||
| startSpanManual({ name: 'parent', op: 'test', forceTransaction: true }, span => { | ||
| parentSpan = span; | ||
| channel.start.runStores(ctx, () => undefined); | ||
| }); | ||
|
|
||
| // Detached: no active span here. | ||
| assertEquals(getActiveSpan(), undefined); | ||
|
|
||
| let restoredActive: Span | undefined; | ||
| channel.asyncStart.runStores(ctx, () => { | ||
| restoredActive = getActiveSpan(); | ||
| startSpan({ name: 'memoized-work', op: 'test' }, () => undefined); | ||
| }); | ||
| channel.asyncEnd.publish(ctx); | ||
| parentSpan!.end(); | ||
|
|
||
| // The callback saw the caller's span restored. | ||
| assertEquals(restoredActive, parentSpan); | ||
|
|
||
| const parent = await withTimeout( | ||
| sink.waitFor(t => t.transaction === 'parent'), | ||
| 5000, | ||
| "'parent' transaction", | ||
| ); | ||
|
|
||
| // The span created in the restored callback nested under the caller, not a new trace. | ||
| const child = parent.spans?.find(s => s.description === 'memoized-work'); | ||
| assertExists( | ||
| child, | ||
| `expected memoized-work nested under parent, got: ${parent.spans?.map(s => s.description).join(', ')}`, | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The Deno integration test for
LruMemoizerwill fail on Deno versions older than 2.8.0 because it lacks a version guard before asserting the integration is present.Severity: LOW
Suggested Fix
Add a version check at the beginning of the test to skip execution on Deno versions older than 2.8.0. Use the existing
gte()version helper function, similar to the pattern found inpackages/deno/test/deno-http.test.ts, to ensure the test only runs in compatible environments.Prompt for AI Agent
Also affects:
packages/deno/src/sdk.ts:82~84Did we get this right? 👍 / 👎 to inform future reviews.