From 54d24e484318befb5bed45387547412767f47667 Mon Sep 17 00:00:00 2001 From: Bob Evans Date: Wed, 5 Jun 2024 12:31:23 -0400 Subject: [PATCH] chore: backported the tracking metric matching as the smithy client version is different --- .../v3/bedrock-chat-completions.tap.js | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/versioned/v3/bedrock-chat-completions.tap.js b/tests/versioned/v3/bedrock-chat-completions.tap.js index bc7eab8..4abf051 100644 --- a/tests/versioned/v3/bedrock-chat-completions.tap.js +++ b/tests/versioned/v3/bedrock-chat-completions.tap.js @@ -11,7 +11,6 @@ utils(tap) const common = require('../common') const createAiResponseServer = require('@newrelic/test-utilities/lib/bedrock-server') const { FAKE_CREDENTIALS } = require('../aws-server-stubs') -const { version: pkgVersion } = require('@smithy/smithy-client/package.json') const { DESTINATIONS } = require('../../../lib/util') const requests = { @@ -240,9 +239,11 @@ tap.afterEach(async (t) => { const { agent } = helper helper.runInTransaction(async (tx) => { await client.send(command) - const metrics = agent.metrics.getOrCreateMetric( - `Supportability/Nodejs/ML/Bedrock/${pkgVersion}` - ) + const metrics = getPrefixedMetric({ + agent, + metricPrefix: 'Supportability/Nodejs/ML/Bedrock' + }) + t.equal(metrics.callCount > 0, true) tx.end() t.end() @@ -590,9 +591,10 @@ tap.test('should not instrument stream when disabled', (t) => { t.equal(events.length, 0, 'should not create Llm events when streaming is disabled') const attributes = tx.trace.attributes.get(DESTINATIONS.TRANS_EVENT) t.equal(attributes.llm, true, 'should assign llm attribute to transaction trace') - const metrics = agent.metrics.getOrCreateMetric( - `Supportability/Nodejs/ML/Bedrock/${pkgVersion}` - ) + const metrics = getPrefixedMetric({ + agent, + metricPrefix: 'Supportability/Nodejs/ML/Bedrock' + }) t.equal(metrics.callCount > 0, true, 'should set framework metric') const supportabilityMetrics = agent.metrics.getOrCreateMetric( `Supportability/Nodejs/ML/Streaming/Disabled` @@ -634,3 +636,13 @@ tap.test('should utilize tokenCountCallback when set', (t) => { t.end() }) }) + +// eslint-disable-next-line consistent-return +function getPrefixedMetric({ agent, metricPrefix }) { + for (const [key, value] of Object.entries(agent.metrics._metrics.unscoped)) { + if (key.startsWith(metricPrefix) === false) { + continue + } + return value + } +}