@@ -42,12 +42,15 @@ export class LangChainInstrumentation extends InstrumentationBase<any> {
42
42
toolsModule ?: any ;
43
43
} ) {
44
44
if ( chainsModule ) {
45
+ this . _diag . debug ( "Manually instrumenting langchain chains" ) ;
45
46
this . patchChainModule ( chainsModule ) ;
46
47
}
47
48
if ( agentsModule ) {
49
+ this . _diag . debug ( "Manually instrumenting langchain agents" ) ;
48
50
this . patchAgentModule ( agentsModule ) ;
49
51
}
50
52
if ( toolsModule ) {
53
+ this . _diag . debug ( "Manually instrumenting langchain tools" ) ;
51
54
this . patchToolsModule ( toolsModule ) ;
52
55
}
53
56
}
@@ -74,7 +77,12 @@ export class LangChainInstrumentation extends InstrumentationBase<any> {
74
77
return [ chainModule , agentModule , toolsModule ] ;
75
78
}
76
79
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
+
78
86
this . _wrap (
79
87
moduleExports . RetrievalQAChain . prototype ,
80
88
"_call" ,
@@ -92,7 +100,12 @@ export class LangChainInstrumentation extends InstrumentationBase<any> {
92
100
return moduleExports ;
93
101
}
94
102
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
+
96
109
this . _wrap (
97
110
moduleExports . AgentExecutor . prototype ,
98
111
"_call" ,
@@ -105,7 +118,12 @@ export class LangChainInstrumentation extends InstrumentationBase<any> {
105
118
return moduleExports ;
106
119
}
107
120
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
+
109
127
this . _wrap (
110
128
moduleExports . Tool . prototype ,
111
129
"call" ,
@@ -114,19 +132,31 @@ export class LangChainInstrumentation extends InstrumentationBase<any> {
114
132
return moduleExports ;
115
133
}
116
134
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
+
118
141
this . _unwrap ( moduleExports . RetrievalQAChain . prototype , "_call" ) ;
119
142
this . _unwrap ( moduleExports . BaseChain . prototype , "call" ) ;
120
143
return moduleExports ;
121
144
}
122
145
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
+
124
152
this . _unwrap ( moduleExports . AgentExecutor . prototype , "_call" ) ;
125
153
return moduleExports ;
126
154
}
127
155
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" ) ;
130
160
return moduleExports ;
131
161
}
132
162
0 commit comments