Skip to content

fix(node): Prevent duplicate LangChain spans from double module patching  #19685

@github-actions

Description

@github-actions

Note

The pull request "fix(node): Prevent duplicate LangChain spans from double module patching " was created by @nicohrubec but did not reference an issue. Therefore this issue was created for better visibility in external tools like Linear.

The LangChain instrumentation registers both a module-level and a file-level hook for each provider package (e.g. @langchain/openai). Both hooks call _patch, which wraps the same prototype methods (invoke, stream, batch) with a new
proxy and callback handler. This results in every LangChain call producing duplicate gen_ai.chat spans. The fix adds a __sentry_patched__ guard on the prototype to skip patching if it's already been done.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions