Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitlab/benchmarks/bp-runner.fail-on-breach.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
66 changes: 39 additions & 27 deletions integration-tests/helpers/index.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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 () => {} }
}
Expand All @@ -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 "[email protected]"', { 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 "[email protected]"', { 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 {
Expand All @@ -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}`)
}
}
}
Expand Down Expand Up @@ -522,14 +522,26 @@ 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<string, string|undefined>} [additionalEnvArgs]
*/
/**
* @param {string} cwd
* @param {string} serverFile
* @param {string|number} agentPort
* @param {function} [stdioHandler]
* @param {Record<string, string|undefined>} [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<string, string|undefined>} */ ({
NODE_OPTIONS: `--loader=${hookFile}`,
DD_TRACE_AGENT_PORT: String(agentPort)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/*'])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/*'])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/*'])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/*'])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/*'])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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}`)
Expand All @@ -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}`)
Expand All @@ -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}`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dd-trace/init.js'
import fastify from 'fastify'
import { createAndStartServer } from './helper.mjs'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dd-trace/init.js'
import * as Fastify from 'fastify'
import { createAndStartServer } from './helper.mjs'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dd-trace/init.js'
import Fastify from 'fastify'
import { createAndStartServer } from './helper.mjs'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/*'])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/*'])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/*'])
})
Expand Down
Loading
Loading