Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
chore: backported the tracking metric matching as the smithy client v…
Browse files Browse the repository at this point in the history
…ersion is different
  • Loading branch information
bizob2828 committed Jun 5, 2024
1 parent 43ae4cd commit 54d24e4
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions tests/versioned/v3/bedrock-chat-completions.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
}
}

0 comments on commit 54d24e4

Please sign in to comment.