11/*
2- * Copyright 2024 New Relic Corporation. All rights reserved.
2+ * Copyright 2025 New Relic Corporation. All rights reserved.
33 * SPDX-License-Identifier: Apache-2.0
44 */
55
@@ -15,7 +15,6 @@ const {
1515 filterLangchainEvents,
1616 filterLangchainEventsByType
1717} = require ( './common' )
18- const { version : pkgVersion } = require ( '@langchain/core/package.json' )
1918const { DESTINATIONS } = require ( '../../../lib/config/attribute-filter' )
2019const helper = require ( '../../lib/agent_helper' )
2120
@@ -51,9 +50,8 @@ function runStreamingEnabledTests(config) {
5150
5251 return async ( t ) => {
5352 await t . test ( 'should log tracking metrics' , function ( t ) {
54- const { agent } = t . nr
55- const { version } = require ( '@langchain/core/package.json' )
56- assertPackageMetrics ( { agent, pkg : '@langchain/core' , version } )
53+ const { agent, langchainCoreVersion } = t . nr
54+ assertPackageMetrics ( { agent, pkg : '@langchain/core' , version : langchainCoreVersion } )
5755 } )
5856
5957 await t . test ( 'should create langchain events for every stream call' , ( t , end ) => {
@@ -92,7 +90,7 @@ function runStreamingEnabledTests(config) {
9290 await t . test (
9391 'should increment tracking metric for each langchain chat prompt event' ,
9492 ( t , end ) => {
95- const { agent, prompt, outputParser, model } = t . nr
93+ const { agent, prompt, outputParser, model, langchainCoreVersion } = t . nr
9694
9795 helper . runInTransaction ( agent , async ( tx ) => {
9896 const input = inputData
@@ -104,7 +102,7 @@ function runStreamingEnabledTests(config) {
104102 }
105103
106104 const metrics = agent . metrics . getOrCreateMetric (
107- `Supportability/Nodejs/ML/Langchain/${ pkgVersion } `
105+ `Supportability/Nodejs/ML/Langchain/${ langchainCoreVersion } `
108106 )
109107 assert . equal ( metrics . callCount > 0 , true )
110108
@@ -220,8 +218,7 @@ function runStreamingEnabledTests(config) {
220218 await t . test (
221219 'should create langchain events for every stream call with parser that returns an array as output' ,
222220 ( t , end ) => {
223- const { CommaSeparatedListOutputParser } = require ( '@langchain/core/output_parsers' )
224- const { agent, prompt, model } = t . nr
221+ const { agent, prompt, model, CommaSeparatedListOutputParser } = t . nr
225222
226223 helper . runInTransaction ( agent , async ( tx ) => {
227224 const parser = new CommaSeparatedListOutputParser ( )
@@ -273,7 +270,7 @@ function runStreamingEnabledTests(config) {
273270 )
274271
275272 await t . test ( 'should add runId when a callback handler exists' , ( t , end ) => {
276- const { BaseCallbackHandler } = require ( '@langchain/core/callbacks/base' )
273+ const { BaseCallbackHandler } = t . nr
277274 let runId
278275 const cbHandler = BaseCallbackHandler . fromMethods ( {
279276 handleChainStart ( ...args ) {
@@ -310,7 +307,7 @@ function runStreamingEnabledTests(config) {
310307 await t . test (
311308 'should create langchain events for every stream call on chat prompt + model + parser with callback' ,
312309 ( t , end ) => {
313- const { BaseCallbackHandler } = require ( '@langchain/core/callbacks/base' )
310+ const { BaseCallbackHandler } = t . nr
314311 const cbHandler = BaseCallbackHandler . fromMethods ( {
315312 handleChainStart ( ) { }
316313 } )
@@ -469,7 +466,7 @@ function runStreamingEnabledTests(config) {
469466 )
470467
471468 await t . test ( 'should create error events from input' , ( t , end ) => {
472- const { ChatPromptTemplate } = require ( '@langchain/core/prompts' )
469+ const { ChatPromptTemplate } = t . nr
473470 const prompt = ChatPromptTemplate . fromMessages ( [
474471 [ 'assistant' , 'tell me short joke about {topic}' ]
475472 ] )
@@ -505,7 +502,7 @@ function runStreamingEnabledTests(config) {
505502 } )
506503
507504 await t . test ( 'should create error events when stream fails' , ( t , end ) => {
508- const { ChatPromptTemplate } = require ( '@langchain/core/prompts' )
505+ const { ChatPromptTemplate } = t . nr
509506 const prompt = ChatPromptTemplate . fromMessages ( [ [ errorPromptTemplate [ 0 ] , errorPromptTemplate [ 1 ] ] ] )
510507 const { agent, model, outputParser } = t . nr
511508
@@ -631,7 +628,7 @@ function runStreamingDisabledTest(config) {
631628 await t . test (
632629 'should not create llm events when `ai_monitoring.streaming.enabled` is false' ,
633630 ( t , end ) => {
634- const { agent, prompt, outputParser, model } = t . nr
631+ const { agent, prompt, outputParser, model, langchainCoreVersion } = t . nr
635632
636633 helper . runInTransaction ( agent , async ( tx ) => {
637634 const input = inputData
@@ -651,7 +648,7 @@ function runStreamingDisabledTest(config) {
651648 const events = agent . customEventAggregator . events . toArray ( )
652649 assert . equal ( events . length , 0 , 'should not create llm events when streaming is disabled' )
653650 const metrics = agent . metrics . getOrCreateMetric (
654- `Supportability/Nodejs/ML/Langchain/${ pkgVersion } `
651+ `Supportability/Nodejs/ML/Langchain/${ langchainCoreVersion } `
655652 )
656653 assert . equal ( metrics . callCount > 0 , true )
657654 const attributes = tx . trace . attributes . get ( DESTINATIONS . TRANS_EVENT )
0 commit comments