@@ -13,21 +13,6 @@ const createAiResponseServer = require('../../lib/aws-server-stubs/ai-server')
13
13
const { FAKE_CREDENTIALS } = require ( '../../lib/aws-server-stubs' )
14
14
const { DESTINATIONS } = require ( '../../../lib/config/attribute-filter' )
15
15
16
- const pkgVersion = ( function ( ) {
17
- try {
18
- const { version } = require ( '@smithy/smithy-client/package.json' )
19
- return version
20
- } catch {
21
- try {
22
- const {
23
- version
24
- } = require ( './node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/smithy-client/package.json' )
25
- return version
26
- } catch { }
27
- }
28
- /* eslint-disable-next-line */
29
- } ( ) )
30
-
31
16
const requests = {
32
17
ai21 : ( prompt , modelId ) => ( {
33
18
body : JSON . stringify ( { prompt, temperature : 0.5 , maxTokens : 100 } ) ,
@@ -241,9 +226,10 @@ tap.afterEach(async (t) => {
241
226
const command = new bedrock . InvokeModelCommand ( input )
242
227
helper . runInTransaction ( agent , async ( tx ) => {
243
228
await client . send ( command )
244
- const metrics = agent . metrics . getOrCreateMetric (
245
- `Supportability/Nodejs/ML/Bedrock/${ pkgVersion } `
246
- )
229
+ const metrics = getPrefixedMetric ( {
230
+ agent,
231
+ metricPrefix : 'Supportability/Nodejs/ML/Bedrock'
232
+ } )
247
233
t . equal ( metrics . callCount > 0 , true )
248
234
tx . end ( )
249
235
t . end ( )
@@ -588,9 +574,10 @@ tap.test('should not instrument stream when disabled', (t) => {
588
574
t . equal ( events . length , 0 , 'should not create Llm events when streaming is disabled' )
589
575
const attributes = tx . trace . attributes . get ( DESTINATIONS . TRANS_EVENT )
590
576
t . equal ( attributes . llm , true , 'should assign llm attribute to transaction trace' )
591
- const metrics = agent . metrics . getOrCreateMetric (
592
- `Supportability/Nodejs/ML/Bedrock/${ pkgVersion } `
593
- )
577
+ const metrics = getPrefixedMetric ( {
578
+ agent,
579
+ metricPrefix : 'Supportability/Nodejs/ML/Bedrock'
580
+ } )
594
581
t . equal ( metrics . callCount > 0 , true , 'should set framework metric' )
595
582
const supportabilityMetrics = agent . metrics . getOrCreateMetric (
596
583
`Supportability/Nodejs/ML/Streaming/Disabled`
@@ -632,3 +619,12 @@ tap.test('should utilize tokenCountCallback when set', (t) => {
632
619
t . end ( )
633
620
} )
634
621
} )
622
+
623
+ function getPrefixedMetric ( { agent, metricPrefix } ) {
624
+ for ( const [ key , value ] of Object . entries ( agent . metrics . _metrics . unscoped ) ) {
625
+ if ( key . startsWith ( metricPrefix ) === false ) {
626
+ continue
627
+ }
628
+ return value
629
+ }
630
+ }
0 commit comments