@@ -42,12 +42,15 @@ export class LangChainInstrumentation extends InstrumentationBase<any> {
4242 toolsModule ?: any ;
4343 } ) {
4444 if ( chainsModule ) {
45+ this . _diag . debug ( "Manually instrumenting langchain chains" ) ;
4546 this . patchChainModule ( chainsModule ) ;
4647 }
4748 if ( agentsModule ) {
49+ this . _diag . debug ( "Manually instrumenting langchain agents" ) ;
4850 this . patchAgentModule ( agentsModule ) ;
4951 }
5052 if ( toolsModule ) {
53+ this . _diag . debug ( "Manually instrumenting langchain tools" ) ;
5154 this . patchToolsModule ( toolsModule ) ;
5255 }
5356 }
@@ -74,7 +77,12 @@ export class LangChainInstrumentation extends InstrumentationBase<any> {
7477 return [ chainModule , agentModule , toolsModule ] ;
7578 }
7679
77- private patchChainModule ( moduleExports : typeof ChainsModule ) {
80+ private patchChainModule (
81+ moduleExports : typeof ChainsModule ,
82+ moduleVersion ?: string ,
83+ ) {
84+ this . _diag . debug ( `Patching langchain/chains.cjs@${ moduleVersion } ` ) ;
85+
7886 this . _wrap (
7987 moduleExports . RetrievalQAChain . prototype ,
8088 "_call" ,
@@ -92,7 +100,12 @@ export class LangChainInstrumentation extends InstrumentationBase<any> {
92100 return moduleExports ;
93101 }
94102
95- private patchAgentModule ( moduleExports : typeof AgentsModule ) {
103+ private patchAgentModule (
104+ moduleExports : typeof AgentsModule ,
105+ moduleVersion ?: string ,
106+ ) {
107+ this . _diag . debug ( `Patching langchain/agents.cjs@${ moduleVersion } ` ) ;
108+
96109 this . _wrap (
97110 moduleExports . AgentExecutor . prototype ,
98111 "_call" ,
@@ -105,7 +118,12 @@ export class LangChainInstrumentation extends InstrumentationBase<any> {
105118 return moduleExports ;
106119 }
107120
108- private patchToolsModule ( moduleExports : typeof ToolsModule ) {
121+ private patchToolsModule (
122+ moduleExports : typeof ToolsModule ,
123+ moduleVersion ?: string ,
124+ ) {
125+ this . _diag . debug ( `Patching langchain/tools.cjs@${ moduleVersion } ` ) ;
126+
109127 this . _wrap (
110128 moduleExports . Tool . prototype ,
111129 "call" ,
@@ -114,19 +132,31 @@ export class LangChainInstrumentation extends InstrumentationBase<any> {
114132 return moduleExports ;
115133 }
116134
117- private unpatchChainModule ( moduleExports : any ) {
135+ private unpatchChainModule (
136+ moduleExports : typeof ChainsModule ,
137+ moduleVersion ?: string ,
138+ ) {
139+ this . _diag . debug ( `Unpatching langchain/chains.cjs@${ moduleVersion } ` ) ;
140+
118141 this . _unwrap ( moduleExports . RetrievalQAChain . prototype , "_call" ) ;
119142 this . _unwrap ( moduleExports . BaseChain . prototype , "call" ) ;
120143 return moduleExports ;
121144 }
122145
123- private unpatchAgentModule ( moduleExports : any ) {
146+ private unpatchAgentModule (
147+ moduleExports : typeof AgentsModule ,
148+ moduleVersion ?: string ,
149+ ) {
150+ this . _diag . debug ( `Unpatching langchain/agents.cjs@${ moduleVersion } ` ) ;
151+
124152 this . _unwrap ( moduleExports . AgentExecutor . prototype , "_call" ) ;
125153 return moduleExports ;
126154 }
127155
128- private unpatchToolsModule ( moduleExports : any ) {
129- this . _unwrap ( moduleExports . AgentExecutor . prototype , "_call" ) ;
156+ private unpatchToolsModule ( moduleExports : typeof ToolsModule ) {
157+ this . _diag . debug ( `Unpatching langchain/tools.cjs` ) ;
158+
159+ this . _unwrap ( moduleExports . Tool . prototype , "call" ) ;
130160 return moduleExports ;
131161 }
132162
0 commit comments