diff --git a/.gitlab/benchmarks/bp-runner.fail-on-breach.yml b/.gitlab/benchmarks/bp-runner.fail-on-breach.yml index e5564896f75..4b83b4e1a4c 100644 --- a/.gitlab/benchmarks/bp-runner.fail-on-breach.yml +++ b/.gitlab/benchmarks/bp-runner.fail-on-breach.yml @@ -12,12 +12,12 @@ experiments: - name: normal_operation/only-tracing thresholds: - threshold: agg_http_req_duration_p50 < 2 ms - warning_range: 3 + warning_range: 1 - agg_http_req_duration_p99 < 15 ms - name: normal_operation/only-tracing-with-runtime-metrics-enabled thresholds: - threshold: agg_http_req_duration_p50 < 2 ms - warning_range: 3 + warning_range: 1 - agg_http_req_duration_p99 < 16 ms - name: high_load/only-tracing thresholds: diff --git a/integration-tests/helpers/index.js b/integration-tests/helpers/index.js index 7d5ed6f7604..de4029a87dc 100644 --- a/integration-tests/helpers/index.js +++ b/integration-tests/helpers/index.js @@ -1,9 +1,7 @@ 'use strict' -const { promisify } = require('util') const childProcess = require('child_process') -const { fork, spawn } = childProcess -const exec = promisify(childProcess.exec) +const { execSync, fork, spawn } = childProcess const http = require('http') const { existsSync, readFileSync, unlinkSync, writeFileSync } = require('fs') const fs = require('fs/promises') @@ -214,22 +212,24 @@ function spawnProc (filename, options = {}, stdioHandler, stderrHandler) { })) } -async function execHelper (command, options) { +function execHelper (command, options) { /* eslint-disable no-console */ try { console.log('Exec START: ', command) - await exec(command, options) + execSync(command, options) console.log('Exec SUCCESS: ', command) } catch (error) { console.error('Exec ERROR: ', command, error) if (command.startsWith('yarn')) { try { console.log('Exec RETRY START: ', command) - await exec(command, options) + execSync(command, options) console.log('Exec RETRY SUCESS: ', command) } catch (retryError) { console.error('Exec RETRY ERROR', command, retryError) + throw retryError } + } else { throw error } } @@ -264,8 +264,8 @@ async function createSandbox (dependencies = [], isGitRepo = false, // yarn-linked into dd-trace and want to run the integration tests against them. // Link dd-trace to itself, then... - await execHelper('yarn link') - await execHelper('yarn link dd-trace') + execHelper('yarn link') + execHelper('yarn link dd-trace') // ... run the tests in the current directory. return { folder: path.join(process.cwd(), 'integration-tests'), remove: async () => {} } } @@ -277,45 +277,45 @@ async function createSandbox (dependencies = [], isGitRepo = false, const preferOfflineFlag = process.env.OFFLINE === '1' || process.env.OFFLINE === 'true' ? ' --prefer-offline' : '' const addCommand = `yarn add ${allDependencies.join(' ')} --ignore-engines${preferOfflineFlag}` const addOptions = { cwd: folder, env: restOfEnv } - await execHelper(`npm pack --silent --pack-destination ${folder}`, { env: restOfEnv }) // TODO: cache this + execHelper(`npm pack --silent --pack-destination ${folder}`, { env: restOfEnv }) // TODO: cache this - await execHelper(addCommand, addOptions) + execHelper(addCommand, addOptions) for (const path of integrationTestsPaths) { if (process.platform === 'win32') { - await execHelper(`Copy-Item -Recurse -Path "${path}" -Destination "${folder}"`, { shell: 'powershell.exe' }) + execHelper(`Copy-Item -Recurse -Path "${path}" -Destination "${folder}"`, { shell: 'powershell.exe' }) } else { - await execHelper(`cp -R ${path} ${folder}`) + execHelper(`cp -R ${path} ${folder}`) } } if (process.platform === 'win32') { // On Windows, we can only sync entire filesystem volume caches. - await execHelper(`Write-VolumeCache ${folder[0]}`, { shell: 'powershell.exe' }) + execHelper(`Write-VolumeCache ${folder[0]}`, { shell: 'powershell.exe' }) } else { - await execHelper(`sync ${folder}`) + execHelper(`sync ${folder}`) } if (followUpCommand) { - await execHelper(followUpCommand, { cwd: folder, env: restOfEnv }) + execHelper(followUpCommand, { cwd: folder, env: restOfEnv }) } if (isGitRepo) { - await execHelper('git init', { cwd: folder }) + execHelper('git init', { cwd: folder }) await fs.writeFile(path.join(folder, '.gitignore'), 'node_modules/', { flush: true }) - await execHelper('git config user.email "john@doe.com"', { cwd: folder }) - await execHelper('git config user.name "John Doe"', { cwd: folder }) - await execHelper('git config commit.gpgsign false', { cwd: folder }) + execHelper('git config user.email "john@doe.com"', { cwd: folder }) + execHelper('git config user.name "John Doe"', { cwd: folder }) + execHelper('git config commit.gpgsign false', { cwd: folder }) // Create a unique local bare repo for this test const localRemotePath = path.join(folder, '..', `${path.basename(folder)}-remote.git`) if (!existsSync(localRemotePath)) { - await execHelper(`git init --bare ${localRemotePath}`) + execHelper(`git init --bare ${localRemotePath}`) } - await execHelper('git add -A', { cwd: folder }) - await execHelper('git commit -m "first commit" --no-verify', { cwd: folder }) - await execHelper(`git remote add origin ${localRemotePath}`, { cwd: folder }) - await execHelper('git push --set-upstream origin HEAD', { cwd: folder }) + execHelper('git add -A', { cwd: folder }) + execHelper('git commit -m "first commit" --no-verify', { cwd: folder }) + execHelper(`git remote add origin ${localRemotePath}`, { cwd: folder }) + execHelper('git push --set-upstream origin HEAD', { cwd: folder }) } return { @@ -324,9 +324,9 @@ async function createSandbox (dependencies = [], isGitRepo = false, // Use `exec` below, instead of `fs.rm` to keep support for older Node.js versions, since this code is called in // our `integration-guardrails` GitHub Actions workflow if (process.platform === 'win32') { - return exec(`Remove-Item -Recurse -Path "${folder}"`, { shell: 'powershell.exe' }) + return execHelper(`Remove-Item -Recurse -Path "${folder}"`, { shell: 'powershell.exe' }) } else { - return exec(`rm -rf ${folder}`) + return execHelper(`rm -rf ${folder}`) } } } @@ -522,6 +522,13 @@ function checkSpansForServiceName (spans, name) { return spans.some((span) => span.some((nestedSpan) => nestedSpan.name === name)) } +/** + * @overload + * @param {string} cwd + * @param {string} serverFile + * @param {string|number} agentPort + * @param {Record} [additionalEnvArgs] + */ /** * @param {string} cwd * @param {string} serverFile @@ -529,7 +536,12 @@ function checkSpansForServiceName (spans, name) { * @param {function} [stdioHandler] * @param {Record} [additionalEnvArgs] */ -async function spawnPluginIntegrationTestProc (cwd, serverFile, agentPort, stdioHandler, additionalEnvArgs = {}) { +async function spawnPluginIntegrationTestProc (cwd, serverFile, agentPort, stdioHandler, additionalEnvArgs) { + if (typeof stdioHandler !== 'function' && !additionalEnvArgs) { + additionalEnvArgs = stdioHandler + stdioHandler = undefined + } + additionalEnvArgs = additionalEnvArgs || {} let env = /** @type {Record} */ ({ NODE_OPTIONS: `--loader=${hookFile}`, DD_TRACE_AGENT_PORT: String(agentPort) diff --git a/package.json b/package.json index 0b6d2dae046..dda9673f675 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dd-trace", - "version": "5.71.0", + "version": "5.71.1", "description": "Datadog APM tracing client for JavaScript", "main": "index.js", "typings": "index.d.ts", diff --git a/packages/datadog-plugin-ai/test/integration-test/client.spec.js b/packages/datadog-plugin-ai/test/integration-test/client.spec.js index 4c0d694d647..b1874a9c077 100644 --- a/packages/datadog-plugin-ai/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-ai/test/integration-test/client.spec.js @@ -23,7 +23,7 @@ describe('esm', () => { withVersions('ai', 'ai', (version, _, realVersion) => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([ `ai@${version}`, `@ai-sdk/openai@${getOpenaiVersion(realVersion)}`, diff --git a/packages/datadog-plugin-amqp10/test/integration-test/client.spec.js b/packages/datadog-plugin-amqp10/test/integration-test/client.spec.js index 19267627646..380deedc44b 100644 --- a/packages/datadog-plugin-amqp10/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-amqp10/test/integration-test/client.spec.js @@ -15,7 +15,7 @@ describe('esm', () => { let sandbox withVersions('amqp10', 'amqp10', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'amqp10@${version}'`, 'rhea'], false, [ './packages/datadog-plugin-amqp10/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-amqplib/test/integration-test/client.spec.js b/packages/datadog-plugin-amqplib/test/integration-test/client.spec.js index f0aa82d6fb1..940a1d8e61e 100644 --- a/packages/datadog-plugin-amqplib/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-amqplib/test/integration-test/client.spec.js @@ -19,7 +19,7 @@ describe('esm', () => { // test against later versions because server.mjs uses newer package syntax withVersions('amqplib', 'amqplib', '>=0.10.0', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'amqplib@${version}'`], false, ['./packages/datadog-plugin-amqplib/test/integration-test/*']) variants = varySandbox(sandbox, 'server.mjs', 'amqplib', 'connect') diff --git a/packages/datadog-plugin-axios/test/integration-test/client.spec.js b/packages/datadog-plugin-axios/test/integration-test/client.spec.js index 018cdc7522d..13f0bb0978b 100644 --- a/packages/datadog-plugin-axios/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-axios/test/integration-test/client.spec.js @@ -14,7 +14,7 @@ describe('esm', () => { let sandbox before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox(['axios'], false, [ './packages/datadog-plugin-axios/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-azure-service-bus/test/integration-test/client.spec.js b/packages/datadog-plugin-azure-service-bus/test/integration-test/client.spec.js index 5a51bfc9f61..1249503136a 100644 --- a/packages/datadog-plugin-azure-service-bus/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-azure-service-bus/test/integration-test/client.spec.js @@ -16,7 +16,7 @@ describe('esm', () => { withVersions('azure-service-bus', '@azure/service-bus', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'@azure/service-bus@${version}'`], false, [ './packages/datadog-plugin-azure-service-bus/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-bunyan/test/integration-test/client.spec.js b/packages/datadog-plugin-bunyan/test/integration-test/client.spec.js index 46a5166f6c4..b26c6fd2951 100644 --- a/packages/datadog-plugin-bunyan/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-bunyan/test/integration-test/client.spec.js @@ -17,7 +17,7 @@ describe('esm', () => { withVersions('bunyan', 'bunyan', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'bunyan@${version}'`], false, ['./packages/datadog-plugin-bunyan/test/integration-test/*']) variants = varySandbox(sandbox, 'server.mjs', 'bunyan') diff --git a/packages/datadog-plugin-cassandra-driver/test/integration-test/client.spec.js b/packages/datadog-plugin-cassandra-driver/test/integration-test/client.spec.js index 158fdb06340..32a6ab43f92 100644 --- a/packages/datadog-plugin-cassandra-driver/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-cassandra-driver/test/integration-test/client.spec.js @@ -19,7 +19,7 @@ describe('esm', () => { // test against later versions because server.mjs uses newer package syntax withVersions('cassandra-driver', 'cassandra-driver', '>=4.4.0', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'cassandra-driver@${version}'`], false, [ './packages/datadog-plugin-cassandra-driver/test/integration-test/*']) variants = varySandbox(sandbox, 'server.mjs', 'cassandra-driver', 'Client') diff --git a/packages/datadog-plugin-confluentinc-kafka-javascript/test/integration-test/client.spec.js b/packages/datadog-plugin-confluentinc-kafka-javascript/test/integration-test/client.spec.js index f96a47af697..2e61d54cfd1 100644 --- a/packages/datadog-plugin-confluentinc-kafka-javascript/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-confluentinc-kafka-javascript/test/integration-test/client.spec.js @@ -15,7 +15,7 @@ describe('esm', () => { let sandbox withVersions('confluentinc-kafka-javascript', '@confluentinc/kafka-javascript', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'@confluentinc/kafka-javascript@${version}'`], false, [ './packages/datadog-plugin-confluentinc-kafka-javascript/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-connect/test/integration-test/client.spec.js b/packages/datadog-plugin-connect/test/integration-test/client.spec.js index f0b8786d02d..8d2d5b59856 100644 --- a/packages/datadog-plugin-connect/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-connect/test/integration-test/client.spec.js @@ -19,7 +19,7 @@ describe('esm', () => { // test against later versions because server.mjs uses newer package syntax withVersions('connect', 'connect', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'connect@${version}'`], false, [ './packages/datadog-plugin-connect/test/integration-test/*']) variants = varySandbox(sandbox, 'server.mjs', 'connect') diff --git a/packages/datadog-plugin-couchbase/test/integration-test/client.spec.js b/packages/datadog-plugin-couchbase/test/integration-test/client.spec.js index b0ec4f9c669..0edf5fda001 100644 --- a/packages/datadog-plugin-couchbase/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-couchbase/test/integration-test/client.spec.js @@ -17,7 +17,7 @@ describe('esm', () => { // test against later versions because server.mjs uses newer package syntax withVersions('couchbase', 'couchbase', '>=4.0.0', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'couchbase@${version}'`], false, [ './packages/datadog-plugin-couchbase/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-dns/test/integration-test/client.spec.js b/packages/datadog-plugin-dns/test/integration-test/client.spec.js index 31a94af0b0d..4fe489b6453 100644 --- a/packages/datadog-plugin-dns/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-dns/test/integration-test/client.spec.js @@ -16,7 +16,7 @@ describe('esm', () => { let variants before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([], false, [ './packages/datadog-plugin-dns/test/integration-test/*']) variants = varySandbox(sandbox, 'server.mjs', 'dns', 'lookup') diff --git a/packages/datadog-plugin-elasticsearch/test/integration-test/client.spec.js b/packages/datadog-plugin-elasticsearch/test/integration-test/client.spec.js index 6f6d45aac3c..78dc3d3d024 100644 --- a/packages/datadog-plugin-elasticsearch/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-elasticsearch/test/integration-test/client.spec.js @@ -19,7 +19,7 @@ describe('esm', () => { // excluding 8.16.0 for esm tests, because it is not working: https://github.com/elastic/elasticsearch-js/issues/2466 withVersions('elasticsearch', ['@elastic/elasticsearch'], '<8.16.0 || >8.16.0', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'@elastic/elasticsearch@${version}'`], false, [ './packages/datadog-plugin-elasticsearch/test/integration-test/*']) variants = varySandbox(sandbox, 'server.mjs', 'elasticsearch', undefined, '@elastic/elasticsearch') diff --git a/packages/datadog-plugin-fastify/test/integration-test/client.spec.js b/packages/datadog-plugin-fastify/test/integration-test/client.spec.js index 13e0630ed2c..46ca79bc837 100644 --- a/packages/datadog-plugin-fastify/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-fastify/test/integration-test/client.spec.js @@ -2,30 +2,24 @@ const { FakeAgent, - createSandbox, curlAndAssertMessage, checkSpansForServiceName, spawnPluginIntegrationTestProc } = require('../../../../integration-tests/helpers') -const { withVersions } = require('../../../dd-trace/test/setup/mocha') +const { withVersions, insertVersionDep } = require('../../../dd-trace/test/setup/mocha') const { assert } = require('chai') +const { join } = require('path') describe('esm', () => { let agent let proc - let sandbox + const env = { + NODE_OPTIONS: `--loader=${join(__dirname, '..', '..', '..', '..', 'initialize.mjs')}` + } // skip older versions of fastify due to syntax differences withVersions('fastify', 'fastify', '>=3', (version, _, specificVersion) => { - before(async function () { - this.timeout(20000) - sandbox = await createSandbox([`'fastify@${version}'`], false, - ['./packages/datadog-plugin-fastify/test/integration-test/*']) - }) - - after(async () => { - await sandbox.remove() - }) + insertVersionDep(__dirname, 'fastify', version) beforeEach(async () => { agent = await new FakeAgent().start() @@ -37,7 +31,7 @@ describe('esm', () => { }) it('is instrumented', async () => { - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server.mjs', agent.port, env) return curlAndAssertMessage(agent, proc, ({ headers, payload }) => { assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`) @@ -47,7 +41,7 @@ describe('esm', () => { }).timeout(20000) it('* import fastify is instrumented', async () => { - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server1.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server1.mjs', agent.port, env) return curlAndAssertMessage(agent, proc, ({ headers, payload }) => { assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`) @@ -57,7 +51,7 @@ describe('esm', () => { }).timeout(20000) it('Fastify import fastify is instrumented', async () => { - proc = await spawnPluginIntegrationTestProc(sandbox.folder, 'server2.mjs', agent.port) + proc = await spawnPluginIntegrationTestProc(__dirname, 'server2.mjs', agent.port, env) return curlAndAssertMessage(agent, proc, ({ headers, payload }) => { assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`) diff --git a/packages/datadog-plugin-fastify/test/integration-test/server.mjs b/packages/datadog-plugin-fastify/test/integration-test/server.mjs index 29d4561346e..7c8ef5c23da 100644 --- a/packages/datadog-plugin-fastify/test/integration-test/server.mjs +++ b/packages/datadog-plugin-fastify/test/integration-test/server.mjs @@ -1,4 +1,3 @@ -import 'dd-trace/init.js' import fastify from 'fastify' import { createAndStartServer } from './helper.mjs' diff --git a/packages/datadog-plugin-fastify/test/integration-test/server1.mjs b/packages/datadog-plugin-fastify/test/integration-test/server1.mjs index bb1f0167abb..88a036df769 100644 --- a/packages/datadog-plugin-fastify/test/integration-test/server1.mjs +++ b/packages/datadog-plugin-fastify/test/integration-test/server1.mjs @@ -1,4 +1,3 @@ -import 'dd-trace/init.js' import * as Fastify from 'fastify' import { createAndStartServer } from './helper.mjs' diff --git a/packages/datadog-plugin-fastify/test/integration-test/server2.mjs b/packages/datadog-plugin-fastify/test/integration-test/server2.mjs index e43ce8122e7..62d68577bf2 100644 --- a/packages/datadog-plugin-fastify/test/integration-test/server2.mjs +++ b/packages/datadog-plugin-fastify/test/integration-test/server2.mjs @@ -1,4 +1,3 @@ -import 'dd-trace/init.js' import Fastify from 'fastify' import { createAndStartServer } from './helper.mjs' diff --git a/packages/datadog-plugin-google-cloud-pubsub/test/integration-test/client.spec.js b/packages/datadog-plugin-google-cloud-pubsub/test/integration-test/client.spec.js index 3e4cb6bc085..d84b0b69e99 100644 --- a/packages/datadog-plugin-google-cloud-pubsub/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-google-cloud-pubsub/test/integration-test/client.spec.js @@ -16,7 +16,7 @@ describe('esm', () => { // test against later versions because server.mjs uses newer package syntax withVersions('google-cloud-pubsub', '@google-cloud/pubsub', '>=4.0.0', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'@google-cloud/pubsub@${version}'`], false, ['./packages/dd-trace/src/id.js', './packages/datadog-plugin-google-cloud-pubsub/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-google-cloud-vertexai/test/integration-test/client.spec.js b/packages/datadog-plugin-google-cloud-vertexai/test/integration-test/client.spec.js index 899e7d110db..31ac3e5f43a 100644 --- a/packages/datadog-plugin-google-cloud-vertexai/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-google-cloud-vertexai/test/integration-test/client.spec.js @@ -16,7 +16,7 @@ describe('esm', () => { withVersions('google-cloud-vertexai', '@google-cloud/vertexai', '>=1', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([ `@google-cloud/vertexai@${version}`, 'sinon' diff --git a/packages/datadog-plugin-grpc/test/integration-test/client.spec.js b/packages/datadog-plugin-grpc/test/integration-test/client.spec.js index afae9b78575..e489dede202 100644 --- a/packages/datadog-plugin-grpc/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-grpc/test/integration-test/client.spec.js @@ -16,7 +16,7 @@ describe('esm', () => { withVersions('grpc', '@grpc/grpc-js', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'@grpc/grpc-js@${version}'`, '@grpc/proto-loader'], false, [ './packages/datadog-plugin-grpc/test/*']) }) diff --git a/packages/datadog-plugin-hapi/test/integration-test/client.spec.js b/packages/datadog-plugin-hapi/test/integration-test/client.spec.js index 953474f30a8..a6e38641fc0 100644 --- a/packages/datadog-plugin-hapi/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-hapi/test/integration-test/client.spec.js @@ -17,7 +17,7 @@ describe('esm', () => { withVersions('hapi', '@hapi/hapi', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'@hapi/hapi@${version}'`], false, [ './packages/datadog-plugin-hapi/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-http/test/integration-test/client.spec.js b/packages/datadog-plugin-http/test/integration-test/client.spec.js index 2d11c13168b..6c4b07ba3d1 100644 --- a/packages/datadog-plugin-http/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-http/test/integration-test/client.spec.js @@ -14,7 +14,7 @@ describe('esm', () => { let sandbox before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([], false, [ './packages/datadog-plugin-http/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-ioredis/test/integration-test/client.spec.js b/packages/datadog-plugin-ioredis/test/integration-test/client.spec.js index 2d580cafe1e..e3b2539abbf 100644 --- a/packages/datadog-plugin-ioredis/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-ioredis/test/integration-test/client.spec.js @@ -17,7 +17,7 @@ describe('esm', () => { let variants withVersions('ioredis', 'ioredis', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'ioredis@${version}'`], false, [ './packages/datadog-plugin-ioredis/test/integration-test/*']) variants = varySandbox(sandbox, 'server.mjs', 'ioredis') diff --git a/packages/datadog-plugin-iovalkey/test/integration-test/client.spec.js b/packages/datadog-plugin-iovalkey/test/integration-test/client.spec.js index 26172421d66..57da3d2f2a5 100644 --- a/packages/datadog-plugin-iovalkey/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-iovalkey/test/integration-test/client.spec.js @@ -15,7 +15,7 @@ describe('esm', () => { let sandbox withVersions('iovalkey', 'iovalkey', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'iovalkey@${version}'`], false, [ './packages/datadog-plugin-iovalkey/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-kafkajs/test/integration-test/client.spec.js b/packages/datadog-plugin-kafkajs/test/integration-test/client.spec.js index 26dc8fb793c..b778a36e3b7 100644 --- a/packages/datadog-plugin-kafkajs/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-kafkajs/test/integration-test/client.spec.js @@ -15,7 +15,7 @@ describe('esm', () => { let sandbox withVersions('kafkajs', 'kafkajs', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'kafkajs@${version}'`], false, [ './packages/datadog-plugin-kafkajs/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-langchain/test/integration-test/client.spec.js b/packages/datadog-plugin-langchain/test/integration-test/client.spec.js index 46cdcd89096..3dcf3fbfe78 100644 --- a/packages/datadog-plugin-langchain/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-langchain/test/integration-test/client.spec.js @@ -16,7 +16,7 @@ describe('esm', () => { withVersions('langchain', ['@langchain/core'], '>=0.1', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([ `@langchain/core@${version}`, `@langchain/openai@${version}`, diff --git a/packages/datadog-plugin-limitd-client/test/integration-test/client.spec.js b/packages/datadog-plugin-limitd-client/test/integration-test/client.spec.js index 8168b52b4b6..b76fa0ed2bf 100644 --- a/packages/datadog-plugin-limitd-client/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-limitd-client/test/integration-test/client.spec.js @@ -18,7 +18,7 @@ describe('esm', () => { withVersions('limitd-client', 'limitd-client', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'limitd-client@${version}'`], false, [ './packages/datadog-plugin-limitd-client/test/integration-test/*']) variants = varySandbox(sandbox, 'server.mjs', 'limitd-client') diff --git a/packages/datadog-plugin-mariadb/test/integration-test/client.spec.js b/packages/datadog-plugin-mariadb/test/integration-test/client.spec.js index c8857d64ee9..387b41d6866 100644 --- a/packages/datadog-plugin-mariadb/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-mariadb/test/integration-test/client.spec.js @@ -17,7 +17,7 @@ describe('esm', () => { // test against later versions because server.mjs uses newer package syntax withVersions('mariadb', 'mariadb', '>=3.0.0', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'mariadb@${version}'`], false, [ './packages/datadog-plugin-mariadb/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-microgateway-core/test/integration-test/client.spec.js b/packages/datadog-plugin-microgateway-core/test/integration-test/client.spec.js index f81c8b58981..19229bc1511 100644 --- a/packages/datadog-plugin-microgateway-core/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-microgateway-core/test/integration-test/client.spec.js @@ -18,7 +18,7 @@ describe('esm', () => { // test against later versions because server.mjs uses newer package syntax withVersions('microgateway-core', 'microgateway-core', '>=3.0.0', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'microgateway-core@${version}'`], false, [ './packages/datadog-plugin-microgateway-core/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-moleculer/test/integration-test/client.spec.js b/packages/datadog-plugin-moleculer/test/integration-test/client.spec.js index 9d955f6c845..3193ace422f 100644 --- a/packages/datadog-plugin-moleculer/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-moleculer/test/integration-test/client.spec.js @@ -16,7 +16,7 @@ describe('esm', () => { // test against later versions because server.mjs uses newer package syntax withVersions('moleculer', 'moleculer', '>0.14.0', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'moleculer@${version}'`], false, [ './packages/datadog-plugin-moleculer/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-mongodb-core/test/integration-test/client.spec.js b/packages/datadog-plugin-mongodb-core/test/integration-test/client.spec.js index 9da419e39e3..e8fe7491033 100644 --- a/packages/datadog-plugin-mongodb-core/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-mongodb-core/test/integration-test/client.spec.js @@ -18,7 +18,7 @@ describe('esm', () => { // test against later versions because server.mjs uses newer package syntax withVersions('mongodb-core', 'mongodb', '>=4', version => { before(async function () { - this.timeout(30000) + this.timeout(60000) sandbox = await createSandbox([`'mongodb@${version}'`], false, [ './packages/datadog-plugin-mongodb-core/test/integration-test/*']) variants = varySandbox(sandbox, 'server.mjs', 'mongodb', 'MongoClient') @@ -55,7 +55,7 @@ describe('esm', () => { // test against later versions because server2.mjs uses newer package syntax withVersions('mongodb-core', 'mongodb-core', '>=3', version => { before(async function () { - this.timeout(30000) + this.timeout(60000) sandbox = await createSandbox([`'mongodb-core@${version}'`], false, [ './packages/datadog-plugin-mongodb-core/test/integration-test/*']) variants = varySandbox(sandbox, 'server2.mjs', 'MongoDBCore') diff --git a/packages/datadog-plugin-mongoose/test/integration-test/client.spec.js b/packages/datadog-plugin-mongoose/test/integration-test/client.spec.js index 903145c25c8..97a0ee4ea6b 100644 --- a/packages/datadog-plugin-mongoose/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-mongoose/test/integration-test/client.spec.js @@ -18,7 +18,7 @@ describe('esm', () => { withVersions('mongoose', ['mongoose'], '>=4', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'mongoose@${version}'`], false, [ './packages/datadog-plugin-mongoose/test/integration-test/*']) variants = varySandbox(sandbox, 'server.mjs', 'mongoose') diff --git a/packages/datadog-plugin-mysql/test/integration-test/client.spec.js b/packages/datadog-plugin-mysql/test/integration-test/client.spec.js index 2b2b878c35a..0c4060d63c6 100644 --- a/packages/datadog-plugin-mysql/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-mysql/test/integration-test/client.spec.js @@ -18,7 +18,7 @@ describe('esm', () => { withVersions('mysql', 'mysql', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'mysql@${version}'`], false, [ './packages/datadog-plugin-mysql/test/integration-test/*']) variants = varySandbox(sandbox, 'server.mjs', 'mysql', 'createConnection') diff --git a/packages/datadog-plugin-mysql2/test/integration-test/client.spec.js b/packages/datadog-plugin-mysql2/test/integration-test/client.spec.js index c21aa72b5c9..8997d50f168 100644 --- a/packages/datadog-plugin-mysql2/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-mysql2/test/integration-test/client.spec.js @@ -16,7 +16,7 @@ describe('esm', () => { withVersions('mysql2', 'mysql2', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'mysql2@${version}'`], false, [ './packages/datadog-plugin-mysql2/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-net/test/integration-test/client.spec.js b/packages/datadog-plugin-net/test/integration-test/client.spec.js index 3e6cad5a0bf..ee0fb301031 100644 --- a/packages/datadog-plugin-net/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-net/test/integration-test/client.spec.js @@ -16,7 +16,7 @@ describe('esm', () => { let variants before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox(['net'], false, [ './packages/datadog-plugin-net/test/integration-test/*']) variants = varySandbox(sandbox, 'server.mjs', 'net', 'createConnection') diff --git a/packages/datadog-plugin-openai/test/integration-test/client.spec.js b/packages/datadog-plugin-openai/test/integration-test/client.spec.js index 2eea8121099..74b855395ec 100644 --- a/packages/datadog-plugin-openai/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-openai/test/integration-test/client.spec.js @@ -19,7 +19,7 @@ describe('esm', () => { // issue link: https://github.com/DataDog/import-in-the-middle/issues/60 withVersions('openai', 'openai', '>=3 <4.0.0 || >4.1.0', (version) => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox( [ `'openai@${version}'`, diff --git a/packages/datadog-plugin-opensearch/test/integration-test/client.spec.js b/packages/datadog-plugin-opensearch/test/integration-test/client.spec.js index 34badfcfb93..8dee287a1af 100644 --- a/packages/datadog-plugin-opensearch/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-opensearch/test/integration-test/client.spec.js @@ -16,7 +16,7 @@ describe('esm', () => { withVersions('opensearch', '@opensearch-project/opensearch', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'@opensearch-project/opensearch@${version}'`], false, [ './packages/datadog-plugin-opensearch/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-oracledb/test/integration-test/client.spec.js b/packages/datadog-plugin-oracledb/test/integration-test/client.spec.js index 6a2669ca1f5..5fb44e0d0db 100644 --- a/packages/datadog-plugin-oracledb/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-oracledb/test/integration-test/client.spec.js @@ -16,7 +16,7 @@ describe('esm', () => { withVersions('oracledb', 'oracledb', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'oracledb@${version}'`], false, [ './packages/datadog-plugin-oracledb/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-pg/test/integration-test/client.spec.js b/packages/datadog-plugin-pg/test/integration-test/client.spec.js index da3b89f509f..db252cb9360 100644 --- a/packages/datadog-plugin-pg/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-pg/test/integration-test/client.spec.js @@ -19,7 +19,7 @@ describe('esm', () => { withVersions('pg', 'pg', (version, _, realVersion) => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'pg@${version}'`], false, [ './packages/datadog-plugin-pg/test/integration-test/*']) variants = varySandbox(sandbox, 'server.mjs', { diff --git a/packages/datadog-plugin-pino/test/integration-test/client.spec.js b/packages/datadog-plugin-pino/test/integration-test/client.spec.js index b5034251008..9a60f326628 100644 --- a/packages/datadog-plugin-pino/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-pino/test/integration-test/client.spec.js @@ -17,7 +17,7 @@ describe('esm', () => { withVersions('pino', 'pino', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'pino@${version}'`], false, ['./packages/datadog-plugin-pino/test/integration-test/*']) variants = varySandbox(sandbox, 'server.mjs', 'pino') diff --git a/packages/datadog-plugin-prisma/test/integration-test/client.spec.js b/packages/datadog-plugin-prisma/test/integration-test/client.spec.js index 7f93517cd51..0aec82e64e9 100644 --- a/packages/datadog-plugin-prisma/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-prisma/test/integration-test/client.spec.js @@ -32,7 +32,7 @@ describe('esm', () => { }) beforeEach(async function () { - this.timeout(30000) + this.timeout(60000) agent = await new FakeAgent().start() execSync( './node_modules/.bin/prisma migrate reset --force && ' + @@ -51,7 +51,7 @@ describe('esm', () => { }) it('is instrumented', async function () { - this.timeout(20000) + this.timeout(60000) const res = agent.assertMessageReceived(({ headers, payload }) => { assert.strictEqual(headers.host, `127.0.0.1:${agent.port}`) assertObjectContains(payload, [[{ diff --git a/packages/datadog-plugin-redis/test/integration-test/client.spec.js b/packages/datadog-plugin-redis/test/integration-test/client.spec.js index 35e400b4458..6017ad3966c 100644 --- a/packages/datadog-plugin-redis/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-redis/test/integration-test/client.spec.js @@ -16,7 +16,7 @@ describe('esm', () => { // test against later versions because server.mjs uses newer package syntax withVersions('redis', 'redis', '>=4', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'redis@${version}'`], false, [ './packages/datadog-plugin-redis/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-restify/test/integration-test/client.spec.js b/packages/datadog-plugin-restify/test/integration-test/client.spec.js index cbf2d043272..aded6631aba 100644 --- a/packages/datadog-plugin-restify/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-restify/test/integration-test/client.spec.js @@ -18,7 +18,7 @@ describe('esm', () => { // test against later versions because server.mjs uses newer package syntax withVersions('restify', 'restify', '>3', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'restify@${version}'`], false, ['./packages/datadog-plugin-restify/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-rhea/test/integration-test/client.spec.js b/packages/datadog-plugin-rhea/test/integration-test/client.spec.js index 18e7c55de5c..d90b1afba7b 100644 --- a/packages/datadog-plugin-rhea/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-rhea/test/integration-test/client.spec.js @@ -16,7 +16,7 @@ describe('esm', () => { withVersions('rhea', 'rhea', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'rhea@${version}'`], false, [ './packages/datadog-plugin-rhea/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-router/test/integration-test/client.spec.js b/packages/datadog-plugin-router/test/integration-test/client.spec.js index 4759f2ffd85..d412c529153 100644 --- a/packages/datadog-plugin-router/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-router/test/integration-test/client.spec.js @@ -17,7 +17,7 @@ describe('esm', () => { withVersions('router', 'router', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'router@${version}'`] , false, ['./packages/datadog-plugin-router/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-sharedb/test/integration-test/client.spec.js b/packages/datadog-plugin-sharedb/test/integration-test/client.spec.js index da5915a7838..98c97cd61a9 100644 --- a/packages/datadog-plugin-sharedb/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-sharedb/test/integration-test/client.spec.js @@ -17,7 +17,7 @@ describe('esm', () => { // test against later versions because server.mjs uses newer package syntax withVersions('sharedb', 'sharedb', '>=3', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'sharedb@${version}'`], false, [ './packages/datadog-plugin-sharedb/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-tedious/test/integration-test/client.spec.js b/packages/datadog-plugin-tedious/test/integration-test/client.spec.js index 3e9fd0221b1..19b19a93a03 100644 --- a/packages/datadog-plugin-tedious/test/integration-test/client.spec.js +++ b/packages/datadog-plugin-tedious/test/integration-test/client.spec.js @@ -23,7 +23,7 @@ describe('esm', () => { // test against later versions because server.mjs uses newer package syntax withVersions('tedious', 'tedious', '>=16.0.0', version => { before(async function () { - this.timeout(20000) + this.timeout(60000) sandbox = await createSandbox([`'tedious@${version}'`], false, [ './packages/datadog-plugin-tedious/test/integration-test/*']) }) diff --git a/packages/datadog-plugin-ws/src/server.js b/packages/datadog-plugin-ws/src/server.js index 15bb4b78a60..aea3c6a16d2 100644 --- a/packages/datadog-plugin-ws/src/server.js +++ b/packages/datadog-plugin-ws/src/server.js @@ -21,8 +21,10 @@ class WSServerPlugin extends TracingPlugin { const protocol = `${getRequestProtocol(req)}:` const host = options.headers.host - const path = req.url - const uri = `${protocol}//${host}${path}` + const url = req.url + const indexOfParam = url.indexOf('?') + const route = indexOfParam === -1 ? url : url.slice(0, indexOfParam) + const uri = `${protocol}//${host}${route}` ctx.args = { options } @@ -34,7 +36,7 @@ class WSServerPlugin extends TracingPlugin { 'http.upgraded': 'websocket', 'http.method': options.method, 'http.url': uri, - 'resource.name': `${options.method} ${path}`, + 'resource.name': `${options.method} ${route}`, 'span.kind': 'server' } diff --git a/packages/datadog-plugin-ws/test/index.spec.js b/packages/datadog-plugin-ws/test/index.spec.js index 522cc76dc24..b61f25d9e5d 100644 --- a/packages/datadog-plugin-ws/test/index.spec.js +++ b/packages/datadog-plugin-ws/test/index.spec.js @@ -11,10 +11,12 @@ describe('Plugin', () => { let clientPort = 6015 let client let messageReceived + let route describe('ws', () => { withVersions('ws', 'ws', '>=8.0.0', version => { describe('when using WebSocket', () => { + route = 'test' beforeEach(async () => { await agent.load(['ws'], [{ service: 'some', @@ -24,7 +26,7 @@ describe('Plugin', () => { wsServer = new WebSocket.Server({ port: clientPort }) - client = new WebSocket(`ws://localhost:${clientPort}`) + client = new WebSocket(`ws://localhost:${clientPort}/${route}?active=true`) }) afterEach(async () => { @@ -99,6 +101,7 @@ describe('Plugin', () => { }) agent.assertSomeTraces(traces => { expect(traces[0][0]).to.have.property('name', 'websocket.receive') + expect(traces[0][0]).to.have.property('resource', `websocket /${route}`) }) .then(done) .catch(done) @@ -132,7 +135,7 @@ describe('Plugin', () => { wsServer = new WebSocket.Server({ port: clientPort }) - client = new WebSocket(`ws://localhost:${clientPort}`) + client = new WebSocket(`ws://localhost:${clientPort}/${route}?active=true`) }) afterEach(async () => { @@ -156,17 +159,16 @@ describe('Plugin', () => { wsServer.on('connection', (ws) => { ws.send('test message') }) - messageReceived = false client.on('message', (data) => { expect(data.toString()).to.equal('test message') - messageReceived = true }) return agent.assertSomeTraces(traces => { - expect(traces[0][0]).to.have.property('service', 'custom-ws-service') + expect(traces[0][0]).to.have.property('resource', `websocket /${route}`) expect(traces[0][0]).to.have.property('name', 'websocket.send') expect(traces[0][0]).to.have.property('type', 'websocket') + expect(traces[0][0]).to.have.property('service', 'custom-ws-service') }) }) @@ -177,7 +179,7 @@ describe('Plugin', () => { }) wsServer.on('message', (data) => { expect(data.toString()).to.equal('test message') - expect(messageReceived).prototype.equal(true) + expect(messageReceived).to.equal(true) }) client.on('message', (data) => { diff --git a/packages/dd-trace/test/setup/mocha.js b/packages/dd-trace/test/setup/mocha.js index 6dd2d5a62be..e1f96aa7c8f 100644 --- a/packages/dd-trace/test/setup/mocha.js +++ b/packages/dd-trace/test/setup/mocha.js @@ -4,6 +4,7 @@ const assert = require('node:assert') const util = require('node:util') const { platform } = require('node:os') const path = require('node:path') +const fs = require('node:fs') const { expect } = require('chai') const { describe, it, beforeEach, afterEach, before, after } = require('mocha') @@ -25,6 +26,7 @@ exports.withVersions = withVersions exports.withExports = withExports exports.withNamingSchema = withNamingSchema exports.withPeerService = withPeerService +exports.insertVersionDep = insertVersionDep const testedPlugins = agent.testedPlugins @@ -321,6 +323,30 @@ function getModulePath (moduleName, version) { return `../../../../versions/${moduleName}@${version}` } +/** + * Sets up a symlink to the tested version of a package in the given directory, + * and tears it down once tests are done. + * + * @param {string} dir - The directory to operate in. Typically __dirname. + * @param {string} pkgName - The name of the package being tested. + * @param {string} version - The "version" string, as used with `withVersions` + */ +function insertVersionDep (dir, pkgName, version) { + const nmDir = path.join(dir, 'node_modules') + const pkgDir = path.join(nmDir, pkgName) + + before(() => { + const pkgPath = path.dirname(require(getModulePath(pkgName, version)).pkgJsonPath()) + fs.mkdirSync(nmDir) + fs.symlinkSync(pkgPath, pkgDir) + }) + + after(() => { + fs.unlinkSync(pkgDir) + fs.rmdirSync(nmDir) + }) +} + exports.mochaHooks = { afterEach () { agent.reset()