Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// <reference lib="deno.ns" />

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 { 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<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('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 () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The test suite doesn't reset the global installedIntegrations array between tests, causing subsequent tests to fail because the integration's setupOnce() is not re-run.
Severity: LOW

Suggested Fix

Reset the global installedIntegrations array between tests. This can be done in a beforeEach or afterEach block to ensure each test runs in a clean state, for example by clearing the array manually.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: dev-packages/deno-integration-tests/suites/orchestrion-langgraph/test.ts#L64

Potential issue: The test file contains multiple tests that initialize the Sentry SDK.
The first test correctly sets up the `langGraphChannelIntegration` and adds it to the
global `installedIntegrations` array. However, this global state is not reset before the
second test runs. Consequently, when the second test initializes the SDK, the
integration system sees that "LangGraph" is already installed and skips calling
`setupOnce()`. This prevents necessary channel subscriptions from being established for
the second test, leading to a failed assertion when an expected AI span is not created.
This is a bug in the test setup, not the production code.

Did we get this right? 👍 / 👎 to inform future reviews.

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<string, unknown> = { 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');
});
1 change: 1 addition & 0 deletions packages/deno/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export {
knexChannelIntegration,
koaChannelIntegration,
langChainChannelIntegration,
langGraphChannelIntegration,
lruMemoizerChannelIntegration,
mongodbChannelIntegration,
mongooseChannelIntegration,
Expand Down
2 changes: 2 additions & 0 deletions packages/deno/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
kafkajsChannelIntegration,
koaChannelIntegration,
langChainChannelIntegration,
langGraphChannelIntegration,
lruMemoizerChannelIntegration,
mongodbChannelIntegration,
mongooseChannelIntegration,
Expand Down Expand Up @@ -109,6 +110,7 @@ export function getDefaultIntegrations(_options: Options): Integration[] {
kafkajsChannelIntegration(),
koaChannelIntegration(),
langChainChannelIntegration(),
langGraphChannelIntegration(),
lruMemoizerChannelIntegration(),
mongodbChannelIntegration(),
mongooseChannelIntegration(),
Expand Down
4 changes: 4 additions & 0 deletions packages/deno/test/__snapshots__/mod.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ snapshot[`captureException 1`] = `
"Kafka",
"Koa",
"LangChain",
"LangGraph",
"LruMemoizer",
"Mongo",
"Mongoose",
Expand Down Expand Up @@ -225,6 +226,7 @@ snapshot[`captureMessage 1`] = `
"Kafka",
"Koa",
"LangChain",
"LangGraph",
"LruMemoizer",
"Mongo",
"Mongoose",
Expand Down Expand Up @@ -329,6 +331,7 @@ snapshot[`captureMessage twice 1`] = `
"Kafka",
"Koa",
"LangChain",
"LangGraph",
"LruMemoizer",
"Mongo",
"Mongoose",
Expand Down Expand Up @@ -440,6 +443,7 @@ snapshot[`captureMessage twice 2`] = `
"Kafka",
"Koa",
"LangChain",
"LangGraph",
"LruMemoizer",
"Mongo",
"Mongoose",
Expand Down
Loading