feat(deno): add langchain integration - #22471
Conversation
816c7f6 to
0e76715
Compare
0e76715 to
760d0a9
Compare
760d0a9 to
5cf5d89
Compare
5cf5d89 to
9c44384
Compare
9c44384 to
92ba4f1
Compare
92ba4f1 to
59377c8
Compare
size-limit report 📦
|
59377c8 to
af052fe
Compare
af052fe to
1c2c8a1
Compare
| Deno.test('langchain 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('LangChain'), `LangChain should be in defaults, got ${names.join(', ')}`); | ||
| }); |
There was a problem hiding this comment.
Bug: A module-level subscribed flag causes test interference, as it is not reset between test runs, leading to subsequent test failures.
Severity: MEDIUM
Suggested Fix
Reset the state between tests. This can be achieved by adding a beforeEach or afterEach hook in the test suite to reset the subscribed flag. Alternatively, export a dedicated reset function from the langchain.ts module to be called between tests.
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-langchain/test.ts#L57-L62
Potential issue: A module-level `subscribed` flag in the LangChain integration causes
test interference. The first test to run calls `init()`, which sets the `subscribed`
flag to `true`. Because Deno tests in the same file run in the same process, they share
module state. When a subsequent test calls `init()`, its `setupOnce()` function sees
that `subscribed` is already `true` and returns early. This prevents crucial tracing
channel listeners from being attached, causing the test to fail its assertion when it
checks for the existence of a span.
Did we get this right? 👍 / 👎 to inform future reviews.
| Deno.test('langchain 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('LangChain'), `LangChain should be in defaults, got ${names.join(', ')}`); | ||
| }); |
There was a problem hiding this comment.
Bug: A module-level subscribed flag causes test interference, as it is not reset between test runs, leading to subsequent test failures.
Severity: MEDIUM
Suggested Fix
Reset the state between tests. This can be achieved by adding a beforeEach or afterEach hook in the test suite to reset the subscribed flag. Alternatively, export a dedicated reset function from the langchain.ts module to be called between tests.
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-langchain/test.ts#L57-L62
Potential issue: A module-level `subscribed` flag in the LangChain integration causes
test interference. The first test to run calls `init()`, which sets the `subscribed`
flag to `true`. Because Deno tests in the same file run in the same process, they share
module state. When a subsequent test calls `init()`, its `setupOnce()` function sees
that `subscribed` is already `true` and returns early. This prevents crucial tracing
channel listeners from being attached, causing the test to fail its assertion when it
checks for the existence of a span.
Did we get this right? 👍 / 👎 to inform future reviews.
71fd09f to
bc7c295
Compare
12112f2 to
43a3245
Compare
| Deno.test('langchain instrumentation: orchestrion @langchain/openai:embedQuery channel produces a nested embeddings span', async () => { | ||
| resetGlobals(); | ||
| const sink = transactionSink(); | ||
| init({ | ||
| dsn: 'https://username@domain/123', | ||
| tracesSampleRate: 1, | ||
| beforeSendTransaction: sink.beforeSendTransaction, | ||
| }); | ||
|
|
||
| const channel = tracingChannel('orchestrion:@langchain/openai:embedQuery'); | ||
|
|
There was a problem hiding this comment.
Bug: The module-level subscribed flag prevents re-initialization on subsequent init() calls within the same module, causing instrumentation to fail silently after the first call.
Severity: MEDIUM
Suggested Fix
The initialization logic should be made idempotent or the state should be resettable. The subscribed flag should be reset or handled in a way that allows init() to be called multiple times, ensuring that channel subscriptions are correctly re-established each time without breaking existing ones.
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-langchain/test.ts#L64-L74
Potential issue: A module-level `subscribed` flag prevents the LangChain integration
from being re-initialized if `init()` is called multiple times within the same module
context. The first call to `init()` sets `subscribed` to `true`. Subsequent calls will
cause the `setupOnce()` function to return early, preventing the
`waitForTracingChannelBinding()` callback from being invoked. This results in channel
subscriptions not being set up, and consequently, LangChain instrumentation spans will
not be created for any operations following the second `init()` call. This is not just a
test issue and can affect production applications that might re-initialize the
integration.
43a3245 to
b5df5c7
Compare
b5df5c7 to
bdf5a28
Compare
bdf5a28 to
329e686
Compare
No description provided.