From f82ece5cd6038e5da7d5f6cc9ea9e927bffcb353 Mon Sep 17 00:00:00 2001 From: Amy Chisholm Date: Tue, 10 Sep 2024 07:25:00 -0700 Subject: [PATCH] refactor: metrics_helper to use `assert` --- test/lib/metrics_helper.js | 25 +++++---- .../bedrock-chat-completions.tap.js | 10 ++-- .../aws-sdk-v3/bedrock-embeddings.tap.js | 6 +-- .../aws-sdk-v3/bedrock-negative-tests.tap.js | 1 - .../express/client-disconnect.tap.js | 4 +- test/versioned/fastify/add-hook.tap.js | 6 +-- test/versioned/fastify/naming-common.js | 4 +- test/versioned/hapi/segments.tap.js | 12 ++--- test/versioned/ioredis/ioredis.tap.js | 4 +- test/versioned/koa/koa.tap.js | 8 +-- test/versioned/koa/router-common.js | 54 +++++++++---------- .../langchain/runnables-streaming.tap.js | 5 +- test/versioned/langchain/runnables.tap.js | 5 +- test/versioned/langchain/tools.tap.js | 5 +- test/versioned/langchain/vectorstore.tap.js | 5 +- test/versioned/nextjs/segments.tap.js | 8 +-- test/versioned/openai/chat-completions.tap.js | 9 ++-- test/versioned/openai/embeddings.tap.js | 4 +- test/versioned/restify/async-handlers.tap.js | 4 +- test/versioned/restify/restify.tap.js | 4 +- .../versioned/when/legacy-promise-segments.js | 26 ++++----- 21 files changed, 101 insertions(+), 108 deletions(-) diff --git a/test/lib/metrics_helper.js b/test/lib/metrics_helper.js index 7b9f9393f7..71512b4cf2 100644 --- a/test/lib/metrics_helper.js +++ b/test/lib/metrics_helper.js @@ -5,7 +5,6 @@ 'use strict' -const tap = require('tap') const assert = require('node:assert') const urltils = require('../../lib/util/urltils') const { isSimpleObject } = require('../../lib/util/objects') @@ -14,7 +13,7 @@ exports.findSegment = findSegment exports.getMetricHostName = getMetricHostName exports.assertMetrics = assertMetrics exports.assertMetricValues = assertMetricValues -tap.Test.prototype.addAssert('assertSegments', 3, assertSegments) +exports.assertSegments = assertSegments /** * @param {Metrics} metrics metrics under test @@ -148,33 +147,33 @@ function assertSegments(parent, expected, options) { if (typeof sequenceItem === 'string') { child = children[childCount++] - this.equal( + assert.equal( child ? child.name : undefined, sequenceItem, 'segment "' + - parent.name + - '" should have child "' + - sequenceItem + - '" in position ' + - childCount + parent.name + + '" should have child "' + + sequenceItem + + '" in position ' + + childCount ) // If the next expected item is not array, then check that the current // child has no children if (!Array.isArray(expected[i + 1])) { // var children = child.children - this.ok( + assert.ok( getChildren(child).length === 0, 'segment "' + child.name + '" should not have any children' ) } } else if (typeof sequenceItem === 'object') { - this.assertSegments(child, sequenceItem, options) + assertSegments(child, sequenceItem, options) } } // check if correct number of children was found - this.equal(children.length, childCount) + assert.equal(children.length, childCount) } else { for (let i = 0; i < expected.length; i++) { const sequenceItem = expected[i] @@ -186,9 +185,9 @@ function assertSegments(parent, expected, options) { child = parent.children[j] } } - this.ok(child, 'segment "' + parent.name + '" should have child "' + sequenceItem + '"') + assert.ok(child, 'segment "' + parent.name + '" should have child "' + sequenceItem + '"') if (typeof expected[i + 1] === 'object') { - this.assertSegments(child, expected[i + 1], exact) + assertSegments(child, expected[i + 1], exact) } } } diff --git a/test/versioned/aws-sdk-v3/bedrock-chat-completions.tap.js b/test/versioned/aws-sdk-v3/bedrock-chat-completions.tap.js index cda36a41cc..9ac1fc4fdf 100644 --- a/test/versioned/aws-sdk-v3/bedrock-chat-completions.tap.js +++ b/test/versioned/aws-sdk-v3/bedrock-chat-completions.tap.js @@ -8,7 +8,7 @@ const tap = require('tap') require('./common') const helper = require('../../lib/agent_helper') -require('../../lib/metrics_helper') +const { assertSegments } = require('../../lib/metrics_helper') const createAiResponseServer = require('../../lib/aws-server-stubs/ai-server') const { FAKE_CREDENTIALS } = require('../../lib/aws-server-stubs') const { DESTINATIONS } = require('../../../lib/config/attribute-filter') @@ -114,7 +114,7 @@ tap.afterEach(async (t) => { const body = JSON.parse(response.body.transformToString('utf8')) t.equal(response.$metadata.requestId, expected.headers['x-amzn-requestid']) t.same(body, expected.body) - t.assertSegments( + assertSegments( tx.trace.root, ['Llm/completion/Bedrock/InvokeModelCommand', [expectedExternalPath(modelId)]], { exact: false } @@ -316,7 +316,7 @@ tap.afterEach(async (t) => { } }) - t.assertSegments( + assertSegments( tx.trace.root, ['Llm/completion/Bedrock/InvokeModelCommand', [expectedExternalPath(modelId)]], { exact: false } @@ -457,7 +457,7 @@ tap.test(`ai21: should properly create errors on create completion (streamed)`, } }) - t.assertSegments( + assertSegments( tx.trace.root, [ 'Llm/completion/Bedrock/InvokeModelWithResponseStreamCommand', @@ -521,7 +521,7 @@ tap.test(`models that do not support streaming should be handled`, (t) => { } }) - t.assertSegments( + assertSegments( tx.trace.root, [ 'Llm/embedding/Bedrock/InvokeModelWithResponseStreamCommand', diff --git a/test/versioned/aws-sdk-v3/bedrock-embeddings.tap.js b/test/versioned/aws-sdk-v3/bedrock-embeddings.tap.js index 5290b67f4d..b0baa99db7 100644 --- a/test/versioned/aws-sdk-v3/bedrock-embeddings.tap.js +++ b/test/versioned/aws-sdk-v3/bedrock-embeddings.tap.js @@ -8,7 +8,7 @@ const tap = require('tap') require('./common') const helper = require('../../lib/agent_helper') -require('../../lib/metrics_helper') +const { assertSegments } = require('../../lib/metrics_helper') const createAiResponseServer = require('../../lib/aws-server-stubs/ai-server') const { FAKE_CREDENTIALS } = require('../../lib/aws-server-stubs') const { DESTINATIONS } = require('../../../lib/config/attribute-filter') @@ -77,7 +77,7 @@ tap.afterEach(async (t) => { const body = JSON.parse(response.body.transformToString('utf8')) t.equal(response.$metadata.requestId, expected.headers['x-amzn-requestid']) t.same(body, expected.body) - t.assertSegments( + assertSegments( tx.trace.root, ['Llm/embedding/Bedrock/InvokeModelCommand', [expectedExternalPath(modelId)]], { exact: false } @@ -168,7 +168,7 @@ tap.afterEach(async (t) => { } }) - t.assertSegments( + assertSegments( tx.trace.root, ['Llm/embedding/Bedrock/InvokeModelCommand', [expectedExternalPath(modelId)]], { exact: false } diff --git a/test/versioned/aws-sdk-v3/bedrock-negative-tests.tap.js b/test/versioned/aws-sdk-v3/bedrock-negative-tests.tap.js index cdf467bd3a..75cede0848 100644 --- a/test/versioned/aws-sdk-v3/bedrock-negative-tests.tap.js +++ b/test/versioned/aws-sdk-v3/bedrock-negative-tests.tap.js @@ -8,7 +8,6 @@ const tap = require('tap') require('./common') const helper = require('../../lib/agent_helper') -require('../../lib/metrics_helper') const createAiResponseServer = require('../../lib/aws-server-stubs/ai-server') const { FAKE_CREDENTIALS } = require('../../lib/aws-server-stubs') const sinon = require('sinon') diff --git a/test/versioned/express/client-disconnect.tap.js b/test/versioned/express/client-disconnect.tap.js index 28ec65c153..f572883bbf 100644 --- a/test/versioned/express/client-disconnect.tap.js +++ b/test/versioned/express/client-disconnect.tap.js @@ -7,7 +7,7 @@ const tap = require('tap') const helper = require('../../lib/agent_helper') -require('../../lib/metrics_helper') +const { assertSegments } = require('../../lib/metrics_helper') const http = require('http') function generateApp(t) { @@ -46,7 +46,7 @@ tap.test('Client Premature Disconnection', (t) => { }) agent.on('transactionFinished', (transaction) => { - t.assertSegments( + assertSegments( transaction.trace.root, [ 'WebTransaction/Expressjs/POST//test', diff --git a/test/versioned/fastify/add-hook.tap.js b/test/versioned/fastify/add-hook.tap.js index c40182c03b..e3c1144140 100644 --- a/test/versioned/fastify/add-hook.tap.js +++ b/test/versioned/fastify/add-hook.tap.js @@ -7,7 +7,7 @@ const tap = require('tap') const helper = require('../../lib/agent_helper') -require('../../lib/metrics_helper') +const { assertSegments } = require('../../lib/metrics_helper') const common = require('./common') // all of these events fire before the route handler @@ -105,7 +105,7 @@ tap.test('fastify hook instrumentation', (t) => { ] ] } - t.assertSegments(transaction.trace.root, expectedSegments) + assertSegments(transaction.trace.root, expectedSegments) }) await fastify.listen(0) @@ -161,7 +161,7 @@ tap.test('fastify hook instrumentation', (t) => { ] } - t.assertSegments(transaction.trace.root, expectedSegments) + assertSegments(transaction.trace.root, expectedSegments) }) await fastify.listen(0) diff --git a/test/versioned/fastify/naming-common.js b/test/versioned/fastify/naming-common.js index 79f9c9875c..d2a22b298f 100644 --- a/test/versioned/fastify/naming-common.js +++ b/test/versioned/fastify/naming-common.js @@ -5,7 +5,7 @@ 'use strict' const { routesToTest, makeRequest } = require('./common') -require('../../lib/metrics_helper') +const { assertSegments } = require('../../lib/metrics_helper') const helper = require('../../lib/agent_helper') module.exports = function createTests(t, getExpectedSegments) { @@ -36,7 +36,7 @@ module.exports = function createTests(t, getExpectedSegments) { ] } - t.assertSegments(transaction.trace.root, expectedSegments) + assertSegments(transaction.trace.root, expectedSegments) }) await fastify.listen(0) diff --git a/test/versioned/hapi/segments.tap.js b/test/versioned/hapi/segments.tap.js index 90d745f893..fdd1995c14 100644 --- a/test/versioned/hapi/segments.tap.js +++ b/test/versioned/hapi/segments.tap.js @@ -8,7 +8,7 @@ const tap = require('tap') const helper = require('../../lib/agent_helper') const http = require('http') -require('../../lib/metrics_helper') +const { assertSegments, assertMetrics } = require('../../lib/metrics_helper') const NAMES = require('../../../lib/metrics/names') const utils = require('./hapi-utils') @@ -41,7 +41,7 @@ tap.test('Hapi segments', function (t) { runTest(t, function (segments, transaction) { checkMetrics(t, transaction.metrics, [NAMES.HAPI.MIDDLEWARE + 'myHandler//test']) - t.assertSegments(transaction.trace.root.children[0], [ + assertSegments(transaction.trace.root.children[0], [ NAMES.HAPI.MIDDLEWARE + 'myHandler//test' ]) t.end() @@ -63,7 +63,7 @@ tap.test('Hapi segments', function (t) { runTest(t, function (segments, transaction) { checkMetrics(t, transaction.metrics, [NAMES.HAPI.MIDDLEWARE + 'customHandler//test']) - t.assertSegments(transaction.trace.root.children[0], [ + assertSegments(transaction.trace.root.children[0], [ NAMES.HAPI.MIDDLEWARE + 'customHandler//test' ]) t.end() @@ -88,7 +88,7 @@ tap.test('Hapi segments', function (t) { NAMES.HAPI.MIDDLEWARE + '//onRequest', NAMES.HAPI.MIDDLEWARE + 'myHandler//test' ]) - t.assertSegments(transaction.trace.root.children[0], [ + assertSegments(transaction.trace.root.children[0], [ NAMES.HAPI.MIDDLEWARE + '//onRequest', NAMES.HAPI.MIDDLEWARE + 'myHandler//test' ]) @@ -118,7 +118,7 @@ tap.test('Hapi segments', function (t) { NAMES.HAPI.MIDDLEWARE + '//onRequest', NAMES.HAPI.MIDDLEWARE + 'customHandler//test' ]) - t.assertSegments(transaction.trace.root.children[0], [ + assertSegments(transaction.trace.root.children[0], [ NAMES.HAPI.MIDDLEWARE + '//onRequest', NAMES.HAPI.MIDDLEWARE + 'customHandler//test' ]) @@ -284,5 +284,5 @@ function checkMetrics(t, metrics, expected, path) { expectedAll.push([{ name: metric, scope: 'WebTransaction/Hapi/GET/' + path }]) } - t.assertMetrics(metrics, expectedAll, true, false) + assertMetrics(metrics, expectedAll, true, false) } diff --git a/test/versioned/ioredis/ioredis.tap.js b/test/versioned/ioredis/ioredis.tap.js index f854d219cd..e559be3f4d 100644 --- a/test/versioned/ioredis/ioredis.tap.js +++ b/test/versioned/ioredis/ioredis.tap.js @@ -7,7 +7,7 @@ const tap = require('tap') const helper = require('../../lib/agent_helper') -require('../../lib/metrics_helper') +const { assertMetrics } = require('../../lib/metrics_helper') const params = require('../../lib/params') const urltils = require('../../../lib/util/urltils') @@ -57,7 +57,7 @@ tap.test('ioredis instrumentation', (t) => { ] expected['Datastore/instance/Redis/' + HOST_ID] = 2 - t.assertMetrics(tx.metrics, expected, false, false) + assertMetrics(tx.metrics, expected, false, false) t.end() }) diff --git a/test/versioned/koa/koa.tap.js b/test/versioned/koa/koa.tap.js index 9f2844fcce..aad374f97d 100644 --- a/test/versioned/koa/koa.tap.js +++ b/test/versioned/koa/koa.tap.js @@ -8,7 +8,7 @@ const tap = require('tap') const http = require('http') const helper = require('../../lib/agent_helper') -require('../../lib/metrics_helper') +const { assertSegments } = require('../../lib/metrics_helper') tap.test('Koa instrumentation', (t) => { t.autoend() @@ -227,7 +227,7 @@ tap.test('Koa instrumentation', (t) => { }) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//', [ 'Nodejs/Middleware/Koa/one', @@ -283,7 +283,7 @@ tap.test('Koa instrumentation', (t) => { }) agent.on('transactionFinished', function (txn) { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ txn.name, [ 'Nodejs/Middleware/Koa/one', @@ -399,7 +399,7 @@ tap.test('Koa instrumentation', (t) => { }) function checkSegments(t, tx) { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ // Until koa-router is instrumented and transaction naming is addressed, // names will be inconsistent depending on whether there is an error. tx.name, diff --git a/test/versioned/koa/router-common.js b/test/versioned/koa/router-common.js index 7927391e36..497792c094 100644 --- a/test/versioned/koa/router-common.js +++ b/test/versioned/koa/router-common.js @@ -7,7 +7,7 @@ module.exports = (pkg) => { const tap = require('tap') - require('../../lib/metrics_helper') + const { assertSegments } = require('../../lib/metrics_helper') const helper = require('../../lib/agent_helper') const semver = require('semver') const { run } = require('./utils') @@ -70,7 +70,7 @@ module.exports = (pkg) => { app.use(router.routes()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//:first', [ 'Koa/Router: /', @@ -97,7 +97,7 @@ module.exports = (pkg) => { }) app.use(router.middleware()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//:first', ['Koa/Router: /', ['Nodejs/Middleware/Koa/firstMiddleware//:first']] ]) @@ -132,7 +132,7 @@ module.exports = (pkg) => { }) app.use(router.routes()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//.*rst$', ['Koa/Router: /', ['Nodejs/Middleware/Koa/firstMiddleware//.*rst$/']] ]) @@ -153,7 +153,7 @@ module.exports = (pkg) => { }) app.use(router.routes()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//:first/(.*)', ['Koa/Router: /', ['Nodejs/Middleware/Koa/firstMiddleware//:first/(.*)']] ]) @@ -178,7 +178,7 @@ module.exports = (pkg) => { }) app.use(router.routes()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//:first', [ 'Koa/Router: /', @@ -210,7 +210,7 @@ module.exports = (pkg) => { app.use(router.routes()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//:first', [ 'Koa/Router: /', @@ -246,7 +246,7 @@ module.exports = (pkg) => { app.use(router.routes()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//:second', [ 'Koa/Router: /', @@ -280,7 +280,7 @@ module.exports = (pkg) => { app.use(router.routes()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//:first', [ 'Nodejs/Middleware/Koa/errorHandler', @@ -311,7 +311,7 @@ module.exports = (pkg) => { app.use(router.routes()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//:first', [ 'Nodejs/Middleware/Koa/errorHandler', @@ -344,7 +344,7 @@ module.exports = (pkg) => { }) app.use(router.routes()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//:second', [ 'Koa/Router: /', @@ -377,7 +377,7 @@ module.exports = (pkg) => { }) app.use(router.routes()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET/(not found)', ['Koa/Router: /'] ]) @@ -406,7 +406,7 @@ module.exports = (pkg) => { }) app.use(router.routes()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET/(not found)', ['Nodejs/Middleware/Koa/baseMiddleware', ['Koa/Router: /']] ]) @@ -447,7 +447,7 @@ module.exports = (pkg) => { // the dispatch function blocking its returned promise on the // resolution of a recursively returned promise. // https://github.com/koajs/compose/blob/e754ca3c13e9248b3f453d98ea0b618e09578e2d/index.js#L42-L44 - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//:second', [ 'Koa/Router: /', @@ -485,7 +485,7 @@ module.exports = (pkg) => { // the dispatch function blocking its returned promise on the // resolution of a recursively returned promise. // https://github.com/koajs/compose/blob/e754ca3c13e9248b3f453d98ea0b618e09578e2d/index.js#L42-L44 - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//:second', [ 'Koa/Router: /', @@ -520,7 +520,7 @@ module.exports = (pkg) => { router.use('/:first', router2.routes()) app.use(router.routes()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//:first/:second', ['Koa/Router: /', [getNestedSpanName('secondMiddleware')]] ]) @@ -550,7 +550,7 @@ module.exports = (pkg) => { app.use(router.routes()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//:first/:second', [ 'Nodejs/Middleware/Koa/appLevelMiddleware', @@ -582,7 +582,7 @@ module.exports = (pkg) => { app.use(router.routes()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//:first/:second', [ 'Nodejs/Middleware/Koa/appLevelMiddleware', @@ -619,7 +619,7 @@ module.exports = (pkg) => { app.use(router.routes()) app.use(router.allowedMethods({ throw: true })) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET/(method not allowed)', ['Koa/Router: /', [`Nodejs/Middleware/Koa/${allowedMethodsFnName}`]] ]) @@ -642,7 +642,7 @@ module.exports = (pkg) => { app.use(router.routes()) app.use(router.allowedMethods({ throw: true })) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET/(not implemented)', ['Koa/Router: /', [`Nodejs/Middleware/Koa/${allowedMethodsFnName}`]] ]) @@ -678,7 +678,7 @@ module.exports = (pkg) => { app.use(router.allowedMethods({ throw: true })) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/NormalizedUri/*', [ 'Nodejs/Middleware/Koa/errorHandler', @@ -717,7 +717,7 @@ module.exports = (pkg) => { app.use(router.allowedMethods({ throw: true })) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET/(method not allowed)', [ 'Nodejs/Middleware/Koa/baseMiddleware', @@ -750,7 +750,7 @@ module.exports = (pkg) => { app.use(router.routes()) app.use(router.allowedMethods()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET/(method not allowed)', ['Koa/Router: /', [`Nodejs/Middleware/Koa/${allowedMethodsFnName}`]] ]) @@ -774,7 +774,7 @@ module.exports = (pkg) => { app.use(router.routes()) app.use(router.allowedMethods()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET/(not implemented)', ['Koa/Router: /', [`Nodejs/Middleware/Koa/${allowedMethodsFnName}`]] ]) @@ -806,7 +806,7 @@ module.exports = (pkg) => { app.use(router.allowedMethods()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET/(method not allowed)', [ 'Nodejs/Middleware/Koa/appLevelMiddleware', @@ -840,7 +840,7 @@ module.exports = (pkg) => { app.use(router.allowedMethods()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET/(not implemented)', [ 'Nodejs/Middleware/Koa/appLevelMiddleware', @@ -866,7 +866,7 @@ module.exports = (pkg) => { app.use(router.routes()) app.use(router.allowedMethods()) agent.on('transactionFinished', (tx) => { - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'WebTransaction/WebFrameworkUri/Koa/GET//:first', ['Koa/Router: /', ['Nodejs/Middleware/Koa/firstMiddleware//:first']] ]) diff --git a/test/versioned/langchain/runnables-streaming.tap.js b/test/versioned/langchain/runnables-streaming.tap.js index 118c32e6a4..501ee060e3 100644 --- a/test/versioned/langchain/runnables-streaming.tap.js +++ b/test/versioned/langchain/runnables-streaming.tap.js @@ -8,8 +8,7 @@ const tap = require('tap') const helper = require('../../lib/agent_helper') const { removeModules } = require('../../lib/cache-buster') -// load the assertSegments assertion -require('../../lib/metrics_helper') +const { assertSegments } = require('../../lib/metrics_helper') const { filterLangchainEvents, filterLangchainEventsByType } = require('./common') const { version: pkgVersion } = require('@langchain/core/package.json') const createOpenAIMockServer = require('../openai/mock-server') @@ -396,7 +395,7 @@ tap.test('Langchain instrumentation - chain streaming', (t) => { // no-op } - t.assertSegments(tx.trace.root, ['Llm/chain/Langchain/stream'], { exact: false }) + assertSegments(tx.trace.root, ['Llm/chain/Langchain/stream'], { exact: false }) tx.end() t.end() diff --git a/test/versioned/langchain/runnables.tap.js b/test/versioned/langchain/runnables.tap.js index a2d3aacc7f..d238d4d30b 100644 --- a/test/versioned/langchain/runnables.tap.js +++ b/test/versioned/langchain/runnables.tap.js @@ -8,8 +8,7 @@ const tap = require('tap') const helper = require('../../lib/agent_helper') const { removeModules } = require('../../lib/cache-buster') -// load the assertSegments assertion -require('../../lib/metrics_helper') +const { assertSegments } = require('../../lib/metrics_helper') const { filterLangchainEvents, filterLangchainEventsByType } = require('./common') const { version: pkgVersion } = require('@langchain/core/package.json') const createOpenAIMockServer = require('../openai/mock-server') @@ -363,7 +362,7 @@ tap.test('Langchain instrumentation - runnable sequence', (t) => { const result = await chain.invoke(input, options) t.ok(result) - t.assertSegments(tx.trace.root, ['Llm/chain/Langchain/invoke'], { exact: false }) + assertSegments(tx.trace.root, ['Llm/chain/Langchain/invoke'], { exact: false }) tx.end() t.end() diff --git a/test/versioned/langchain/tools.tap.js b/test/versioned/langchain/tools.tap.js index baf24f7343..bc14190087 100644 --- a/test/versioned/langchain/tools.tap.js +++ b/test/versioned/langchain/tools.tap.js @@ -8,8 +8,7 @@ const tap = require('tap') const helper = require('../../lib/agent_helper') const { removeModules, removeMatchedModules } = require('../../lib/cache-buster') -// load the assertSegments assertion -require('../../lib/metrics_helper') +const { assertSegments } = require('../../lib/metrics_helper') const { version: pkgVersion } = require('@langchain/core/package.json') const config = { ai_monitoring: { @@ -42,7 +41,7 @@ tap.test('Langchain instrumentation - tools', (t) => { helper.runInTransaction(agent, async (tx) => { const result = await tool.call(input) t.ok(result) - t.assertSegments(tx.trace.root, ['Llm/tool/Langchain/node-agent-test-tool'], { exact: false }) + assertSegments(tx.trace.root, ['Llm/tool/Langchain/node-agent-test-tool'], { exact: false }) tx.end() t.end() }) diff --git a/test/versioned/langchain/vectorstore.tap.js b/test/versioned/langchain/vectorstore.tap.js index 9d0a3520fb..94c63577c9 100644 --- a/test/versioned/langchain/vectorstore.tap.js +++ b/test/versioned/langchain/vectorstore.tap.js @@ -8,8 +8,7 @@ const tap = require('tap') const helper = require('../../lib/agent_helper') const { removeModules } = require('../../lib/cache-buster') -// load the assertSegments assertion -require('../../lib/metrics_helper') +const { assertSegments } = require('../../lib/metrics_helper') const fs = require('fs') let pkgVersion try { @@ -101,7 +100,7 @@ tap.test('Langchain instrumentation - vectorstore', (t) => { helper.runInTransaction(agent, async (tx) => { const result = await vs.similaritySearch('This is an embedding test.', 1) t.ok(result) - t.assertSegments(tx.trace.root, ['Llm/vectorstore/Langchain/similaritySearch'], { + assertSegments(tx.trace.root, ['Llm/vectorstore/Langchain/similaritySearch'], { exact: false }) tx.end() diff --git a/test/versioned/nextjs/segments.tap.js b/test/versioned/nextjs/segments.tap.js index 6f224240ae..cc5bbdcce7 100644 --- a/test/versioned/nextjs/segments.tap.js +++ b/test/versioned/nextjs/segments.tap.js @@ -16,7 +16,7 @@ const { isMiddlewareInstrumentationSupported } = require('../../../lib/instrumentation/nextjs/utils') const agentHelper = require('../../lib/agent_helper') -require('../../lib/metrics_helper') +const { assertSegments } = require('../../lib/metrics_helper') function getChildSegments(uri) { const segments = [ @@ -72,7 +72,7 @@ tap.test('Next.js', (t) => { children: getChildSegments(URI) } ] - t.assertSegments(tx.trace.root, expectedSegments, { exact: false }) + assertSegments(tx.trace.root, expectedSegments, { exact: false }) }) t.test('should properly name getServerSideProps segments on dynamic pages', async (t) => { @@ -91,7 +91,7 @@ tap.test('Next.js', (t) => { children: getChildSegments(EXPECTED_URI) } ] - t.assertSegments(tx.trace.root, expectedSegments, { exact: false }) + assertSegments(tx.trace.root, expectedSegments, { exact: false }) }) t.test( @@ -121,7 +121,7 @@ tap.test('Next.js', (t) => { ] } - t.assertSegments(tx.trace.root, expectedSegments, { exact: false }) + assertSegments(tx.trace.root, expectedSegments, { exact: false }) } ) }) diff --git a/test/versioned/openai/chat-completions.tap.js b/test/versioned/openai/chat-completions.tap.js index 322691bebb..950ffe3d7e 100644 --- a/test/versioned/openai/chat-completions.tap.js +++ b/test/versioned/openai/chat-completions.tap.js @@ -12,8 +12,7 @@ const tap = require('tap') const helper = require('../../lib/agent_helper') -// load the assertSegments assertion -require('../../lib/metrics_helper') +const { assertSegments } = require('../../lib/metrics_helper') const { AI: { OPENAI } } = require('../../../lib/metrics/names') @@ -47,7 +46,7 @@ tap.test('OpenAI instrumentation - chat completions', (t) => { test.notOk(results.headers, 'should remove response headers from user result') test.equal(results.choices[0].message.content, '1 plus 2 is 3.') - test.assertSegments( + assertSegments( tx.trace.root, [OPENAI.COMPLETION, [`External/${host}:${port}/chat/completions`]], { exact: false } @@ -127,7 +126,7 @@ tap.test('OpenAI instrumentation - chat completions', (t) => { test.equal(chunk.choices[0].message.content, expectedRes.streamData) test.equal(chunk.choices[0].message.content, res) - test.assertSegments( + assertSegments( tx.trace.root, [OPENAI.COMPLETION, [`External/${host}:${port}/chat/completions`]], { exact: false } @@ -342,7 +341,7 @@ tap.test('OpenAI instrumentation - chat completions', (t) => { const events = agent.customEventAggregator.events.toArray() test.equal(events.length, 0) // we will still record the external segment but not the chat completion - test.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'timers.setTimeout', `External/${host}:${port}/chat/completions` ]) diff --git a/test/versioned/openai/embeddings.tap.js b/test/versioned/openai/embeddings.tap.js index e5e7c05eeb..660e7ee81a 100644 --- a/test/versioned/openai/embeddings.tap.js +++ b/test/versioned/openai/embeddings.tap.js @@ -12,7 +12,7 @@ const tap = require('tap') const helper = require('../../lib/agent_helper') -require('../../lib/metrics_helper') +const { assertSegments } = require('../../lib/metrics_helper') const { beforeHook, afterEachHook, afterHook } = require('./common') const { AI: { OPENAI } @@ -45,7 +45,7 @@ tap.test('OpenAI instrumentation - embedding', (t) => { test.notOk(results.headers, 'should remove response headers from user result') test.equal(results.model, 'text-embedding-ada-002-v2') - test.assertSegments( + assertSegments( tx.trace.root, [OPENAI.EMBEDDING, [`External/${host}:${port}/embeddings`]], { diff --git a/test/versioned/restify/async-handlers.tap.js b/test/versioned/restify/async-handlers.tap.js index 43dd2920f3..e21578e83d 100644 --- a/test/versioned/restify/async-handlers.tap.js +++ b/test/versioned/restify/async-handlers.tap.js @@ -8,7 +8,7 @@ const tap = require('tap') const helper = require('../../lib/agent_helper') -require('../../lib/metrics_helper') +const { assertMetrics } = require('../../lib/metrics_helper') const { runTest } = require('./common') const simulateAsyncWork = async () => { @@ -172,7 +172,7 @@ tap.test('Restify metrics for async handlers', (t) => { helper.makeGetRequest(url, function (error) { t.error(error) - t.assertMetrics(agent.metrics, expectedMiddlewareMetrics, false, false) + assertMetrics(agent.metrics, expectedMiddlewareMetrics, false, false) t.end() }) }) diff --git a/test/versioned/restify/restify.tap.js b/test/versioned/restify/restify.tap.js index 8088d0eb4d..60de1b9639 100644 --- a/test/versioned/restify/restify.tap.js +++ b/test/versioned/restify/restify.tap.js @@ -8,7 +8,7 @@ const tap = require('tap') const helper = require('../../lib/agent_helper') -require('../../lib/metrics_helper') +const { assertMetrics } = require('../../lib/metrics_helper') const METRIC = 'WebTransaction/Restify/GET//hello/:name' @@ -168,7 +168,7 @@ tap.test('Restify', (t) => { helper.makeGetRequest(url, function (error) { t.error(error) - t.assertMetrics(agent.metrics, expectedMiddlewareMetrics, false, false) + assertMetrics(agent.metrics, expectedMiddlewareMetrics, false, false) t.end() }) }) diff --git a/test/versioned/when/legacy-promise-segments.js b/test/versioned/when/legacy-promise-segments.js index 3edc160bc6..75b83658d3 100644 --- a/test/versioned/when/legacy-promise-segments.js +++ b/test/versioned/when/legacy-promise-segments.js @@ -6,7 +6,7 @@ 'use strict' const helper = require('../../lib/agent_helper') -require('../../lib/metrics_helper') +const { assertSegments } = require('../../lib/metrics_helper') module.exports = runTests @@ -45,7 +45,7 @@ function segmentsEnabledTests(t, agent, Promise, doSomeWork) { agent.once('transactionFinished', function (tx) { t.equal(tx.trace.root.children.length, 1) - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'doSomeWork', ['Promise startSomeWork', ['Promise#then ', ['someChildSegment']]] ]) @@ -72,7 +72,7 @@ function segmentsEnabledTests(t, agent, Promise, doSomeWork) { agent.once('transactionFinished', function (tx) { t.equal(tx.trace.root.children.length, 1) - t.assertSegments(tx.trace.root, ['doWork1', ['doWork2', ['secondThen']]]) + assertSegments(tx.trace.root, ['doWork1', ['doWork2', ['secondThen']]]) t.end() }) @@ -97,7 +97,7 @@ function segmentsEnabledTests(t, agent, Promise, doSomeWork) { agent.once('transactionFinished', function (tx) { t.equal(tx.trace.root.children.length, 1) - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'doWork1', ['Promise startSomeWork', ['Promise#then firstThen', ['Promise#then secondThen']]] ]) @@ -122,7 +122,7 @@ function segmentsEnabledTests(t, agent, Promise, doSomeWork) { agent.once('transactionFinished', function (tx) { t.equal(tx.trace.root.children.length, 1) - t.assertSegments(tx.trace.root, [ + assertSegments(tx.trace.root, [ 'doWork1', ['Promise startSomeWork', ['Promise#catch catchHandler']] ]) @@ -150,7 +150,7 @@ function segmentsEnabledTests(t, agent, Promise, doSomeWork) { agent.once('transactionFinished', function (tx) { t.equal(tx.trace.root.children.length, 1) - t.assertSegments(tx.trace.root, ['doWork1', ['doWork2', ['catchHandler']]]) + assertSegments(tx.trace.root, ['doWork1', ['doWork2', ['catchHandler']]]) t.end() }) @@ -180,7 +180,7 @@ function segmentsEnabledTests(t, agent, Promise, doSomeWork) { agent.once('transactionFinished', function (tx) { t.equal(tx.trace.root.children.length, 2) - t.assertSegments( + assertSegments( tx.trace.root, ['Promise startSomeWork', ['Promise#then myThen'], 'doSomeWork'], true @@ -219,7 +219,7 @@ function segmentsDisabledTests(t, agent, Promise, doSomeWork) { agent.once('transactionFinished', function (tx) { t.equal(tx.trace.root.children.length, 1) - t.assertSegments(tx.trace.root, ['doSomeWork', ['someChildSegment']]) + assertSegments(tx.trace.root, ['doSomeWork', ['someChildSegment']]) t.end() }) @@ -241,7 +241,7 @@ function segmentsDisabledTests(t, agent, Promise, doSomeWork) { agent.once('transactionFinished', function (tx) { t.equal(tx.trace.root.children.length, 1) - t.assertSegments(tx.trace.root, ['doWork1']) + assertSegments(tx.trace.root, ['doWork1']) t.end() }) @@ -265,7 +265,7 @@ function segmentsDisabledTests(t, agent, Promise, doSomeWork) { agent.once('transactionFinished', function (tx) { t.equal(tx.trace.root.children.length, 1) - t.assertSegments(tx.trace.root, ['doWork1']) + assertSegments(tx.trace.root, ['doWork1']) t.end() }) @@ -287,7 +287,7 @@ function segmentsDisabledTests(t, agent, Promise, doSomeWork) { agent.once('transactionFinished', function (tx) { t.equal(tx.trace.root.children.length, 1) - t.assertSegments(tx.trace.root, ['doWork1']) + assertSegments(tx.trace.root, ['doWork1']) t.end() }) @@ -309,7 +309,7 @@ function segmentsDisabledTests(t, agent, Promise, doSomeWork) { agent.once('transactionFinished', function (tx) { t.equal(tx.trace.root.children.length, 1) - t.assertSegments(tx.trace.root, ['doWork1', ['doWork2']]) + assertSegments(tx.trace.root, ['doWork1', ['doWork2']]) t.end() }) @@ -332,7 +332,7 @@ function segmentsDisabledTests(t, agent, Promise, doSomeWork) { agent.once('transactionFinished', function (tx) { t.equal(tx.trace.root.children.length, 1) - t.assertSegments(tx.trace.root, ['doSomeWork'], true) + assertSegments(tx.trace.root, ['doSomeWork'], true) t.end() })