@@ -18,10 +18,14 @@ class LangchainRunnableStreamSubscriber extends LangchainSubscriber {
1818
1919 handler ( data , ctx ) {
2020 const { agent, logger } = this
21+ // We need these checks inside the handler because it is possible for monitoring
22+ // to be disabled at the account level. In such a case, the value is set
23+ // after the instrumentation has been initialized.
24+ if ( ! agent ?. config ?. ai_monitoring ?. enabled ) {
25+ this . logger . debug ( 'Langchain instrumentation is disabled. To enable, set `config.ai_monitoring.enabled` to true.' )
26+ return ctx
27+ }
2128 if ( ! agent . config ?. ai_monitoring ?. streaming ?. enabled ) {
22- // We need this check inside the handler because it is possible for monitoring
23- // to be disabled at the account level. In such a case, the value is set
24- // after the instrumentation has been initialized.
2529 logger . warn ( '`ai_monitoring.streaming.enabled` is set to `false`, stream will not be instrumented.' )
2630 agent . metrics . getOrCreateMetric ( STREAMING_DISABLED ) . incrementCallCount ( )
2731 agent . metrics
@@ -44,12 +48,6 @@ class LangchainRunnableStreamSubscriber extends LangchainSubscriber {
4448 if ( transaction ?. isActive ( ) !== true ) {
4549 return
4650 }
47- if ( ! this ?. agent ?. config ?. ai_monitoring ?. streaming ?. enabled ) {
48- // ideally, we'd never get here because `handler` this case,
49- // but the config could possibly get changed in-between the two
50- // logger warning and metric creation is handled by `handler` so just return here
51- return
52- }
5351
5452 const request = data ?. arguments ?. [ 0 ]
5553 const params = data ?. arguments ?. [ 1 ] || { }
0 commit comments