From bae2a187095b0efc762863422dce02c70da9dab2 Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 21 Jul 2026 13:45:08 -0700 Subject: [PATCH] feat(deno): add langgraph integration Also, abstract out test utils in deno-integration-tests --- .../deno-integration-tests/src/index.ts | 59 +++++++++++++++++++ .../suites/orchestrion-amqplib/test.ts | 50 +--------------- .../suites/orchestrion-anthropic/test.ts | 50 +--------------- .../suites/orchestrion-aws/test.ts | 51 +--------------- .../suites/orchestrion-express/test.ts | 50 +--------------- .../suites/orchestrion-firebase/test.ts | 50 +--------------- .../suites/orchestrion-generic-pool/test.ts | 50 +--------------- .../suites/orchestrion-google-genai/test.ts | 50 +--------------- .../suites/orchestrion-graphql/test.ts | 50 +--------------- .../suites/orchestrion-hapi/test.ts | 50 +--------------- .../suites/orchestrion-kafkajs/test.ts | 50 +--------------- .../suites/orchestrion-koa/test.ts | 50 +--------------- .../suites/orchestrion-langchain/test.ts | 50 +--------------- .../suites/orchestrion-langgraph/test.ts | 53 +++++++++++++++++ .../suites/orchestrion-lru-memoizer/test.ts | 59 +------------------ .../suites/orchestrion-mongo/test.ts | 50 +--------------- .../suites/orchestrion-mongoose/test.ts | 50 +--------------- .../suites/orchestrion-mysql/test.ts | 50 +--------------- .../suites/orchestrion-mysql2/test.ts | 50 +--------------- .../suites/orchestrion-openai/test.ts | 50 +--------------- .../suites/orchestrion-postgres/test.ts | 50 +--------------- .../suites/orchestrion-postgresjs/test.ts | 50 +--------------- .../suites/orchestrion-tedious/test.ts | 50 +--------------- .../suites/orchestrion-vercel-ai/test.ts | 50 +--------------- .../deno-integration-tests/tsconfig.json | 2 +- packages/deno/src/index.ts | 1 + packages/deno/src/sdk.ts | 2 + .../deno/test/__snapshots__/mod.test.ts.snap | 4 ++ 28 files changed, 166 insertions(+), 1065 deletions(-) create mode 100644 dev-packages/deno-integration-tests/src/index.ts create mode 100644 dev-packages/deno-integration-tests/suites/orchestrion-langgraph/test.ts diff --git a/dev-packages/deno-integration-tests/src/index.ts b/dev-packages/deno-integration-tests/src/index.ts new file mode 100644 index 000000000000..272d4b988997 --- /dev/null +++ b/dev-packages/deno-integration-tests/src/index.ts @@ -0,0 +1,59 @@ +import type { TransactionEvent } from '@sentry/core'; +import { getCurrentScope, getGlobalScope, getIsolationScope } from '@sentry/deno'; + +/** + * Clear the current, isolation, and global scopes and detach the client so each + * test starts from a clean slate. + */ +export function resetGlobals(): void { + getCurrentScope().clear(); + getCurrentScope().setClient(undefined); + getIsolationScope().clear(); + getGlobalScope().clear(); +} + +export interface TransactionSink { + beforeSendTransaction: (event: TransactionEvent) => null; + waitFor: (predicate: (event: TransactionEvent) => boolean) => Promise; +} + +/** + * A `beforeSendTransaction` hook that records every transaction and lets a test + * `await` the first one matching a predicate. `waitFor` resolves immediately if + * a match already arrived, so there is no ordering race with the hook. + */ +export function transactionSink(): TransactionSink { + 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(resolve => { + waiters.push({ predicate, resolve }); + }); + }, + }; +} + +/** Reject with a descriptive message if `p` does not settle within `ms`. */ +export function withTimeout(p: Promise, ms: number, what: string): Promise { + let timer: ReturnType | undefined; + const timeout = new Promise((_, 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); + }); +} diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-amqplib/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-amqplib/test.ts index e29cae5eaff5..98cc26214026 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-amqplib/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-amqplib/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } from '@sentry/deno'; import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts'; import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('amqplib instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-anthropic/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-anthropic/test.ts index f03d7450c6cb..3bbf14447d77 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-anthropic/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-anthropic/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } from '@sentry/deno'; import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts'; import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('anthropic instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-aws/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-aws/test.ts index ee9d529806e9..114a4441d6b6 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-aws/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-aws/test.ts @@ -1,58 +1,13 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { Span, TransactionEvent } from '@sentry/core'; +import type { Span } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, spanToJSON, startSpan } from '@sentry/deno'; +import { init, spanToJSON, startSpan } from '@sentry/deno'; import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts'; import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('aws-sdk instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-express/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-express/test.ts index 1e29b96b5314..5e1e09dd25cb 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-express/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-express/test.ts @@ -2,58 +2,12 @@ import { EventEmitter } from 'node:events'; import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } 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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('express instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-firebase/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-firebase/test.ts index e8625ddcac5d..a4a3c78474fc 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-firebase/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-firebase/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } from '@sentry/deno'; import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts'; import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('firebase instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-generic-pool/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-generic-pool/test.ts index f3b67fd84bd7..1e7f561ad8e1 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-generic-pool/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-generic-pool/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } 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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('generic-pool instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-google-genai/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-google-genai/test.ts index 4d9d6c5b7f86..b2e601b98507 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-google-genai/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-google-genai/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } from '@sentry/deno'; import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts'; import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('google-genai instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-graphql/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-graphql/test.ts index c6ce701e37ba..14e4e7a57ad8 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-graphql/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-graphql/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } 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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; // Drives one graphql parse channel and asserts the resulting nested span. The // composed integration subscribes to both the orchestrion channel (graphql diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-hapi/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-hapi/test.ts index 58c9a8d59815..df6b44e0a487 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-hapi/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-hapi/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } 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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('hapi instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-kafkajs/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-kafkajs/test.ts index 819de70e2c40..a435112a91c0 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-kafkajs/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-kafkajs/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } 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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('kafkajs instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-koa/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-koa/test.ts index 9aa1c89773fa..237ac63f51ab 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-koa/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-koa/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } from '@sentry/deno'; import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts'; import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('koa instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-langchain/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-langchain/test.ts index 2e64c059ac6c..acdf35ddbe25 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-langchain/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-langchain/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } from '@sentry/deno'; import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts'; import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('langchain instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-langgraph/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-langgraph/test.ts new file mode 100644 index 000000000000..e2ba9ece5630 --- /dev/null +++ b/dev-packages/deno-integration-tests/suites/orchestrion-langgraph/test.ts @@ -0,0 +1,53 @@ +// + +import { tracingChannel } from 'node:diagnostics_channel'; +import type { DenoClient } from '@sentry/deno'; +import { init, startSpan } from '@sentry/deno'; +import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; +import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts'; +import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.ts'; +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; + +Deno.test('langgraph 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('LangGraph'), `LangGraph should be in defaults, got ${names.join(', ')}`); +}); + +Deno.test('langgraph instrumentation: orchestrion stateGraphCompile channel produces a nested create_agent span', async () => { + resetGlobals(); + const sink = transactionSink(); + init({ + dsn: 'https://username@domain/123', + tracesSampleRate: 1, + beforeSendTransaction: sink.beforeSendTransaction, + }); + + const channel = tracingChannel('orchestrion:@langchain/langgraph:stateGraphCompile'); + + // `arguments[0]` is the compile options; `name` names the agent span. + const ctx: Record = { arguments: [{ name: 'my-agent' }] }; + + startSpan({ name: 'parent', op: 'test' }, () => { + channel.start.runStores(ctx, () => undefined); + ctx.result = {}; + channel.end.publish(ctx); + }); + + const parent = await withTimeout( + sink.waitFor(t => t.transaction === 'parent'), + 5000, + "'parent' transaction", + ); + + const aiSpan = parent.spans?.find(s => s.op === 'gen_ai.create_agent'); + assertExists( + aiSpan, + `expected a gen_ai.create_agent child span, got ops: ${parent.spans?.map(s => s.op).join(', ')}`, + ); + assertEquals(aiSpan!.description, 'create_agent my-agent'); + assertEquals(aiSpan!.data?.['gen_ai.operation.name'], 'create_agent'); + assertEquals(aiSpan!.data?.['gen_ai.agent.name'], 'my-agent'); + assertEquals(aiSpan!.data?.['sentry.origin'], 'auto.ai.langgraph'); +}); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-lru-memoizer/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-lru-memoizer/test.ts index 4cbdc3179943..33652636572b 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-lru-memoizer/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-lru-memoizer/test.ts @@ -1,66 +1,13 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { Span, TransactionEvent } from '@sentry/core'; +import type { Span } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { - getActiveSpan, - getCurrentScope, - getGlobalScope, - getIsolationScope, - init, - startSpan, - startSpanManual, -} from '@sentry/deno'; +import { getActiveSpan, 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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('lru-memoizer instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-mongo/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-mongo/test.ts index f11103cb9ae4..8cdb55e296bc 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-mongo/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-mongo/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } 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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('mongodb instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-mongoose/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-mongoose/test.ts index c720aefddae2..6fd6d10cb338 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-mongoose/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-mongoose/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } from '@sentry/deno'; import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts'; import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('mongoose instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-mysql/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-mysql/test.ts index a7c92d675f44..163a3113a376 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-mysql/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-mysql/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } 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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('mysql instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-mysql2/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-mysql2/test.ts index b0aef546de46..05eaee336596 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-mysql2/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-mysql2/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } 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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('mysql2 instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-openai/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-openai/test.ts index 84195f961ae0..34492cbf218f 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-openai/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-openai/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } from '@sentry/deno'; import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts'; import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('openai instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-postgres/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-postgres/test.ts index 4d08d5e2505b..fcc4ce6ebeb6 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-postgres/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-postgres/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } 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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('pg instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-postgresjs/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-postgresjs/test.ts index 17960406dec4..7b389269ed45 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-postgresjs/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-postgresjs/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } from '@sentry/deno'; import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts'; import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('postgres.js instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-tedious/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-tedious/test.ts index a5c22dff256b..108f648ef8a3 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-tedious/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-tedious/test.ts @@ -2,58 +2,12 @@ import { EventEmitter } from 'node:events'; import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } 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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('tedious instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/suites/orchestrion-vercel-ai/test.ts b/dev-packages/deno-integration-tests/suites/orchestrion-vercel-ai/test.ts index a452661027c7..994338a2bcbd 100644 --- a/dev-packages/deno-integration-tests/suites/orchestrion-vercel-ai/test.ts +++ b/dev-packages/deno-integration-tests/suites/orchestrion-vercel-ai/test.ts @@ -1,58 +1,12 @@ // import { tracingChannel } from 'node:diagnostics_channel'; -import type { TransactionEvent } from '@sentry/core'; import type { DenoClient } from '@sentry/deno'; -import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '@sentry/deno'; +import { init, startSpan } from '@sentry/deno'; import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts'; import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.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; -} { - 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(resolve => { - waiters.push({ predicate, resolve }); - }); - }, - }; -} - -function withTimeout(p: Promise, ms: number, what: string): Promise { - let timer: ReturnType | undefined; - const timeout = new Promise((_, 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); - }); -} +import { resetGlobals, transactionSink, withTimeout } from '../../src/index.ts'; Deno.test('vercel-ai instrumentation: included in default integrations (Deno 2.8.0+)', () => { resetGlobals(); diff --git a/dev-packages/deno-integration-tests/tsconfig.json b/dev-packages/deno-integration-tests/tsconfig.json index 5906a14b8872..cd6bd9e86747 100644 --- a/dev-packages/deno-integration-tests/tsconfig.json +++ b/dev-packages/deno-integration-tests/tsconfig.json @@ -1,6 +1,6 @@ { "extends": "../../tsconfig.json", - "include": ["suites/**/*"], + "include": ["src/**/*", "suites/**/*"], "compilerOptions": { "lib": ["esnext"], "target": "esnext" diff --git a/packages/deno/src/index.ts b/packages/deno/src/index.ts index 73035f7155b3..37fa55d43fd6 100644 --- a/packages/deno/src/index.ts +++ b/packages/deno/src/index.ts @@ -130,6 +130,7 @@ export { knexChannelIntegration, koaChannelIntegration, langChainChannelIntegration, + langGraphChannelIntegration, lruMemoizerChannelIntegration, mongodbChannelIntegration, mongooseChannelIntegration, diff --git a/packages/deno/src/sdk.ts b/packages/deno/src/sdk.ts index 95acaa34e30b..17f5ce854701 100644 --- a/packages/deno/src/sdk.ts +++ b/packages/deno/src/sdk.ts @@ -24,6 +24,7 @@ import { kafkajsChannelIntegration, koaChannelIntegration, langChainChannelIntegration, + langGraphChannelIntegration, lruMemoizerChannelIntegration, mongodbChannelIntegration, mongooseChannelIntegration, @@ -109,6 +110,7 @@ export function getDefaultIntegrations(_options: Options): Integration[] { kafkajsChannelIntegration(), koaChannelIntegration(), langChainChannelIntegration(), + langGraphChannelIntegration(), lruMemoizerChannelIntegration(), mongodbChannelIntegration(), mongooseChannelIntegration(), diff --git a/packages/deno/test/__snapshots__/mod.test.ts.snap b/packages/deno/test/__snapshots__/mod.test.ts.snap index 9ad6fe00f65a..8ed98ca84ae1 100644 --- a/packages/deno/test/__snapshots__/mod.test.ts.snap +++ b/packages/deno/test/__snapshots__/mod.test.ts.snap @@ -128,6 +128,7 @@ snapshot[`captureException 1`] = ` "Kafka", "Koa", "LangChain", + "LangGraph", "LruMemoizer", "Mongo", "Mongoose", @@ -225,6 +226,7 @@ snapshot[`captureMessage 1`] = ` "Kafka", "Koa", "LangChain", + "LangGraph", "LruMemoizer", "Mongo", "Mongoose", @@ -329,6 +331,7 @@ snapshot[`captureMessage twice 1`] = ` "Kafka", "Koa", "LangChain", + "LangGraph", "LruMemoizer", "Mongo", "Mongoose", @@ -440,6 +443,7 @@ snapshot[`captureMessage twice 2`] = ` "Kafka", "Koa", "LangChain", + "LangGraph", "LruMemoizer", "Mongo", "Mongoose",