dd-trace 4.18.0 → 4.20.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.
Files changed (57) hide show
  1. package/LICENSE-3rdparty.csv +2 -2
  2. package/README.md +3 -3
  3. package/ext/kinds.d.ts +1 -0
  4. package/ext/kinds.js +2 -1
  5. package/ext/tags.d.ts +2 -1
  6. package/ext/tags.js +6 -1
  7. package/package.json +6 -6
  8. package/packages/datadog-core/src/storage/async_resource.js +1 -1
  9. package/packages/datadog-esbuild/index.js +1 -20
  10. package/packages/datadog-instrumentations/src/helpers/bundler-register.js +1 -2
  11. package/packages/datadog-instrumentations/src/helpers/instrument.js +1 -1
  12. package/packages/datadog-instrumentations/src/helpers/register.js +1 -1
  13. package/packages/datadog-instrumentations/src/restify.js +14 -1
  14. package/packages/datadog-plugin-kafkajs/src/consumer.js +8 -6
  15. package/packages/datadog-plugin-kafkajs/src/producer.js +9 -6
  16. package/packages/dd-trace/src/appsec/channels.js +1 -1
  17. package/packages/dd-trace/src/appsec/iast/iast-log.js +1 -1
  18. package/packages/dd-trace/src/appsec/iast/iast-plugin.js +1 -1
  19. package/packages/dd-trace/src/appsec/iast/index.js +1 -1
  20. package/packages/dd-trace/src/appsec/iast/path-line.js +1 -1
  21. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +1 -1
  22. package/packages/dd-trace/src/appsec/index.js +1 -1
  23. package/packages/dd-trace/src/appsec/recommended.json +272 -48
  24. package/packages/dd-trace/src/appsec/reporter.js +31 -34
  25. package/packages/dd-trace/src/appsec/rule_manager.js +9 -6
  26. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-itr-configuration.js +17 -7
  27. package/packages/dd-trace/src/config.js +12 -5
  28. package/packages/dd-trace/src/datastreams/processor.js +60 -15
  29. package/packages/dd-trace/src/format.js +6 -1
  30. package/packages/dd-trace/src/id.js +12 -0
  31. package/packages/dd-trace/src/iitm.js +1 -1
  32. package/packages/dd-trace/src/log/channels.js +1 -1
  33. package/packages/dd-trace/src/opentelemetry/span.js +95 -2
  34. package/packages/dd-trace/src/opentelemetry/tracer.js +9 -10
  35. package/packages/dd-trace/src/opentracing/propagation/text_map.js +14 -5
  36. package/packages/dd-trace/src/opentracing/span.js +4 -0
  37. package/packages/dd-trace/src/opentracing/span_context.js +5 -2
  38. package/packages/dd-trace/src/plugin_manager.js +1 -1
  39. package/packages/dd-trace/src/plugins/database.js +1 -1
  40. package/packages/dd-trace/src/plugins/plugin.js +1 -1
  41. package/packages/dd-trace/src/plugins/util/ci.js +6 -19
  42. package/packages/dd-trace/src/plugins/util/git.js +2 -1
  43. package/packages/dd-trace/src/plugins/util/ip_extractor.js +7 -6
  44. package/packages/dd-trace/src/plugins/util/url.js +26 -0
  45. package/packages/dd-trace/src/plugins/util/user-provided-git.js +1 -14
  46. package/packages/dd-trace/src/profiling/config.js +18 -2
  47. package/packages/dd-trace/src/profiling/profilers/events.js +166 -0
  48. package/packages/dd-trace/src/profiling/profilers/shared.js +9 -0
  49. package/packages/dd-trace/src/profiling/profilers/wall.js +116 -58
  50. package/packages/dd-trace/src/ritm.js +1 -1
  51. package/packages/dd-trace/src/span_processor.js +4 -0
  52. package/packages/dd-trace/src/telemetry/dependencies.js +1 -1
  53. package/packages/dd-trace/src/telemetry/index.js +1 -1
  54. package/packages/dd-trace/src/telemetry/logs/index.js +1 -1
  55. package/packages/dd-trace/src/tracer.js +4 -2
  56. package/packages/diagnostics_channel/index.js +0 -3
  57. package/packages/diagnostics_channel/src/index.js +0 -121
@@ -8,7 +8,7 @@ require,@datadog/sketches-js,Apache license 2.0,Copyright 2020 Datadog Inc.
8
8
  require,@opentelemetry/api,Apache license 2.0,Copyright OpenTelemetry Authors
9
9
  require,@opentelemetry/core,Apache license 2.0,Copyright OpenTelemetry Authors
10
10
  require,crypto-randomuuid,MIT,Copyright 2021 Node.js Foundation and contributors
11
- require,diagnostics_channel,MIT,Copyright 2021 Simon D.
11
+ require,dc-polyfill,MIT,Copyright 2023 Datadog Inc.
12
12
  require,ignore,MIT,Copyright 2013 Kael Zhang and contributors
13
13
  require,import-in-the-middle,Apache license 2.0,Copyright 2021 Datadog Inc.
14
14
  require,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
@@ -28,6 +28,7 @@ require,msgpack-lite,MIT,Copyright 2015 Yusuke Kawasaki
28
28
  require,node-abort-controller,MIT,Copyright (c) 2019 Steve Faulkner
29
29
  require,opentracing,MIT,Copyright 2016 Resonance Labs Inc
30
30
  require,path-to-regexp,MIT,Copyright 2014 Blake Embrey
31
+ require,pprof-format,MIT,Copyright 2022 Stephen Belanger
31
32
  require,protobufjs,BSD-3-Clause,Copyright 2016 Daniel Wirtz
32
33
  require,retry,MIT,Copyright 2011 Tim Koschützki Felix Geisendörfer
33
34
  require,semver,ISC,Copyright Isaac Z. Schlueter and Contributors
@@ -62,7 +63,6 @@ dev,mocha,MIT,Copyright 2011-2018 JS Foundation and contributors https://js.foun
62
63
  dev,multer,MIT,Copyright 2014 Hage Yaapa
63
64
  dev,nock,MIT,Copyright 2017 Pedro Teixeira and other contributors
64
65
  dev,nyc,ISC,Copyright 2015 Contributors
65
- dev,pprof-format,MIT,Copyright 2022 Stephen Belanger
66
66
  dev,proxyquire,MIT,Copyright 2013 Thorsten Lorenz
67
67
  dev,rimraf,ISC,Copyright Isaac Z. Schlueter and Contributors
68
68
  dev,sinon,BSD-3-Clause,Copyright 2010-2017 Christian Johansen
package/README.md CHANGED
@@ -202,11 +202,11 @@ To get around this, one can treat all third party modules, or at least third par
202
202
 
203
203
  For these reasons it's necessary to have custom-built bundler plugins. Such plugins are able to instruct the bundler on how to behave, injecting intermediary code and otherwise intercepting the "translated" `require()` calls. The result is that many more packages are then included in the bundled JavaScript file. Some applications can have 100% of modules bundled, however native modules still need to remain external to the bundle.
204
204
 
205
- ### Esbuild Support
205
+ ### ESBuild Support
206
206
 
207
- This library provides experimental esbuild support in the form of an esbuild plugin, and currently requires at least Node.js v16.17 or v18.7. To use the plugin, make sure you have `dd-trace@3+` installed, and then require the `dd-trace/esbuild` module when building your bundle.
207
+ This library provides experimental ESBuild support in the form of an ESBuild plugin. Require the `dd-trace/esbuild` module when building your bundle to enable the plugin.
208
208
 
209
- Here's an example of how one might use `dd-trace` with esbuild:
209
+ Here's an example of how one might use `dd-trace` with ESBuild:
210
210
 
211
211
  ```javascript
212
212
  const ddPlugin = require('dd-trace/esbuild')
package/ext/kinds.d.ts CHANGED
@@ -3,6 +3,7 @@ declare const kinds: {
3
3
  CLIENT: 'client'
4
4
  PRODUCER: 'producer'
5
5
  CONSUMER: 'consumer'
6
+ INTERNAL: 'internal'
6
7
  }
7
8
 
8
9
  export = kinds
package/ext/kinds.js CHANGED
@@ -4,5 +4,6 @@ module.exports = {
4
4
  SERVER: 'server',
5
5
  CLIENT: 'client',
6
6
  PRODUCER: 'producer',
7
- CONSUMER: 'consumer'
7
+ CONSUMER: 'consumer',
8
+ INTERNAL: 'internal'
8
9
  }
package/ext/tags.d.ts CHANGED
@@ -17,7 +17,8 @@ declare const tags: {
17
17
  HTTP_REQUEST_HEADERS: 'http.request.headers'
18
18
  HTTP_RESPONSE_HEADERS: 'http.response.headers'
19
19
  HTTP_USERAGENT: 'http.useragent',
20
- HTTP_CLIENT_IP: 'http.client_ip'
20
+ HTTP_CLIENT_IP: 'http.client_ip',
21
+ PATHWAY_HASH: 'pathway.hash'
21
22
  }
22
23
 
23
24
  export = tags
package/ext/tags.js CHANGED
@@ -22,7 +22,12 @@ const tags = {
22
22
  HTTP_REQUEST_HEADERS: 'http.request.headers',
23
23
  HTTP_RESPONSE_HEADERS: 'http.response.headers',
24
24
  HTTP_USERAGENT: 'http.useragent',
25
- HTTP_CLIENT_IP: 'http.client_ip'
25
+ HTTP_CLIENT_IP: 'http.client_ip',
26
+
27
+ // Messaging
28
+
29
+ // DSM Specific
30
+ PATHWAY_HASH: 'pathway.hash'
26
31
  }
27
32
 
28
33
  // Deprecated
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "4.18.0",
3
+ "version": "4.20.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "test:appsec:ci": "nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" -- npm run test:appsec",
20
20
  "test:appsec:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/appsec/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
21
21
  "test:appsec:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" -- npm run test:appsec:plugins",
22
- "test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,encode,exporters,opentelemetry,opentracing,plugins,service-naming,telemetry}/**/*.spec.js\"",
22
+ "test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,datastreams,encode,exporters,opentelemetry,opentracing,plugins,service-naming,telemetry}/**/*.spec.js\"",
23
23
  "test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/**/*.js\"",
24
24
  "test:instrumentations": "mocha --colors -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
25
25
  "test:instrumentations:ci": "nyc --no-clean --include 'packages/datadog-instrumentations/src/**/*.js' -- npm run test:instrumentations",
@@ -68,16 +68,16 @@
68
68
  "node": ">=16"
69
69
  },
70
70
  "dependencies": {
71
- "@datadog/native-appsec": "^4.0.0",
71
+ "@datadog/native-appsec": "4.0.0",
72
72
  "@datadog/native-iast-rewriter": "2.2.1",
73
- "@datadog/native-iast-taint-tracking": "1.6.3",
73
+ "@datadog/native-iast-taint-tracking": "1.6.4",
74
74
  "@datadog/native-metrics": "^2.0.0",
75
75
  "@datadog/pprof": "4.0.1",
76
76
  "@datadog/sketches-js": "^2.1.0",
77
77
  "@opentelemetry/api": "^1.0.0",
78
78
  "@opentelemetry/core": "^1.14.0",
79
79
  "crypto-randomuuid": "^1.0.0",
80
- "diagnostics_channel": "^1.1.0",
80
+ "dc-polyfill": "^0.1.2",
81
81
  "ignore": "^5.2.4",
82
82
  "import-in-the-middle": "^1.4.2",
83
83
  "int64-buffer": "^0.1.9",
@@ -97,6 +97,7 @@
97
97
  "node-abort-controller": "^3.1.1",
98
98
  "opentracing": ">=0.12.1",
99
99
  "path-to-regexp": "^0.1.2",
100
+ "pprof-format": "^2.0.7",
100
101
  "protobufjs": "^7.2.4",
101
102
  "retry": "^0.13.1",
102
103
  "semver": "^7.5.4"
@@ -133,7 +134,6 @@
133
134
  "multer": "^1.4.5-lts.1",
134
135
  "nock": "^11.3.3",
135
136
  "nyc": "^15.1.0",
136
- "pprof-format": "^2.0.7",
137
137
  "proxyquire": "^1.8.0",
138
138
  "rimraf": "^3.0.0",
139
139
  "sinon": "^15.2.0",
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { createHook, executionAsyncResource } = require('async_hooks')
4
- const { channel } = require('../../../diagnostics_channel')
4
+ const { channel } = require('dc-polyfill')
5
5
 
6
6
  const beforeCh = channel('dd-trace:storage:before')
7
7
  const afterCh = channel('dd-trace:storage:after')
@@ -5,8 +5,6 @@
5
5
  const instrumentations = require('../datadog-instrumentations/src/helpers/instrumentations.js')
6
6
  const hooks = require('../datadog-instrumentations/src/helpers/hooks.js')
7
7
 
8
- warnIfUnsupported()
9
-
10
8
  for (const hook of Object.values(hooks)) {
11
9
  hook()
12
10
  }
@@ -144,7 +142,7 @@ module.exports.setup = function (build) {
144
142
  ${fileCode}
145
143
  })(...arguments);
146
144
  {
147
- const dc = require('diagnostics_channel');
145
+ const dc = require('dc-polyfill');
148
146
  const ch = dc.channel('${CHANNEL}');
149
147
  const mod = module.exports
150
148
  const payload = {
@@ -167,23 +165,6 @@ module.exports.setup = function (build) {
167
165
  })
168
166
  }
169
167
 
170
- // Currently esbuild support requires Node.js >=v16.17 or >=v18.7
171
- // Better yet it would support Node >=v14.17 or >=v16
172
- // Of course, the most ideal would be to support all versions of Node that dd-trace supports.
173
- // Version constraints based on Node's diagnostics_channel support
174
- function warnIfUnsupported () {
175
- const [major, minor] = process.versions.node.split('.').map(Number)
176
- if (
177
- major < 16 ||
178
- (major === 16 && minor < 17) ||
179
- (major === 18 && minor < 7)) {
180
- console.error('WARNING: Esbuild support isn\'t available for older versions of Node.js.')
181
- console.error(`Expected: Node.js >=v16.17 or >=v18.7. Actual: Node.js = ${process.version}.`)
182
- console.error('This application may build properly with this version of Node.js, but unless a')
183
- console.error('more recent version is used at runtime, third party packages won\'t be instrumented.')
184
- }
185
- }
186
-
187
168
  // @see https://github.com/nodejs/node/issues/47000
188
169
  function dotFriendlyResolve (path, directory) {
189
170
  if (path === '.') {
@@ -1,7 +1,6 @@
1
1
  'use strict'
2
2
 
3
- // eslint-disable-next-line n/no-restricted-require
4
- const dc = require('diagnostics_channel')
3
+ const dc = require('dc-polyfill')
5
4
 
6
5
  const {
7
6
  filename,
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const dc = require('../../../diagnostics_channel')
3
+ const dc = require('dc-polyfill')
4
4
  const semver = require('semver')
5
5
  const instrumentations = require('./instrumentations')
6
6
  const { AsyncResource } = require('async_hooks')
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { channel } = require('../../../diagnostics_channel')
3
+ const { channel } = require('dc-polyfill')
4
4
  const path = require('path')
5
5
  const semver = require('semver')
6
6
  const Hook = require('./hook')
@@ -50,7 +50,20 @@ function wrapFn (fn) {
50
50
  enterChannel.publish({ req, route })
51
51
 
52
52
  try {
53
- return fn.apply(this, arguments)
53
+ const result = fn.apply(this, arguments)
54
+ if (result && typeof result === 'object' && typeof result.then === 'function') {
55
+ return result.then(function () {
56
+ nextChannel.publish({ req })
57
+ finishChannel.publish({ req })
58
+ return arguments
59
+ }).catch(function (error) {
60
+ errorChannel.publish({ req, error })
61
+ nextChannel.publish({ req })
62
+ finishChannel.publish({ req })
63
+ throw error
64
+ })
65
+ }
66
+ return result
54
67
  } catch (error) {
55
68
  errorChannel.publish({ req, error })
56
69
  nextChannel.publish({ req })
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ const { getMessageSize, CONTEXT_PROPAGATION_KEY } = require('../../dd-trace/src/datastreams/processor')
3
4
  const ConsumerPlugin = require('../../dd-trace/src/plugins/consumer')
4
5
 
5
6
  class KafkajsConsumerPlugin extends ConsumerPlugin {
@@ -7,13 +8,8 @@ class KafkajsConsumerPlugin extends ConsumerPlugin {
7
8
  static get operation () { return 'consume' }
8
9
 
9
10
  start ({ topic, partition, message, groupId }) {
10
- if (this.config.dsmEnabled) {
11
- this.tracer.decodeDataStreamsContext(message.headers['dd-pathway-ctx'])
12
- this.tracer
13
- .setCheckpoint(['direction:in', `group:${groupId}`, `topic:${topic}`, 'type:kafka'])
14
- }
15
11
  const childOf = extract(this.tracer, message.headers)
16
- this.startSpan({
12
+ const span = this.startSpan({
17
13
  childOf,
18
14
  resource: topic,
19
15
  type: 'worker',
@@ -26,6 +22,12 @@ class KafkajsConsumerPlugin extends ConsumerPlugin {
26
22
  'kafka.partition': partition
27
23
  }
28
24
  })
25
+ if (this.config.dsmEnabled) {
26
+ const payloadSize = getMessageSize(message)
27
+ this.tracer.decodeDataStreamsContext(message.headers[CONTEXT_PROPAGATION_KEY])
28
+ this.tracer
29
+ .setCheckpoint(['direction:in', `group:${groupId}`, `topic:${topic}`, 'type:kafka'], span, payloadSize)
30
+ }
29
31
  }
30
32
  }
31
33
 
@@ -2,6 +2,8 @@
2
2
 
3
3
  const ProducerPlugin = require('../../dd-trace/src/plugins/producer')
4
4
  const { encodePathwayContext } = require('../../dd-trace/src/datastreams/pathway')
5
+ const { getMessageSize, CONTEXT_PROPAGATION_KEY } = require('../../dd-trace/src/datastreams/processor')
6
+
5
7
  const BOOTSTRAP_SERVERS_KEY = 'messaging.kafka.bootstrap.servers'
6
8
 
7
9
  class KafkajsProducerPlugin extends ProducerPlugin {
@@ -11,11 +13,6 @@ class KafkajsProducerPlugin extends ProducerPlugin {
11
13
 
12
14
  start ({ topic, messages, bootstrapServers }) {
13
15
  let pathwayCtx
14
- if (this.config.dsmEnabled) {
15
- const dataStreamsContext = this.tracer
16
- .setCheckpoint(['direction:out', `topic:${topic}`, 'type:kafka'])
17
- pathwayCtx = encodePathwayContext(dataStreamsContext)
18
- }
19
16
  const span = this.startSpan({
20
17
  resource: topic,
21
18
  meta: {
@@ -31,8 +28,14 @@ class KafkajsProducerPlugin extends ProducerPlugin {
31
28
  }
32
29
  for (const message of messages) {
33
30
  if (typeof message === 'object') {
34
- if (this.config.dsmEnabled) message.headers['dd-pathway-ctx'] = pathwayCtx
35
31
  this.tracer.inject(span, 'text_map', message.headers)
32
+ if (this.config.dsmEnabled) {
33
+ const payloadSize = getMessageSize(message)
34
+ const dataStreamsContext = this.tracer
35
+ .setCheckpoint(['direction:out', `topic:${topic}`, 'type:kafka'], span, payloadSize)
36
+ pathwayCtx = encodePathwayContext(dataStreamsContext)
37
+ message.headers[CONTEXT_PROPAGATION_KEY] = pathwayCtx
38
+ }
36
39
  }
37
40
  }
38
41
  }
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const dc = require('../../../diagnostics_channel')
3
+ const dc = require('dc-polyfill')
4
4
 
5
5
  // TODO: use TBD naming convention
6
6
  module.exports = {
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const dc = require('../../../../diagnostics_channel')
3
+ const dc = require('dc-polyfill')
4
4
  const log = require('../../log')
5
5
  const { calculateDDBasePath } = require('../../util')
6
6
 
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { channel } = require('../../../../diagnostics_channel')
3
+ const { channel } = require('dc-polyfill')
4
4
 
5
5
  const iastLog = require('./iast-log')
6
6
  const Plugin = require('../../plugins/plugin')
@@ -3,7 +3,7 @@ const { enableAllAnalyzers, disableAllAnalyzers } = require('./analyzers')
3
3
  const web = require('../../plugins/util/web')
4
4
  const { storage } = require('../../../../datadog-core')
5
5
  const overheadController = require('./overhead-controller')
6
- const dc = require('../../../../diagnostics_channel')
6
+ const dc = require('dc-polyfill')
7
7
  const iastContextFunctions = require('./iast-context')
8
8
  const {
9
9
  enableTaintTracking,
@@ -13,7 +13,7 @@ const pathLine = {
13
13
  }
14
14
 
15
15
  const EXCLUDED_PATHS = [
16
- path.join(path.sep, 'node_modules', 'diagnostics_channel')
16
+ path.join(path.sep, 'node_modules', 'dc-polyfill')
17
17
  ]
18
18
  const EXCLUDED_PATH_PREFIXES = [
19
19
  'node:diagnostics_channel',
@@ -7,7 +7,7 @@ const { isPrivateModule, isNotLibraryFile } = require('./filter')
7
7
  const { csiMethods } = require('./csi-methods')
8
8
  const { getName } = require('../telemetry/verbosity')
9
9
  const { getRewriteFunction } = require('./rewriter-telemetry')
10
- const dc = require('../../../../../diagnostics_channel')
10
+ const dc = require('dc-polyfill')
11
11
 
12
12
  const hardcodedSecretCh = dc.channel('datadog:secrets:result')
13
13
  let rewriter
@@ -36,7 +36,7 @@ function enable (_config) {
36
36
 
37
37
  setTemplates(_config)
38
38
 
39
- RuleManager.applyRules(_config.appsec.rules, _config.appsec)
39
+ RuleManager.loadRules(_config.appsec)
40
40
 
41
41
  remoteConfig.enableWafUpdate(_config.appsec)
42
42