Skip to content

Commit

Permalink
Merge branch 'master' into juan-fernandez/add-quarantined-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-fernandez committed Feb 17, 2025
2 parents 7661f31 + b599fab commit 4576e12
Show file tree
Hide file tree
Showing 33 changed files with 828 additions and 117 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ services:
ports:
- "127.0.0.1:6379:6379"
mongo:
image: circleci/mongo:3.6
image: circleci/mongo:4.4
platform: linux/amd64
ports:
- "127.0.0.1:27017:27017"
Expand Down
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default [
'**/versions', // This is effectively a node_modules tree.
'**/acmeair-nodejs', // We don't own this.
'**/vendor', // Generally, we didn't author this code.
'integration-tests/debugger/target-app/source-map-support/index.js', // Generated
'integration-tests/esbuild/out.js', // Generated
'integration-tests/esbuild/aws-sdk-out.js', // Generated
'packages/dd-trace/src/appsec/blocked_templates.js', // TODO Why is this ignored?
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/debugger/basic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ function assertBasicInputPayload (t, payload) {
service: 'node',
message: 'Hello World!',
logger: {
name: t.breakpoint.file,
name: t.breakpoint.deployedFile,
method: 'fooHandler',
version,
thread_name: 'MainThread'
Expand All @@ -544,7 +544,7 @@ function assertBasicInputPayload (t, payload) {
probe: {
id: t.rcConfig.config.id,
version: 0,
location: { file: t.breakpoint.file, lines: [String(t.breakpoint.line)] }
location: { file: t.breakpoint.deployedFile, lines: [String(t.breakpoint.line)] }
},
language: 'javascript'
}
Expand Down
27 changes: 27 additions & 0 deletions integration-tests/debugger/source-map-support.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

const { assert } = require('chai')
const { setup } = require('./utils')

describe('Dynamic Instrumentation', function () {
describe('source map support', function () {
const t = setup({
testApp: 'target-app/source-map-support/index.js',
testAppSource: 'target-app/source-map-support/index.ts'
})

beforeEach(t.triggerBreakpoint)

it('should support source maps', function (done) {
t.agent.on('debugger-input', ({ payload: [{ 'debugger.snapshot': { probe: { location } } }] }) => {
assert.deepEqual(location, {
file: 'target-app/source-map-support/index.ts',
lines: ['9']
})
done()
})

t.agent.addRemoteConfig(t.rcConfig)
})
})
})
13 changes: 13 additions & 0 deletions integration-tests/debugger/target-app/source-map-support/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions integration-tests/debugger/target-app/source-map-support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require('dd-trace/init')

import { createServer } from 'node:http'

const server = createServer((req, res) => {
// Blank lines below to ensure line numbers in transpiled file differ from original file


res.end('hello world') // BREAKPOINT: /
})

server.listen(process.env.APP_PORT, () => {
process.send?.({ port: process.env.APP_PORT })
})
20 changes: 12 additions & 8 deletions integration-tests/debugger/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ module.exports = {
setup
}

function setup ({ env, testApp } = {}) {
function setup ({ env, testApp, testAppSource } = {}) {
let sandbox, cwd, appPort
const breakpoints = getBreakpointInfo({ file: testApp, stackIndex: 1 }) // `1` to disregard the `setup` function
const breakpoints = getBreakpointInfo({
deployedFile: testApp,
sourceFile: testAppSource,
stackIndex: 1 // `1` to disregard the `setup` function
})
const t = {
breakpoint: breakpoints[0],
breakpoints,
Expand Down Expand Up @@ -71,7 +75,7 @@ function setup ({ env, testApp } = {}) {
sandbox = await createSandbox(['fastify']) // TODO: Make this dynamic
cwd = sandbox.folder
// The sandbox uses the `integration-tests` folder as its root
t.appFile = join(cwd, 'debugger', breakpoints[0].file)
t.appFile = join(cwd, 'debugger', breakpoints[0].deployedFile)
})

after(async function () {
Expand Down Expand Up @@ -110,8 +114,8 @@ function setup ({ env, testApp } = {}) {
return t
}

function getBreakpointInfo ({ file, stackIndex = 0 }) {
if (!file) {
function getBreakpointInfo ({ deployedFile, sourceFile = deployedFile, stackIndex = 0 } = {}) {
if (!deployedFile) {
// First, get the filename of file that called this function
const testFile = new Error().stack
.split('\n')[stackIndex + 2] // +2 to skip this function + the first line, which is the error message
Expand All @@ -120,17 +124,17 @@ function getBreakpointInfo ({ file, stackIndex = 0 }) {
.split(':')[0]

// Then, find the corresponding file in which the breakpoint(s) exists
file = join('target-app', basename(testFile).replace('.spec', ''))
deployedFile = sourceFile = join('target-app', basename(testFile).replace('.spec', ''))
}

// Finally, find the line number(s) of the breakpoint(s)
const lines = readFileSync(join(__dirname, file), 'utf8').split('\n')
const lines = readFileSync(join(__dirname, sourceFile), 'utf8').split('\n')
const result = []
for (let i = 0; i < lines.length; i++) {
const index = lines[i].indexOf(BREAKPOINT_TOKEN)
if (index !== -1) {
const url = lines[i].slice(index + BREAKPOINT_TOKEN.length + 1).trim()
result.push({ file, line: i + 1, url })
result.push({ sourceFile, deployedFile, line: i + 1, url })
}
}

Expand Down
10 changes: 8 additions & 2 deletions integration-tests/playwright/playwright.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const {
TEST_SOURCE_START,
TEST_TYPE,
TEST_SOURCE_FILE,
TEST_CONFIGURATION_BROWSER_NAME,
TEST_PARAMETERS,
TEST_BROWSER_NAME,
TEST_IS_NEW,
TEST_IS_RETRY,
TEST_EARLY_FLAKE_ENABLED,
Expand Down Expand Up @@ -155,7 +156,12 @@ versions.forEach((version) => {
assert.propertyVal(testEvent.content.meta, 'test.customtag', 'customvalue')
assert.propertyVal(testEvent.content.meta, 'test.customtag2', 'customvalue2')
// Adds the browser used
assert.propertyVal(testEvent.content.meta, TEST_CONFIGURATION_BROWSER_NAME, 'chromium')
assert.propertyVal(testEvent.content.meta, TEST_BROWSER_NAME, 'chromium')
assert.propertyVal(
testEvent.content.meta,
TEST_PARAMETERS,
JSON.stringify({ arguments: { browser: 'chromium' }, metadata: {} })
)
assert.exists(testEvent.content.metrics[DD_HOST_CPU_COUNT])
})

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"bench:e2e:ci-visibility": "node benchmark/e2e-ci/benchmark-run.js",
"type:doc": "cd docs && yarn && yarn build",
"type:test": "cd docs && yarn && yarn test",
"lint": "node scripts/check_licenses.js && eslint . && yarn audit",
"lint:fix": "node scripts/check_licenses.js && eslint . --fix && yarn audit",
"lint": "node scripts/check_licenses.js && eslint . --max-warnings 0 && yarn audit",
"lint:fix": "node scripts/check_licenses.js && eslint . --max-warnings 0 --fix && yarn audit",
"release:proposal": "node scripts/release/proposal",
"services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
"test": "SERVICES=* yarn services && mocha --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
Expand Down
8 changes: 8 additions & 0 deletions packages/datadog-instrumentations/src/openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ const V4_PACKAGE_SHIMS = [
targetClass: 'Translations',
baseResource: 'audio.translations',
methods: ['create']
},
{
file: 'resources/chat/completions/completions.js',
targetClass: 'Completions',
baseResource: 'chat.completions',
methods: ['create'],
streamedResponse: true,
versions: ['>=4.85.0']
}
]

Expand Down
8 changes: 7 additions & 1 deletion packages/datadog-plugin-cucumber/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const {
const id = require('../../dd-trace/src/id')

const BREAKPOINT_HIT_GRACE_PERIOD_MS = 200
const BREAKPOINT_SET_GRACE_PERIOD_MS = 200
const isCucumberWorker = !!process.env.CUCUMBER_WORKER_ID

function getTestSuiteTags (testSuiteSpan) {
Expand Down Expand Up @@ -257,7 +258,12 @@ class CucumberPlugin extends CiPlugin {
const { file, line, stackIndex } = probeInformation
this.runningTestProbe = { file, line }
this.testErrorStackIndex = stackIndex
// TODO: we're not waiting for setProbePromise to be resolved, so there might be race conditions
const waitUntil = Date.now() + BREAKPOINT_SET_GRACE_PERIOD_MS
while (Date.now() < waitUntil) {
// TODO: To avoid a race condition, we should wait until `probeInformation.setProbePromise` has resolved.
// However, Cucumber doesn't have a mechanism for waiting asyncrounously here, so for now, we'll have to
// fall back to a fixed syncronous delay.
}
}
}
span.setTag(TEST_STATUS, 'fail')
Expand Down
2 changes: 1 addition & 1 deletion packages/datadog-plugin-dd-trace-api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = class DdTraceApiPlugin extends Plugin {
})

const handleEvent = (name) => {
const counter = apiMetrics.count('dd_trace_api.called', [
const counter = apiMetrics.count('public_api.called', [
`name:${name.replaceAll(':', '.')}`,
'api_version:v1',
injectionEnabledTag
Expand Down
9 changes: 8 additions & 1 deletion packages/datadog-plugin-mocha/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const {
const id = require('../../dd-trace/src/id')
const log = require('../../dd-trace/src/log')

const BREAKPOINT_SET_GRACE_PERIOD_MS = 200

function getTestSuiteLevelVisibilityTags (testSuiteSpan) {
const testSuiteSpanContext = testSuiteSpan.context()
const suiteTags = {
Expand Down Expand Up @@ -281,7 +283,12 @@ class MochaPlugin extends CiPlugin {
this.runningTestProbe = { file, line }
this.testErrorStackIndex = stackIndex
test._ddShouldWaitForHitProbe = true
// TODO: we're not waiting for setProbePromise to be resolved, so there might be race conditions
const waitUntil = Date.now() + BREAKPOINT_SET_GRACE_PERIOD_MS
while (Date.now() < waitUntil) {
// TODO: To avoid a race condition, we should wait until `probeInformation.setProbePromise` has resolved.
// However, Mocha doesn't have a mechanism for waiting asyncrounously here, so for now, we'll have to
// fall back to a fixed syncronous delay.
}
}
}

Expand Down
30 changes: 28 additions & 2 deletions packages/datadog-plugin-mongodb-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class MongodbCorePlugin extends DatabasePlugin {
start ({ ns, ops, options = {}, name }) {
const query = getQuery(ops)
const resource = truncate(getResource(this, ns, query, name))
this.startSpan(this.operationName(), {
service: this.serviceName({ pluginConfig: this.config }),
const service = this.serviceName({ pluginConfig: this.config })
const span = this.startSpan(this.operationName(), {
service,
resource,
type: 'mongodb',
kind: 'client',
Expand All @@ -24,6 +25,7 @@ class MongodbCorePlugin extends DatabasePlugin {
'out.port': options.port
}
})
ops = this.injectDbmCommand(span, ops, service)
}

getPeerService (tags) {
Expand All @@ -34,6 +36,30 @@ class MongodbCorePlugin extends DatabasePlugin {
}
return super.getPeerService(tags)
}

injectDbmCommand (span, command, serviceName) {
const dbmTraceComment = this.createDbmComment(span, serviceName)

if (!dbmTraceComment) {
return command
}

// create a copy of the command to avoid mutating the original
const dbmTracedCommand = { ...command }

if (dbmTracedCommand.comment) {
// if the command already has a comment, append the dbm trace comment
if (typeof dbmTracedCommand.comment === 'string') {
dbmTracedCommand.comment += `,${dbmTraceComment}`
} else if (Array.isArray(dbmTracedCommand.comment)) {
dbmTracedCommand.comment.push(dbmTraceComment)
} // do nothing if the comment is not a string or an array
} else {
dbmTracedCommand.comment = dbmTraceComment
}

return dbmTracedCommand
}
}

function sanitizeBigInt (data) {
Expand Down
Loading

0 comments on commit 4576e12

Please sign in to comment.