dd-trace 5.77.0 → 5.79.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "5.77.0",
3
+ "version": "5.79.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -46,6 +46,8 @@
46
46
  "test:llmobs:sdk:ci": "nyc --no-clean --include \"packages/dd-trace/src/llmobs/**/*.js\" -- npm run test:llmobs:sdk",
47
47
  "test:llmobs:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/llmobs/plugins/@($(echo $PLUGINS))/*.spec.js\"",
48
48
  "test:llmobs:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/src/llmobs/**/*.js\" -- npm run test:llmobs:plugins",
49
+ "test:openfeature": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/openfeature/*.spec.js\"",
50
+ "test:openfeature:ci": "nyc --no-clean --include \"packages/dd-trace/src/openfeature/**/*.js\" -- npm run test:openfeature",
49
51
  "test:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/@($(echo ${SPEC:-'*'})).spec.js\"",
50
52
  "test:plugins:ci": "yarn services && nyc --no-clean --include \"packages/datadog-plugin-@($(echo $PLUGINS))/src/**/*.js\" -- npm run test:plugins",
51
53
  "test:plugins:ci:flaky": "yarn services && nyc --no-clean --include \"packages/datadog-plugin-@($(echo $PLUGINS))/src/**/*.js\" -- npm run test:plugins -- --bail --retries 2",
@@ -125,7 +127,7 @@
125
127
  "@datadog/native-appsec": "10.3.0",
126
128
  "@datadog/native-iast-taint-tracking": "4.0.0",
127
129
  "@datadog/native-metrics": "3.1.1",
128
- "@datadog/openfeature-node-server": "0.1.0-preview.15",
130
+ "@datadog/openfeature-node-server": "^0.2.0",
129
131
  "@datadog/pprof": "5.12.0",
130
132
  "@datadog/sketches-js": "2.1.1",
131
133
  "@datadog/wasm-js-rewriter": "5.0.1",
@@ -165,7 +167,7 @@
165
167
  "@eslint/js": "^9.39.0",
166
168
  "@msgpack/msgpack": "^3.1.2",
167
169
  "@openfeature/core": "^1.9.0",
168
- "@openfeature/server-sdk": "^1.20.0",
170
+ "@openfeature/server-sdk": "~1.20.0",
169
171
  "@stylistic/eslint-plugin": "^5.5.0",
170
172
  "@types/chai": "^4.3.16",
171
173
  "@types/mocha": "^10.0.10",
@@ -1345,9 +1345,6 @@ addHook({
1345
1345
  }
1346
1346
  }
1347
1347
  return returnedValue
1348
- } catch (error) {
1349
- testSuiteErrorCh.publish({ error, testSuiteAbsolutePath: this._testPath })
1350
- throw error
1351
1348
  } finally {
1352
1349
  // Restore original prepareStackTrace
1353
1350
  Error.prepareStackTrace = originalPrepareStackTrace
@@ -282,11 +282,7 @@ class JestPlugin extends CiPlugin {
282
282
  log.warn('"ci:jest:test-suite:finish": no span found for test suite absolute path %s', testSuiteAbsolutePath)
283
283
  return
284
284
  }
285
- const hasStatus = testSuiteSpan.context()._tags[TEST_STATUS]
286
- if (!hasStatus) {
287
- // The status may have been set in 'ci:jest:test-suite:error'
288
- testSuiteSpan.setTag(TEST_STATUS, status)
289
- }
285
+ testSuiteSpan.setTag(TEST_STATUS, status)
290
286
  if (error) {
291
287
  testSuiteSpan.setTag('error', error)
292
288
  testSuiteSpan.setTag(TEST_STATUS, 'fail')
@@ -323,7 +319,6 @@ class JestPlugin extends CiPlugin {
323
319
  } else if (errorMessage) {
324
320
  runningTestSuiteSpan.setTag('error', new Error(errorMessage))
325
321
  }
326
- runningTestSuiteSpan.setTag(TEST_STATUS, 'fail')
327
322
  })
328
323
 
329
324
  /**
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { readFileSync } = require('fs')
4
- const { parse, extract } = require('jest-docblock')
4
+ const { parse } = require('jest-docblock')
5
5
 
6
6
  const { getTestSuitePath } = require('../../dd-trace/src/plugins/util/test')
7
7
  const log = require('../../dd-trace/src/log')
@@ -61,29 +61,59 @@ function getJestTestName (test, shouldStripSeed = false) {
61
61
  return testName
62
62
  }
63
63
 
64
+ const globalDocblockRegExp = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/
65
+
64
66
  function isMarkedAsUnskippable (test) {
65
- let docblocks
67
+ let testSource
66
68
 
67
69
  try {
68
- const testSource = readFileSync(test.path, 'utf8')
69
- docblocks = parse(extract(testSource))
70
+ testSource = readFileSync(test.path, 'utf8')
70
71
  } catch {
71
- // If we have issues parsing the file, we'll assume no unskippable was passed
72
72
  return false
73
73
  }
74
74
 
75
- // docblocks were correctly parsed but it does not include a @datadog block
76
- if (!docblocks?.datadog) {
77
- return false
78
- }
75
+ const re = globalDocblockRegExp
76
+ re.lastIndex = 0
77
+ let commentsChecked = 0
78
+
79
+ while (testSource.length) {
80
+ const match = re.exec(testSource)
81
+ if (!match) break
82
+ const comment = match[1]
83
+
84
+ let docblocks
85
+ try {
86
+ docblocks = parse(comment)
87
+ } catch {
88
+ // Skip unparsable comment and continue scanning
89
+ if (commentsChecked++ >= 10) {
90
+ return false
91
+ }
92
+ continue
93
+ }
79
94
 
80
- try {
81
- return JSON.parse(docblocks.datadog).unskippable
82
- } catch {
83
- // If the @datadog block comment is present but malformed, we'll run the suite
84
- log.warn('@datadog block comment is malformed.')
85
- return true
95
+ if (docblocks?.datadog) {
96
+ try {
97
+ // @ts-expect-error The datadog type is defined by us and may only be a string.
98
+ return JSON.parse(docblocks.datadog).unskippable
99
+ } catch {
100
+ // If the @datadog block comment is present but malformed, we'll run the suite
101
+ log.warn('@datadog block comment is malformed.')
102
+ return true
103
+ }
104
+ }
105
+
106
+ if (commentsChecked++ >= 10) {
107
+ return false
108
+ }
109
+
110
+ // To stop as soon as no doc blocks are found, slice the source. That way the
111
+ // regexp works by using the `^` anchor. Without it, it would continue
112
+ // scanning the rest of the file.
113
+ testSource = testSource.slice(match[0].length)
86
114
  }
115
+
116
+ return false
87
117
  }
88
118
 
89
119
  function getJestSuitesToRun (skippableSuites, originalTests, rootDir) {
@@ -2,6 +2,7 @@
2
2
 
3
3
  const path = require('path')
4
4
  const process = require('process')
5
+ const { fileURLToPath } = require('url')
5
6
  const { ddBasePath } = require('../../util')
6
7
  const { getOriginalPathAndLineFromSourceMap } = require('./taint-tracking/rewriter')
7
8
  const pathLine = {
@@ -31,11 +32,11 @@ function getNonDDCallSiteFrames (callSiteFrames, externallyExcludedPaths) {
31
32
  const result = []
32
33
 
33
34
  for (const callsite of callSiteFrames) {
34
- let filepath = callsite.file
35
+ let filepath = callsite.file?.startsWith('file://') ? fileURLToPath(callsite.file) : callsite.file
35
36
 
36
37
  if (globalThis.__DD_ESBUILD_IAST_WITH_SM) {
37
38
  const callsiteLocation = {
38
- path: getRelativePath(filepath),
39
+ path: filepath,
39
40
  line: callsite.line,
40
41
  column: callsite.column
41
42
  }
@@ -16,47 +16,17 @@ const {
16
16
  incrementWafConfigErrors,
17
17
  incrementWafRequests
18
18
  } = require('./waf')
19
- const telemetryMetrics = require('../../telemetry/metrics')
20
19
 
21
20
  const metricsStoreMap = new WeakMap()
22
21
 
23
- const appsecMetrics = telemetryMetrics.manager.namespace('appsec')
24
-
25
22
  let enabled = false
26
- let interval
27
- const SUPPORTED_ORIGINS = new Set(['env_var', 'code', 'remote_config', 'unknown'])
28
23
 
29
24
  function enable (config) {
30
- const telemetryConfig = config.telemetry
31
- enabled = telemetryConfig?.enabled && telemetryConfig.metrics
32
-
33
- if (enabled) {
34
- let origin = 'remote_config'
35
-
36
- if (config.appsec.enabled) {
37
- origin = config.getOrigin('appsec.enabled')
38
-
39
- if (!SUPPORTED_ORIGINS.has(origin)) {
40
- origin = 'unknown'
41
- }
42
- }
43
-
44
- const gauge = appsecMetrics.gauge('enabled', { origin })
45
- gauge.track()
46
-
47
- interval = setInterval(() => {
48
- gauge.track()
49
- }, telemetryConfig.heartbeatInterval)
50
- interval.unref?.()
51
- }
25
+ enabled = config.telemetry?.enabled && config.telemetry?.metrics
52
26
  }
53
27
 
54
28
  function disable () {
55
29
  enabled = false
56
- if (interval) {
57
- clearInterval(interval)
58
- interval = undefined
59
- }
60
30
  }
61
31
 
62
32
  function newStore () {
@@ -2,6 +2,16 @@
2
2
 
3
3
  const inspector = require('./inspector_promises_polyfill')
4
4
 
5
- const session = module.exports = new inspector.Session()
5
+ /**
6
+ * @typedef {import('node:events').EventEmitter & {
7
+ * connect: () => void,
8
+ * connectToMainThread: () => void
9
+ * disconnect: () => void,
10
+ * post: (method: string, params?: object) => Promise<any>,
11
+ * }} CDPSession
12
+ */
13
+ const session = /** @type {CDPSession} */ (new inspector.Session())
6
14
 
7
15
  session.connectToMainThread()
16
+
17
+ module.exports = session
@@ -6,6 +6,7 @@ const RemoteConfigManager = require('./manager')
6
6
  const RemoteConfigCapabilities = require('./capabilities')
7
7
  const { setCollectionMode } = require('../appsec/user_tracking')
8
8
  const log = require('../log')
9
+ const { updateConfig } = require('../telemetry')
9
10
 
10
11
  let rc
11
12
 
@@ -62,7 +63,8 @@ function enable (config, appsec) {
62
63
 
63
64
  function enableOrDisableAppsec (action, rcConfig, config, appsec) {
64
65
  if (typeof rcConfig.asm?.enabled === 'boolean') {
65
- const shouldEnable = action === 'apply' || action === 'modify'
66
+ const isRemoteConfigControlling = action === 'apply' || action === 'modify'
67
+ const shouldEnable = isRemoteConfigControlling
66
68
  ? rcConfig.asm.enabled // take control
67
69
  : config.appsec.enabled // give back control to local config
68
70
 
@@ -71,6 +73,14 @@ function enableOrDisableAppsec (action, rcConfig, config, appsec) {
71
73
  } else {
72
74
  appsec.disable()
73
75
  }
76
+
77
+ updateConfig([
78
+ {
79
+ name: 'appsec.enabled',
80
+ origin: isRemoteConfigControlling ? 'remote_config' : config.getOrigin('appsec.enabled'),
81
+ value: shouldEnable
82
+ }
83
+ ], config)
74
84
  }
75
85
  }
76
86