Skip to content

Commit 5b85f9a

Browse files
committed
patch all
1 parent 87cd986 commit 5b85f9a

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

packages/node/src/integrations/tracing/langchain/instrumentation.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -256,25 +256,20 @@ export class SentryLangChainInstrumentation extends InstrumentationBase<LangChai
256256
private _patchEmbeddingsMethods(exports: PatchedLangChainExports, options: LangChainOptions): void {
257257
const exportsToPatch = (exports.universal_exports ?? exports) as Record<string, unknown>;
258258

259-
const embeddingClass = Object.values(exportsToPatch).find(exp => {
259+
for (const exp of Object.values(exportsToPatch)) {
260260
if (typeof exp !== 'function' || !exp.prototype) {
261-
return false;
261+
continue;
262262
}
263263
const proto = exp.prototype as Record<string, unknown>;
264-
return typeof proto.embedQuery === 'function' && typeof proto.embedDocuments === 'function';
265-
}) as { prototype: Record<string, unknown> } | undefined;
266-
267-
if (!embeddingClass) {
268-
return;
269-
}
270-
271-
const targetProto = embeddingClass.prototype;
264+
if (typeof proto.embedQuery !== 'function' || typeof proto.embedDocuments !== 'function') {
265+
continue;
266+
}
267+
if (proto.__sentry_patched__) {
268+
continue;
269+
}
270+
proto.__sentry_patched__ = true;
272271

273-
if (targetProto.__sentry_patched__) {
274-
return;
272+
instrumentLangChainEmbeddings(proto, options);
275273
}
276-
targetProto.__sentry_patched__ = true;
277-
278-
instrumentLangChainEmbeddings(targetProto, options);
279274
}
280275
}

0 commit comments

Comments
 (0)