dd-trace 2.24.0 → 2.25.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 (38) hide show
  1. package/LICENSE-3rdparty.csv +1 -0
  2. package/index.d.ts +16 -0
  3. package/package.json +6 -4
  4. package/packages/datadog-instrumentations/src/helpers/register.js +7 -0
  5. package/packages/datadog-instrumentations/src/mocha.js +33 -8
  6. package/packages/datadog-instrumentations/src/pg.js +6 -1
  7. package/packages/datadog-plugin-http/src/client.js +1 -1
  8. package/packages/datadog-plugin-jest/src/index.js +2 -2
  9. package/packages/datadog-plugin-mocha/src/index.js +2 -2
  10. package/packages/datadog-plugin-pg/src/index.js +1 -1
  11. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +6 -6
  12. package/packages/dd-trace/src/appsec/iast/index.js +8 -3
  13. package/packages/dd-trace/src/appsec/iast/overhead-controller.js +20 -1
  14. package/packages/dd-trace/src/appsec/iast/taint-tracking/csi-methods.js +6 -1
  15. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +24 -6
  16. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +63 -41
  17. package/packages/dd-trace/src/appsec/recommended.json +75 -8
  18. package/packages/dd-trace/src/appsec/remote_config/manager.js +2 -2
  19. package/packages/dd-trace/src/config.js +24 -5
  20. package/packages/dd-trace/src/exporters/common/request.js +33 -1
  21. package/packages/dd-trace/src/format.js +5 -1
  22. package/packages/dd-trace/src/lambda/handler.js +72 -0
  23. package/packages/dd-trace/src/lambda/index.js +5 -0
  24. package/packages/dd-trace/src/lambda/runtime/errors.js +20 -0
  25. package/packages/dd-trace/src/lambda/runtime/patch.js +74 -0
  26. package/packages/dd-trace/src/lambda/runtime/ritm.js +143 -0
  27. package/packages/dd-trace/src/plugin_manager.js +4 -0
  28. package/packages/dd-trace/src/plugins/ci_plugin.js +6 -0
  29. package/packages/dd-trace/src/plugins/database.js +4 -4
  30. package/packages/dd-trace/src/plugins/log_plugin.js +2 -2
  31. package/packages/dd-trace/src/plugins/util/ci.js +5 -2
  32. package/packages/dd-trace/src/plugins/util/test.js +2 -2
  33. package/packages/dd-trace/src/plugins/util/user-provided-git.js +14 -1
  34. package/packages/dd-trace/src/priority_sampler.js +6 -2
  35. package/packages/dd-trace/src/proxy.js +4 -3
  36. package/packages/dd-trace/src/ritm.js +7 -1
  37. package/packages/dd-trace/src/span_processor.js +13 -0
  38. package/packages/dd-trace/src/span_sampler.js +1 -4
@@ -25,8 +25,8 @@ class DatabasePlugin extends StoragePlugin {
25
25
  }
26
26
  }
27
27
 
28
- createDBMPropagationCommentService () {
29
- this.encodingServiceTags('dddbs', 'encodedDddbs', this.config.service)
28
+ createDBMPropagationCommentService (serviceName) {
29
+ this.encodingServiceTags('dddbs', 'encodedDddbs', serviceName)
30
30
  this.encodingServiceTags('dde', 'encodedDde', this.tracer._env)
31
31
  this.encodingServiceTags('ddps', 'encodedDdps', this.tracer._service)
32
32
  this.encodingServiceTags('ddpv', 'encodedDdpv', this.tracer._version)
@@ -37,11 +37,11 @@ class DatabasePlugin extends StoragePlugin {
37
37
  `ddps='${encodedDdps}',ddpv='${encodedDdpv}'`
38
38
  }
39
39
 
40
- injectDbmQuery (query) {
40
+ injectDbmQuery (query, serviceName) {
41
41
  if (this.config.dbmPropagationMode === 'disabled') {
42
42
  return query
43
43
  }
44
- const servicePropagation = this.createDBMPropagationCommentService()
44
+ const servicePropagation = this.createDBMPropagationCommentService(serviceName)
45
45
  if (this.config.dbmPropagationMode === 'service') {
46
46
  return `/*${servicePropagation}*/ ${query}`
47
47
  } else if (this.config.dbmPropagationMode === 'full') {
@@ -43,8 +43,8 @@ module.exports = class LogPlugin extends Plugin {
43
43
  const store = storage.getStore()
44
44
  const span = store && store.span
45
45
 
46
- if (!span) return
47
-
46
+ // NOTE: This needs to run whether or not there is a span
47
+ // so service, version, and env will always get injected.
48
48
  const holder = {}
49
49
  this.tracer.inject(span, LOG, holder)
50
50
  arg.message = messageProxy(arg.message, holder)
@@ -235,7 +235,8 @@ module.exports = {
235
235
  GITHUB_SHA,
236
236
  GITHUB_REPOSITORY,
237
237
  GITHUB_SERVER_URL,
238
- GITHUB_RUN_ATTEMPT
238
+ GITHUB_RUN_ATTEMPT,
239
+ GITHUB_JOB
239
240
  } = env
240
241
 
241
242
  const repositoryURL = `${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git`
@@ -259,6 +260,7 @@ module.exports = {
259
260
  [GIT_COMMIT_SHA]: GITHUB_SHA,
260
261
  [GIT_REPOSITORY_URL]: repositoryURL,
261
262
  [CI_JOB_URL]: jobUrl,
263
+ [CI_JOB_NAME]: GITHUB_JOB,
262
264
  [CI_WORKSPACE_PATH]: GITHUB_WORKSPACE,
263
265
  [refKey]: ref,
264
266
  [CI_ENV_VARS]: JSON.stringify({
@@ -353,7 +355,8 @@ module.exports = {
353
355
  [GIT_COMMIT_AUTHOR_EMAIL]: BUILD_REQUESTEDFOREMAIL,
354
356
  [GIT_COMMIT_MESSAGE]: BUILD_SOURCEVERSIONMESSAGE,
355
357
  [CI_STAGE_NAME]: SYSTEM_STAGEDISPLAYNAME,
356
- [CI_JOB_NAME]: SYSTEM_JOBDISPLAYNAME
358
+ [CI_JOB_NAME]: SYSTEM_JOBDISPLAYNAME,
359
+ [CI_ENV_VARS]: JSON.stringify({ SYSTEM_TEAMPROJECTID, BUILD_BUILDID, SYSTEM_JOBID })
357
360
  }
358
361
 
359
362
  if (SYSTEM_TEAMFOUNDATIONSERVERURI && SYSTEM_TEAMPROJECTID && BUILD_BUILDID) {
@@ -47,7 +47,7 @@ const JEST_TEST_RUNNER = 'test.jest.test_runner'
47
47
 
48
48
  const TEST_ITR_TESTS_SKIPPED = '_dd.ci.itr.tests_skipped'
49
49
  const TEST_SESSION_ITR_SKIPPING_ENABLED = 'test_session.itr.tests_skipping.enabled'
50
- const TEST_SESSION_ITR_CODE_COVERAGE_ENABLED = 'test_session.itr.code_coverage.enabled'
50
+ const TEST_SESSION_CODE_COVERAGE_ENABLED = 'test_session.code_coverage.enabled'
51
51
 
52
52
  const TEST_CODE_COVERAGE_LINES_TOTAL = 'test.codecov_lines_total'
53
53
 
@@ -81,7 +81,7 @@ module.exports = {
81
81
  TEST_SUITE_ID,
82
82
  TEST_ITR_TESTS_SKIPPED,
83
83
  TEST_SESSION_ITR_SKIPPING_ENABLED,
84
- TEST_SESSION_ITR_CODE_COVERAGE_ENABLED,
84
+ TEST_SESSION_CODE_COVERAGE_ENABLED,
85
85
  TEST_CODE_COVERAGE_LINES_TOTAL,
86
86
  getCoveredFilenamesFromCoverage,
87
87
  resetCoverage,
@@ -26,6 +26,19 @@ function removeEmptyValues (tags) {
26
26
  }, {})
27
27
  }
28
28
 
29
+ function filterSensitiveInfoFromRepository (repositoryUrl) {
30
+ try {
31
+ if (repositoryUrl.startsWith('git@')) {
32
+ return repositoryUrl
33
+ }
34
+ const { protocol, hostname, pathname } = new URL(repositoryUrl)
35
+
36
+ return `${protocol}//${hostname}${pathname}`
37
+ } catch (e) {
38
+ return repositoryUrl
39
+ }
40
+ }
41
+
29
42
  function getUserProviderGitMetadata () {
30
43
  const {
31
44
  DD_GIT_COMMIT_SHA,
@@ -57,7 +70,7 @@ function getUserProviderGitMetadata () {
57
70
  return removeEmptyValues({
58
71
  [GIT_COMMIT_SHA]: DD_GIT_COMMIT_SHA,
59
72
  [GIT_BRANCH]: branch,
60
- [GIT_REPOSITORY_URL]: DD_GIT_REPOSITORY_URL,
73
+ [GIT_REPOSITORY_URL]: filterSensitiveInfoFromRepository(DD_GIT_REPOSITORY_URL),
61
74
  [GIT_TAG]: tag,
62
75
  [GIT_COMMIT_MESSAGE]: DD_GIT_COMMIT_MESSAGE,
63
76
  [GIT_COMMIT_COMMITTER_NAME]: DD_GIT_COMMIT_COMMITTER_NAME,
@@ -109,9 +109,9 @@ class PrioritySampler {
109
109
  }
110
110
 
111
111
  _getPriorityFromTags (tags) {
112
- if (tags.hasOwnProperty(MANUAL_KEEP) && tags[MANUAL_KEEP] !== false) {
112
+ if (hasOwn(tags, MANUAL_KEEP) && tags[MANUAL_KEEP] !== false) {
113
113
  return USER_KEEP
114
- } else if (tags.hasOwnProperty(MANUAL_DROP) && tags[MANUAL_DROP] !== false) {
114
+ } else if (hasOwn(tags, MANUAL_DROP) && tags[MANUAL_DROP] !== false) {
115
115
  return USER_REJECT
116
116
  } else {
117
117
  const priority = parseInt(tags[SAMPLING_PRIORITY], 10)
@@ -198,4 +198,8 @@ class PrioritySampler {
198
198
  }
199
199
  }
200
200
 
201
+ function hasOwn (object, prop) {
202
+ return Object.prototype.hasOwnProperty.call(object, prop)
203
+ }
204
+
201
205
  module.exports = PrioritySampler
@@ -25,7 +25,7 @@ class Tracer extends NoopProxy {
25
25
  try {
26
26
  const config = new Config(options) // TODO: support dynamic config
27
27
 
28
- if (!config.isCiVisibility) {
28
+ if (config.remoteConfig.enabled && !config.isCiVisibility) {
29
29
  remoteConfig.enable(config)
30
30
  }
31
31
 
@@ -49,11 +49,12 @@ class Tracer extends NoopProxy {
49
49
  require('./appsec').enable(config)
50
50
  }
51
51
 
52
+ this._tracer = new DatadogTracer(config)
53
+
52
54
  if (config.iast.enabled) {
53
- require('./appsec/iast').enable(config)
55
+ require('./appsec/iast').enable(config, this._tracer)
54
56
  }
55
57
 
56
- this._tracer = new DatadogTracer(config)
57
58
  this._pluginManager.configure(config)
58
59
  setStartupLogPluginManager(this._pluginManager)
59
60
  telemetry.start(config, this._pluginManager)
@@ -97,7 +97,13 @@ function Hook (modules, options, onrequire) {
97
97
  if (!hooks) return exports // abort if module name isn't on whitelist
98
98
  name = filename
99
99
  } else {
100
- const stat = parse(filename)
100
+ const inAWSLambda = process.env.AWS_LAMBDA_FUNCTION_NAME !== undefined
101
+ const hasLambdaHandler = process.env.DD_LAMBDA_HANDLER !== undefined
102
+ const segments = filename.split(path.sep)
103
+ const filenameFromNodeModule = segments.lastIndexOf('node_modules') !== -1
104
+ // decide how to assign the stat
105
+ // first case will only happen when patching an AWS Lambda Handler
106
+ const stat = inAWSLambda && hasLambdaHandler && !filenameFromNodeModule ? { name: filename } : parse(filename)
101
107
  if (!stat) return exports // abort if filename could not be parsed
102
108
  name = stat.name
103
109
  basedir = stat.basedir
@@ -14,6 +14,7 @@ class SpanProcessor {
14
14
  this._exporter = exporter
15
15
  this._prioritySampler = prioritySampler
16
16
  this._config = config
17
+ this._killAll = false
17
18
 
18
19
  this._stats = new SpanStatsProcessor(config)
19
20
  this._spanSampler = new SpanSampler(config)
@@ -48,6 +49,18 @@ class SpanProcessor {
48
49
 
49
50
  this._erase(trace, active)
50
51
  }
52
+
53
+ if (this._killAll) {
54
+ started.map(startedSpan => {
55
+ if (!startedSpan._finished) {
56
+ startedSpan.finish()
57
+ }
58
+ })
59
+ }
60
+ }
61
+
62
+ killAll () {
63
+ this._killAll = true
51
64
  }
52
65
 
53
66
  _erase (trace, active) {
@@ -1,9 +1,6 @@
1
1
  'use strict'
2
2
  const { globMatch } = require('../src/util')
3
- const {
4
- USER_KEEP,
5
- AUTO_KEEP
6
- } = require('../../../ext').priority
3
+ const { USER_KEEP, AUTO_KEEP } = require('../../../ext').priority
7
4
  const RateLimiter = require('./rate_limiter')
8
5
 
9
6
  class SpanSampler {