Skip to content

Commit 330cc4b

Browse files
authoredMay 23, 2024··
chore: Fixed aws-sdk-v3 bedrock tests (again) (#2212)
1 parent 050469e commit 330cc4b

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed
 

‎test/versioned/aws-sdk-v3/bedrock-chat-completions.tap.js

+17-21
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,6 @@ const createAiResponseServer = require('../../lib/aws-server-stubs/ai-server')
1313
const { FAKE_CREDENTIALS } = require('../../lib/aws-server-stubs')
1414
const { DESTINATIONS } = require('../../../lib/config/attribute-filter')
1515

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-
3116
const requests = {
3217
ai21: (prompt, modelId) => ({
3318
body: JSON.stringify({ prompt, temperature: 0.5, maxTokens: 100 }),
@@ -241,9 +226,10 @@ tap.afterEach(async (t) => {
241226
const command = new bedrock.InvokeModelCommand(input)
242227
helper.runInTransaction(agent, async (tx) => {
243228
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+
})
247233
t.equal(metrics.callCount > 0, true)
248234
tx.end()
249235
t.end()
@@ -588,9 +574,10 @@ tap.test('should not instrument stream when disabled', (t) => {
588574
t.equal(events.length, 0, 'should not create Llm events when streaming is disabled')
589575
const attributes = tx.trace.attributes.get(DESTINATIONS.TRANS_EVENT)
590576
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+
})
594581
t.equal(metrics.callCount > 0, true, 'should set framework metric')
595582
const supportabilityMetrics = agent.metrics.getOrCreateMetric(
596583
`Supportability/Nodejs/ML/Streaming/Disabled`
@@ -632,3 +619,12 @@ tap.test('should utilize tokenCountCallback when set', (t) => {
632619
t.end()
633620
})
634621
})
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

Comments
 (0)
Please sign in to comment.