dd-trace 3.14.1 → 3.16.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 (187) hide show
  1. package/LICENSE-3rdparty.csv +2 -2
  2. package/README.md +9 -5
  3. package/ci/init.js +9 -1
  4. package/ext/exporters.d.ts +2 -1
  5. package/ext/exporters.js +2 -1
  6. package/index.d.ts +36 -3
  7. package/package.json +21 -19
  8. package/packages/datadog-instrumentations/src/cucumber.js +80 -3
  9. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +100 -27
  10. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
  11. package/packages/datadog-instrumentations/src/jest.js +35 -3
  12. package/packages/datadog-instrumentations/src/ldapjs.js +12 -2
  13. package/packages/datadog-instrumentations/src/mariadb.js +130 -11
  14. package/packages/datadog-instrumentations/src/mocha.js +30 -6
  15. package/packages/datadog-instrumentations/src/mongodb-core.js +8 -2
  16. package/packages/datadog-instrumentations/src/mongoose.js +1 -1
  17. package/packages/datadog-instrumentations/src/next.js +33 -4
  18. package/packages/datadog-instrumentations/src/playwright.js +42 -13
  19. package/packages/datadog-plugin-amqp10/src/consumer.js +1 -1
  20. package/packages/datadog-plugin-amqp10/src/index.js +1 -1
  21. package/packages/datadog-plugin-amqp10/src/producer.js +3 -2
  22. package/packages/datadog-plugin-amqplib/src/client.js +3 -2
  23. package/packages/datadog-plugin-amqplib/src/consumer.js +1 -1
  24. package/packages/datadog-plugin-amqplib/src/index.js +1 -1
  25. package/packages/datadog-plugin-amqplib/src/producer.js +3 -2
  26. package/packages/datadog-plugin-aws-sdk/src/base.js +7 -2
  27. package/packages/datadog-plugin-aws-sdk/src/index.js +1 -1
  28. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +2 -0
  29. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +2 -0
  30. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +2 -0
  31. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +2 -0
  32. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +2 -0
  33. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +2 -0
  34. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +2 -0
  35. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +2 -0
  36. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +2 -0
  37. package/packages/datadog-plugin-bunyan/src/index.js +1 -1
  38. package/packages/datadog-plugin-cassandra-driver/src/index.js +3 -2
  39. package/packages/datadog-plugin-connect/src/index.js +1 -1
  40. package/packages/datadog-plugin-couchbase/src/index.js +1 -1
  41. package/packages/datadog-plugin-cucumber/src/index.js +33 -6
  42. package/packages/datadog-plugin-cypress/src/index.js +1 -1
  43. package/packages/datadog-plugin-cypress/src/plugin.js +40 -33
  44. package/packages/datadog-plugin-dns/src/index.js +1 -1
  45. package/packages/datadog-plugin-dns/src/lookup.js +1 -1
  46. package/packages/datadog-plugin-dns/src/lookup_service.js +1 -1
  47. package/packages/datadog-plugin-dns/src/resolve.js +1 -1
  48. package/packages/datadog-plugin-dns/src/reverse.js +1 -1
  49. package/packages/datadog-plugin-elasticsearch/src/index.js +1 -1
  50. package/packages/datadog-plugin-express/src/index.js +1 -1
  51. package/packages/datadog-plugin-fastify/src/index.js +1 -1
  52. package/packages/datadog-plugin-find-my-way/src/index.js +1 -1
  53. package/packages/datadog-plugin-fs/src/index.js +1 -1
  54. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +5 -5
  55. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +1 -1
  56. package/packages/datadog-plugin-google-cloud-pubsub/src/index.js +1 -1
  57. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +7 -6
  58. package/packages/datadog-plugin-graphql/src/execute.js +1 -1
  59. package/packages/datadog-plugin-graphql/src/index.js +1 -1
  60. package/packages/datadog-plugin-graphql/src/parse.js +1 -1
  61. package/packages/datadog-plugin-graphql/src/resolve.js +1 -1
  62. package/packages/datadog-plugin-graphql/src/validate.js +1 -1
  63. package/packages/datadog-plugin-grpc/src/client.js +1 -1
  64. package/packages/datadog-plugin-grpc/src/index.js +1 -1
  65. package/packages/datadog-plugin-grpc/src/server.js +1 -1
  66. package/packages/datadog-plugin-hapi/src/index.js +1 -1
  67. package/packages/datadog-plugin-http/src/client.js +2 -2
  68. package/packages/datadog-plugin-http/src/index.js +1 -1
  69. package/packages/datadog-plugin-http/src/server.js +3 -3
  70. package/packages/datadog-plugin-http2/src/client.js +4 -3
  71. package/packages/datadog-plugin-http2/src/index.js +1 -1
  72. package/packages/datadog-plugin-http2/src/server.js +3 -3
  73. package/packages/datadog-plugin-ioredis/src/index.js +1 -1
  74. package/packages/datadog-plugin-jest/src/index.js +53 -19
  75. package/packages/datadog-plugin-kafkajs/src/consumer.js +1 -1
  76. package/packages/datadog-plugin-kafkajs/src/index.js +1 -1
  77. package/packages/datadog-plugin-kafkajs/src/producer.js +1 -1
  78. package/packages/datadog-plugin-koa/src/index.js +1 -1
  79. package/packages/datadog-plugin-mariadb/src/index.js +18 -1
  80. package/packages/datadog-plugin-memcached/src/index.js +3 -2
  81. package/packages/datadog-plugin-microgateway-core/src/index.js +1 -1
  82. package/packages/datadog-plugin-mocha/src/index.js +13 -9
  83. package/packages/datadog-plugin-moleculer/src/client.js +1 -1
  84. package/packages/datadog-plugin-moleculer/src/index.js +1 -1
  85. package/packages/datadog-plugin-moleculer/src/server.js +1 -1
  86. package/packages/datadog-plugin-mongodb-core/src/index.js +1 -1
  87. package/packages/datadog-plugin-mysql/src/index.js +3 -2
  88. package/packages/datadog-plugin-mysql2/src/index.js +1 -1
  89. package/packages/datadog-plugin-net/src/index.js +9 -75
  90. package/packages/datadog-plugin-net/src/ipc.js +1 -1
  91. package/packages/datadog-plugin-net/src/tcp.js +3 -2
  92. package/packages/datadog-plugin-next/src/index.js +3 -3
  93. package/packages/datadog-plugin-opensearch/src/index.js +1 -1
  94. package/packages/datadog-plugin-oracledb/src/index.js +3 -2
  95. package/packages/datadog-plugin-paperplane/src/index.js +1 -1
  96. package/packages/datadog-plugin-paperplane/src/logger.js +1 -1
  97. package/packages/datadog-plugin-paperplane/src/server.js +1 -1
  98. package/packages/datadog-plugin-pg/src/index.js +3 -2
  99. package/packages/datadog-plugin-pino/src/index.js +1 -1
  100. package/packages/datadog-plugin-playwright/src/index.js +5 -4
  101. package/packages/datadog-plugin-redis/src/index.js +3 -2
  102. package/packages/datadog-plugin-restify/src/index.js +1 -1
  103. package/packages/datadog-plugin-rhea/src/consumer.js +1 -1
  104. package/packages/datadog-plugin-rhea/src/index.js +1 -1
  105. package/packages/datadog-plugin-rhea/src/producer.js +3 -2
  106. package/packages/datadog-plugin-router/src/index.js +8 -8
  107. package/packages/datadog-plugin-sharedb/src/index.js +1 -1
  108. package/packages/datadog-plugin-tedious/src/index.js +3 -2
  109. package/packages/datadog-plugin-web/src/index.js +1 -1
  110. package/packages/datadog-plugin-winston/src/index.js +1 -1
  111. package/packages/dd-trace/src/appsec/addresses.js +3 -1
  112. package/packages/dd-trace/src/appsec/blocking.js +35 -9
  113. package/packages/dd-trace/src/appsec/gateway/engine/runner.js +2 -1
  114. package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +2 -0
  115. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +2 -2
  116. package/packages/dd-trace/src/appsec/iast/iast-context.js +6 -2
  117. package/packages/dd-trace/src/appsec/iast/iast-log.js +111 -0
  118. package/packages/dd-trace/src/appsec/iast/index.js +10 -6
  119. package/packages/dd-trace/src/appsec/iast/path-line.js +3 -6
  120. package/packages/dd-trace/src/appsec/iast/taint-tracking/index.js +2 -0
  121. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations.js +2 -0
  122. package/packages/dd-trace/src/appsec/iast/taint-tracking/origin-types.js +2 -0
  123. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +2 -0
  124. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +9 -4
  125. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +5 -3
  126. package/packages/dd-trace/src/appsec/iast/telemetry/log_collector.js +96 -0
  127. package/packages/dd-trace/src/appsec/iast/telemetry/logs.js +87 -0
  128. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +27 -2
  129. package/packages/dd-trace/src/appsec/index.js +4 -4
  130. package/packages/dd-trace/src/appsec/recommended.json +76 -75
  131. package/packages/dd-trace/src/appsec/remote_config/capabilities.js +2 -1
  132. package/packages/dd-trace/src/appsec/remote_config/index.js +3 -0
  133. package/packages/dd-trace/src/appsec/sdk/index.js +19 -1
  134. package/packages/dd-trace/src/appsec/sdk/noop.js +6 -0
  135. package/packages/dd-trace/src/appsec/sdk/set_user.js +30 -0
  136. package/packages/dd-trace/src/appsec/sdk/track_event.js +2 -2
  137. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +73 -0
  138. package/packages/dd-trace/src/ci-visibility/encode/json-encoder.js +27 -0
  139. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +17 -9
  140. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +14 -8
  141. package/packages/dd-trace/src/ci-visibility/exporters/jest-worker/index.js +33 -0
  142. package/packages/dd-trace/src/ci-visibility/exporters/jest-worker/writer.js +37 -0
  143. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-itr-configuration.js +12 -4
  144. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +12 -4
  145. package/packages/dd-trace/src/config.js +24 -5
  146. package/packages/dd-trace/src/constants.js +2 -1
  147. package/packages/dd-trace/src/datastreams/encoding.js +80 -0
  148. package/packages/dd-trace/src/exporter.js +7 -9
  149. package/packages/dd-trace/src/exporters/common/agents.js +42 -0
  150. package/packages/dd-trace/src/exporters/common/docker.js +4 -1
  151. package/packages/dd-trace/src/exporters/common/request.js +1 -4
  152. package/packages/dd-trace/src/lambda/handler.js +19 -12
  153. package/packages/dd-trace/src/log/writer.js +32 -24
  154. package/packages/dd-trace/src/metrics.js +18 -0
  155. package/packages/dd-trace/src/noop/proxy.js +2 -2
  156. package/packages/dd-trace/src/opentracing/span.js +5 -0
  157. package/packages/dd-trace/src/opentracing/span_context.js +1 -1
  158. package/packages/dd-trace/src/plugin_manager.js +7 -7
  159. package/packages/dd-trace/src/plugins/ci_plugin.js +20 -17
  160. package/packages/dd-trace/src/plugins/index.js +1 -0
  161. package/packages/dd-trace/src/plugins/log_plugin.js +1 -1
  162. package/packages/dd-trace/src/plugins/outgoing.js +2 -1
  163. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  164. package/packages/dd-trace/src/plugins/util/ci.js +12 -0
  165. package/packages/dd-trace/src/plugins/util/exec.js +2 -2
  166. package/packages/dd-trace/src/plugins/util/git.js +16 -1
  167. package/packages/dd-trace/src/plugins/util/ip_extractor.js +23 -27
  168. package/packages/dd-trace/src/plugins/util/test.js +26 -7
  169. package/packages/dd-trace/src/profiler.js +3 -0
  170. package/packages/dd-trace/src/profiling/config.js +92 -20
  171. package/packages/dd-trace/src/profiling/constants.js +16 -0
  172. package/packages/dd-trace/src/profiling/exporter_cli.js +62 -0
  173. package/packages/dd-trace/src/profiling/exporters/agent.js +2 -1
  174. package/packages/dd-trace/src/profiling/exporters/file.js +13 -2
  175. package/packages/dd-trace/src/profiling/profiler.js +42 -12
  176. package/packages/dd-trace/src/profiling/profilers/space.js +21 -1
  177. package/packages/dd-trace/src/profiling/profilers/wall.js +1 -0
  178. package/packages/dd-trace/src/proxy.js +1 -1
  179. package/packages/dd-trace/src/span_processor.js +1 -1
  180. package/packages/dd-trace/src/span_sampler.js +71 -54
  181. package/packages/dd-trace/src/startup-log.js +3 -6
  182. package/packages/dd-trace/src/telemetry/index.js +16 -2
  183. package/packages/dd-trace/src/tracer.js +0 -16
  184. package/packages/dd-trace/src/util.js +10 -1
  185. package/scripts/install_plugin_modules.js +5 -1
  186. package/scripts/junit_report.js +0 -25
  187. package/scripts/tdd.js +0 -34
@@ -3,6 +3,7 @@
3
3
  const log = require('../../log')
4
4
  const { getRootSpan } = require('./utils')
5
5
  const { MANUAL_KEEP } = require('../../../../../ext/tags')
6
+ const { setUserTags } = require('./set_user')
6
7
 
7
8
  function trackUserLoginSuccessEvent (tracer, user, metadata) {
8
9
  // TODO: better user check here and in _setUser() ?
@@ -17,8 +18,7 @@ function trackUserLoginSuccessEvent (tracer, user, metadata) {
17
18
  return
18
19
  }
19
20
 
20
- // TODO: use sdk._setUser(user, rootSpan) (available in User Blocking PR #2710)
21
- tracer.setUser(user)
21
+ setUserTags(user, rootSpan)
22
22
 
23
23
  trackEvent(tracer, 'users.login.success', metadata, 'trackUserLoginSuccessEvent', rootSpan)
24
24
  }
@@ -0,0 +1,73 @@
1
+ 'use strict'
2
+
3
+ const { USER_ID } = require('../addresses')
4
+ const Gateway = require('../gateway/engine')
5
+ const { getRootSpan } = require('./utils')
6
+ const { block } = require('../blocking')
7
+ const { storage } = require('../../../../datadog-core')
8
+ const { setUserTags } = require('./set_user')
9
+ const log = require('../../log')
10
+
11
+ function isUserBlocked (user) {
12
+ const results = Gateway.propagate({ [USER_ID]: user.id })
13
+
14
+ if (!results) {
15
+ return false
16
+ }
17
+
18
+ for (const entry of results) {
19
+ if (entry && entry.includes('block')) {
20
+ return true
21
+ }
22
+ }
23
+
24
+ return false
25
+ }
26
+
27
+ function checkUserAndSetUser (tracer, user) {
28
+ if (!user || !user.id) {
29
+ log.warn('Invalid user provided to isUserBlocked')
30
+ return false
31
+ }
32
+
33
+ const rootSpan = getRootSpan(tracer)
34
+ if (rootSpan) {
35
+ if (!rootSpan.context()._tags['usr.id']) {
36
+ setUserTags(user, rootSpan)
37
+ }
38
+ } else {
39
+ log.warn('Root span not available in isUserBlocked')
40
+ }
41
+
42
+ return isUserBlocked(user)
43
+ }
44
+
45
+ function blockRequest (tracer, req, res) {
46
+ if (!req || !res) {
47
+ const store = storage.getStore()
48
+ if (store) {
49
+ req = req || store.req
50
+ res = res || store.res
51
+ }
52
+ }
53
+
54
+ if (!req || !res) {
55
+ log.warn('Requests or response object not available in blockRequest')
56
+ return false
57
+ }
58
+
59
+ const rootSpan = getRootSpan(tracer)
60
+ if (!rootSpan) {
61
+ log.warn('Root span not available in blockRequest')
62
+ return false
63
+ }
64
+
65
+ block(req, res, rootSpan)
66
+
67
+ return true
68
+ }
69
+
70
+ module.exports = {
71
+ checkUserAndSetUser,
72
+ blockRequest
73
+ }
@@ -0,0 +1,27 @@
1
+ 'use strict'
2
+
3
+ class JSONEncoder {
4
+ constructor () {
5
+ this.payloads = []
6
+ }
7
+
8
+ encode (payload) {
9
+ this.payloads.push(payload)
10
+ }
11
+
12
+ count () {
13
+ return this.payloads.length
14
+ }
15
+
16
+ reset () {
17
+ this.payloads = []
18
+ }
19
+
20
+ makePayload () {
21
+ const data = JSON.stringify(this.payloads)
22
+ this.reset()
23
+ return data
24
+ }
25
+ }
26
+
27
+ module.exports = { JSONEncoder }
@@ -8,6 +8,19 @@ const { getSkippableSuites: getSkippableSuitesRequest } = require('../intelligen
8
8
  const log = require('../../log')
9
9
  const AgentInfoExporter = require('../../exporters/common/agent-info-exporter')
10
10
 
11
+ function getTestConfigurationTags (tags) {
12
+ if (!tags) {
13
+ return {}
14
+ }
15
+ return Object.keys(tags).reduce((acc, key) => {
16
+ if (key.startsWith('test.configuration.')) {
17
+ const [, configKey] = key.split('test.configuration.')
18
+ acc[configKey] = tags[key]
19
+ }
20
+ return acc
21
+ }, {})
22
+ }
23
+
11
24
  function getIsTestSessionTrace (trace) {
12
25
  return trace.some(span =>
13
26
  span.type === 'test_session_end' || span.type === 'test_suite_end' || span.type === 'test_module_end'
@@ -95,6 +108,7 @@ class CiVisibilityExporter extends AgentInfoExporter {
95
108
  env: this._config.env,
96
109
  service: this._config.service,
97
110
  isEvpProxy: !!this._isUsingEvpProxy,
111
+ custom: getTestConfigurationTags(this._config.tags),
98
112
  ...testConfiguration
99
113
  }
100
114
  getSkippableSuitesRequest(configuration, callback)
@@ -119,6 +133,7 @@ class CiVisibilityExporter extends AgentInfoExporter {
119
133
  env: this._config.env,
120
134
  service: this._config.service,
121
135
  isEvpProxy: !!this._isUsingEvpProxy,
136
+ custom: getTestConfigurationTags(this._config.tags),
122
137
  ...testConfiguration
123
138
  }
124
139
  getItrConfigurationRequest(configuration, (err, itrConfig) => {
@@ -163,23 +178,16 @@ class CiVisibilityExporter extends AgentInfoExporter {
163
178
  this._export(trace)
164
179
  }
165
180
 
166
- exportCoverage (coveragePayload) {
181
+ exportCoverage (formattedCoverage) {
167
182
  // Until it's initialized, we just store the coverages as is
168
183
  if (!this._isInitialized) {
169
- this._coverageBuffer.push(coveragePayload)
184
+ this._coverageBuffer.push(formattedCoverage)
170
185
  return
171
186
  }
172
187
  if (!this.canReportCodeCoverage()) {
173
188
  return
174
189
  }
175
190
 
176
- const { span, coverageFiles } = coveragePayload
177
- const formattedCoverage = {
178
- traceId: span.context()._traceId,
179
- spanId: span.context()._spanId,
180
- files: coverageFiles
181
- }
182
-
183
191
  this._export(formattedCoverage, this._coverageWriter, '_coverageTimer')
184
192
  }
185
193
 
@@ -10,21 +10,23 @@ const {
10
10
  getLatestCommits,
11
11
  getRepositoryUrl,
12
12
  generatePackFilesForCommits,
13
- getCommitsToUpload
13
+ getCommitsToUpload,
14
+ isShallowRepository,
15
+ unshallowRepository
14
16
  } = require('../../../plugins/util/git')
15
17
 
16
- const isValidSha = (sha) => /[0-9a-f]{40}/.test(sha)
18
+ const isValidSha1 = (sha) => /^[0-9a-f]{40}$/.test(sha)
19
+ const isValidSha256 = (sha) => /^[0-9a-f]{64}$/.test(sha)
17
20
 
18
- function sanitizeCommits (commits) {
21
+ function validateCommits (commits) {
19
22
  return commits.map(({ id: commitSha, type }) => {
20
23
  if (type !== 'commit') {
21
24
  throw new Error('Invalid commit type response')
22
25
  }
23
- const sanitizedCommit = commitSha.replace(/[^0-9a-f]+/g, '')
24
- if (sanitizedCommit !== commitSha || !isValidSha(sanitizedCommit)) {
25
- throw new Error('Invalid commit format')
26
+ if (isValidSha1(commitSha) || isValidSha256(commitSha)) {
27
+ return commitSha.replace(/[^0-9a-f]+/g, '')
26
28
  }
27
- return sanitizedCommit
29
+ throw new Error('Invalid commit format')
28
30
  })
29
31
  }
30
32
 
@@ -82,7 +84,7 @@ function getCommitsToExclude ({ url, isEvpProxy, repositoryUrl }, callback) {
82
84
  }
83
85
  let commitsToExclude
84
86
  try {
85
- commitsToExclude = sanitizeCommits(JSON.parse(response).data)
87
+ commitsToExclude = validateCommits(JSON.parse(response).data)
86
88
  } catch (e) {
87
89
  return callback(new Error(`Can't parse commits to exclude response: ${e.message}`))
88
90
  }
@@ -157,6 +159,10 @@ function sendGitMetadata (url, isEvpProxy, callback) {
157
159
  return callback(new Error('Repository URL is empty'))
158
160
  }
159
161
 
162
+ if (isShallowRepository()) {
163
+ unshallowRepository()
164
+ }
165
+
160
166
  getCommitsToExclude({ url, repositoryUrl, isEvpProxy }, (err, commitsToExclude, headCommit) => {
161
167
  if (err) {
162
168
  return callback(err)
@@ -0,0 +1,33 @@
1
+ 'use strict'
2
+
3
+ const Writer = require('./writer')
4
+ const {
5
+ JEST_WORKER_COVERAGE_PAYLOAD_CODE,
6
+ JEST_WORKER_TRACE_PAYLOAD_CODE
7
+ } = require('../../../plugins/util/test')
8
+
9
+ /**
10
+ * Lightweight exporter whose writers only do simple JSON serialization
11
+ * of trace and coverage payloads, which they send to the jest main process.
12
+ */
13
+ class JestWorkerCiVisibilityExporter {
14
+ constructor () {
15
+ this._writer = new Writer(JEST_WORKER_TRACE_PAYLOAD_CODE)
16
+ this._coverageWriter = new Writer(JEST_WORKER_COVERAGE_PAYLOAD_CODE)
17
+ }
18
+
19
+ export (payload) {
20
+ this._writer.append(payload)
21
+ }
22
+
23
+ exportCoverage (formattedCoverage) {
24
+ this._coverageWriter.append(formattedCoverage)
25
+ }
26
+
27
+ flush () {
28
+ this._writer.flush()
29
+ this._coverageWriter.flush()
30
+ }
31
+ }
32
+
33
+ module.exports = JestWorkerCiVisibilityExporter
@@ -0,0 +1,37 @@
1
+ 'use strict'
2
+ const { JSONEncoder } = require('../../encode/json-encoder')
3
+
4
+ class Writer {
5
+ constructor (interprocessCode) {
6
+ this._encoder = new JSONEncoder()
7
+ // Code used to identify the type of payload being sent to the main process
8
+ this._interprocessCode = interprocessCode
9
+ }
10
+
11
+ flush () {
12
+ const count = this._encoder.count()
13
+
14
+ if (count > 0) {
15
+ const payload = this._encoder.makePayload()
16
+
17
+ this._sendPayload(payload)
18
+ }
19
+ }
20
+
21
+ append (payload) {
22
+ this._encoder.encode(payload)
23
+ }
24
+
25
+ _sendPayload (data) {
26
+ // Only available when `child_process` is used for the jest worker.
27
+ // eslint-disable-next-line
28
+ // https://github.com/facebook/jest/blob/bb39cb2c617a3334bf18daeca66bd87b7ccab28b/packages/jest-worker/README.md#experimental-worker
29
+ // If worker_threads is used, this will not work
30
+ // TODO: make it compatible with worker_threads
31
+ if (process.send) { // it only works if process.send is available
32
+ process.send([this._interprocessCode, data])
33
+ }
34
+ }
35
+ }
36
+
37
+ module.exports = Writer
@@ -13,7 +13,8 @@ function getItrConfiguration ({
13
13
  osArchitecture,
14
14
  runtimeName,
15
15
  runtimeVersion,
16
- branch
16
+ branch,
17
+ custom
17
18
  }, done) {
18
19
  const options = {
19
20
  path: '/api/v2/libraries/tests/services/setting',
@@ -35,9 +36,15 @@ function getItrConfiguration ({
35
36
  process.env.DATADOG_APPLICATION_KEY ||
36
37
  process.env.DD_APPLICATION_KEY
37
38
 
38
- if (!apiKey || !appKey) {
39
- return done(new Error('App key or API key undefined'))
39
+ const messagePrefix = 'Request to settings endpoint was not done because Datadog'
40
+
41
+ if (!appKey) {
42
+ return done(new Error(`${messagePrefix} application key is not defined.`))
43
+ }
44
+ if (!apiKey) {
45
+ return done(new Error(`${messagePrefix} API key is not defined.`))
40
46
  }
47
+
41
48
  options.headers['dd-api-key'] = apiKey
42
49
  options.headers['dd-application-key'] = appKey
43
50
  }
@@ -53,7 +60,8 @@ function getItrConfiguration ({
53
60
  'os.version': osVersion,
54
61
  'os.architecture': osArchitecture,
55
62
  'runtime.name': runtimeName,
56
- 'runtime.version': runtimeVersion
63
+ 'runtime.version': runtimeVersion,
64
+ custom
57
65
  },
58
66
  service,
59
67
  env,
@@ -11,7 +11,8 @@ function getSkippableSuites ({
11
11
  osPlatform,
12
12
  osArchitecture,
13
13
  runtimeName,
14
- runtimeVersion
14
+ runtimeVersion,
15
+ custom
15
16
  }, done) {
16
17
  const options = {
17
18
  path: '/api/v2/ci/tests/skippable',
@@ -34,9 +35,15 @@ function getSkippableSuites ({
34
35
  process.env.DATADOG_APPLICATION_KEY ||
35
36
  process.env.DD_APPLICATION_KEY
36
37
 
37
- if (!apiKey || !appKey) {
38
- return done(new Error('App key or API key undefined'))
38
+ const messagePrefix = 'Skippable suites were not fetched because Datadog'
39
+
40
+ if (!appKey) {
41
+ return done(new Error(`${messagePrefix} application key is not defined.`))
42
+ }
43
+ if (!apiKey) {
44
+ return done(new Error(`${messagePrefix} API key is not defined.`))
39
45
  }
46
+
40
47
  options.headers['dd-api-key'] = apiKey
41
48
  options.headers['dd-application-key'] = appKey
42
49
  }
@@ -51,7 +58,8 @@ function getSkippableSuites ({
51
58
  'os.version': osVersion,
52
59
  'os.architecture': osArchitecture,
53
60
  'runtime.name': runtimeName,
54
- 'runtime.version': runtimeVersion
61
+ 'runtime.version': runtimeVersion,
62
+ custom
55
63
  },
56
64
  service,
57
65
  env,
@@ -161,7 +161,7 @@ class Config {
161
161
 
162
162
  const DD_CIVISIBILITY_ITR_ENABLED = coalesce(
163
163
  process.env.DD_CIVISIBILITY_ITR_ENABLED,
164
- false
164
+ true
165
165
  )
166
166
 
167
167
  const DD_SERVICE = options.service ||
@@ -197,6 +197,10 @@ class Config {
197
197
  process.env.DD_TRACE_TELEMETRY_ENABLED,
198
198
  !process.env.AWS_LAMBDA_FUNCTION_NAME
199
199
  )
200
+ const DD_TELEMETRY_DEBUG_ENABLED = coalesce(
201
+ process.env.DD_TELEMETRY_DEBUG_ENABLED,
202
+ false
203
+ )
200
204
  const DD_TRACE_AGENT_PROTOCOL_VERSION = coalesce(
201
205
  options.protocolVersion,
202
206
  process.env.DD_TRACE_AGENT_PROTOCOL_VERSION,
@@ -352,6 +356,10 @@ ken|consumer_?(?:id|key|secret)|sign(?:ed|ature)?|auth(?:entication|orization)?)
352
356
  process.env.DD_IAST_ENABLED,
353
357
  false
354
358
  )
359
+ const DD_TELEMETRY_LOG_COLLECTION_ENABLED = coalesce(
360
+ process.env.DD_TELEMETRY_LOG_COLLECTION_ENABLED,
361
+ DD_IAST_ENABLED
362
+ )
355
363
 
356
364
  const defaultIastRequestSampling = 30
357
365
  const iastRequestSampling = coalesce(
@@ -374,9 +382,15 @@ ken|consumer_?(?:id|key|secret)|sign(?:ed|ature)?|auth(?:entication|orization)?)
374
382
  2
375
383
  )
376
384
 
385
+ const DD_IAST_DEDUPLICATION_ENABLED = coalesce(
386
+ iastOptions && iastOptions.deduplicationEnabled,
387
+ process.env.DD_IAST_DEDUPLICATION_ENABLED && isTrue(process.env.DD_IAST_DEDUPLICATION_ENABLED),
388
+ true
389
+ )
390
+
377
391
  const DD_CIVISIBILITY_GIT_UPLOAD_ENABLED = coalesce(
378
392
  process.env.DD_CIVISIBILITY_GIT_UPLOAD_ENABLED,
379
- false
393
+ true
380
394
  )
381
395
 
382
396
  const ingestion = options.ingestion || {}
@@ -456,7 +470,11 @@ ken|consumer_?(?:id|key|secret)|sign(?:ed|ature)?|auth(?:entication|orization)?)
456
470
  this.lookup = options.lookup
457
471
  this.startupLogs = isTrue(DD_TRACE_STARTUP_LOGS)
458
472
  // Disabled for CI Visibility's agentless
459
- this.telemetryEnabled = DD_TRACE_EXPORTER !== 'datadog' && isTrue(DD_TRACE_TELEMETRY_ENABLED)
473
+ this.telemetry = {
474
+ enabled: DD_TRACE_EXPORTER !== 'datadog' && isTrue(DD_TRACE_TELEMETRY_ENABLED),
475
+ logCollection: isTrue(DD_TELEMETRY_LOG_COLLECTION_ENABLED),
476
+ debug: isTrue(DD_TELEMETRY_DEBUG_ENABLED)
477
+ }
460
478
  this.protocolVersion = DD_TRACE_AGENT_PROTOCOL_VERSION
461
479
  this.tagsHeaderMaxLength = parseInt(DD_TRACE_X_DATADOG_TAGS_MAX_LENGTH)
462
480
  this.appsec = {
@@ -477,14 +495,15 @@ ken|consumer_?(?:id|key|secret)|sign(?:ed|ature)?|auth(?:entication|orization)?)
477
495
  enabled: isTrue(DD_IAST_ENABLED),
478
496
  requestSampling: DD_IAST_REQUEST_SAMPLING,
479
497
  maxConcurrentRequests: DD_IAST_MAX_CONCURRENT_REQUESTS,
480
- maxContextOperations: DD_IAST_MAX_CONTEXT_OPERATIONS
498
+ maxContextOperations: DD_IAST_MAX_CONTEXT_OPERATIONS,
499
+ deduplicationEnabled: DD_IAST_DEDUPLICATION_ENABLED
481
500
  }
482
501
 
483
502
  this.isCiVisibility = isTrue(DD_IS_CIVISIBILITY)
484
503
 
485
504
  this.isIntelligentTestRunnerEnabled = this.isCiVisibility && isTrue(DD_CIVISIBILITY_ITR_ENABLED)
486
505
  this.isGitUploadEnabled = this.isCiVisibility &&
487
- (this.isIntelligentTestRunnerEnabled || isTrue(DD_CIVISIBILITY_GIT_UPLOAD_ENABLED))
506
+ (this.isIntelligentTestRunnerEnabled && !isFalse(DD_CIVISIBILITY_GIT_UPLOAD_ENABLED))
488
507
 
489
508
  this.stats = {
490
509
  enabled: isTrue(DD_TRACE_STATS_COMPUTATION_ENABLED)
@@ -24,5 +24,6 @@ module.exports = {
24
24
  ERROR_TYPE: 'error.type',
25
25
  ERROR_MESSAGE: 'error.message',
26
26
  ERROR_STACK: 'error.stack',
27
- COMPONENT: 'component'
27
+ COMPONENT: 'component',
28
+ CLIENT_PORT_KEY: 'network.destination.port'
28
29
  }
@@ -0,0 +1,80 @@
1
+ // encodes positive and negative numbers, using zig zag encoding to reduce the size of the variable length encoding.
2
+ // uses high and low part to ensure those parts are under the limit for byte operations in javascript (32 bits)
3
+ // maximum number possible to encode is MAX_SAFE_INTEGER/2 (using zig zag shifts the bits by 1 to the left)
4
+ function encodeVarint (v) {
5
+ const sign = v >= 0 ? 0 : 1
6
+ // we leave the least significant bit for the sign.
7
+ const double = Math.abs(v) * 2
8
+ if (double > Number.MAX_SAFE_INTEGER) {
9
+ return undefined
10
+ }
11
+ const high = Math.floor(double / 0x100000000)
12
+ const low = (double & 0xffffffff) | sign
13
+ return encodeUvarint64(low, high)
14
+ }
15
+
16
+ // decodes positive and negative numbers, using zig zag encoding to reduce the size of the variable length encoding.
17
+ // uses high and low part to ensure those parts are under the limit for byte operations in javascript (32 bits)
18
+ function decodeVarint (b) {
19
+ const [low, high] = decodeUvarint64(b)
20
+ if (low === undefined || high === undefined) {
21
+ return undefined
22
+ }
23
+ const positive = (low & 1) === 0
24
+ const abs = (low >>> 1) + high * 0x80000000
25
+ return positive ? abs : -abs
26
+ }
27
+
28
+ const maxVarLen64 = 9
29
+
30
+ function encodeUvarint64 (low, high) {
31
+ const result = new Uint8Array(maxVarLen64)
32
+ let i = 0
33
+ // if first byte is 1, the number is negative in javascript, but we want to interpret it as positive
34
+ while ((high !== 0 || low < 0 || low > 0x80) && i < maxVarLen64 - 1) {
35
+ result[i] = (low & 0x7f) | 0x80
36
+ low >>>= 7
37
+ low |= (high & 0x7f) << 25
38
+ high >>>= 7
39
+ i++
40
+ }
41
+ result[i] = low & 0x7f
42
+ return result.slice(0, i + 1)
43
+ }
44
+
45
+ function decodeUvarint64 (
46
+ bytes
47
+ ) {
48
+ let low = 0
49
+ let high = 0
50
+ let s = 0
51
+ for (let i = 0; ; i++) {
52
+ if (bytes.length <= i) {
53
+ return [undefined, undefined]
54
+ }
55
+ const n = bytes[i]
56
+ if (n < 0x80 || i === maxVarLen64 - 1) {
57
+ bytes = bytes.slice(i + 1)
58
+ if (s < 32) {
59
+ low |= n << s
60
+ }
61
+ if (s > 0) {
62
+ high |= s - 32 > 0 ? n << (s - 32) : n >> (32 - s)
63
+ }
64
+ return [low, high]
65
+ }
66
+ if (s < 32) {
67
+ low |= (n & 0x7f) << s
68
+ }
69
+ if (s > 0) {
70
+ high |=
71
+ s - 32 > 0 ? (n & 0x7f) << (s - 32) : (n & 0x7f) >> (32 - s)
72
+ }
73
+ s += 7
74
+ }
75
+ }
76
+
77
+ module.exports = {
78
+ encodeVarint,
79
+ decodeVarint
80
+ }
@@ -1,9 +1,5 @@
1
1
  'use strict'
2
2
 
3
- const AgentExporter = require('./exporters/agent')
4
- const LogExporter = require('./exporters/log')
5
- const AgentlessCiVisibilityExporter = require('./ci-visibility/exporters/agentless')
6
- const AgentProxyCiVisibilityExporter = require('./ci-visibility/exporters/agent-proxy')
7
3
  const exporters = require('../../../ext/exporters')
8
4
  const fs = require('fs')
9
5
  const constants = require('./constants')
@@ -14,14 +10,16 @@ module.exports = name => {
14
10
 
15
11
  switch (name) {
16
12
  case exporters.LOG:
17
- return LogExporter
13
+ return require('./exporters/log')
18
14
  case exporters.AGENT:
19
- return AgentExporter
15
+ return require('./exporters/agent')
20
16
  case exporters.DATADOG:
21
- return AgentlessCiVisibilityExporter
17
+ return require('./ci-visibility/exporters/agentless')
22
18
  case exporters.AGENT_PROXY:
23
- return AgentProxyCiVisibilityExporter
19
+ return require('./ci-visibility/exporters/agent-proxy')
20
+ case exporters.JEST_WORKER:
21
+ return require('./ci-visibility/exporters/jest-worker')
24
22
  default:
25
- return inAWSLambda && !usingLambdaExtension ? LogExporter : AgentExporter
23
+ return inAWSLambda && !usingLambdaExtension ? require('./exporters/log') : require('./exporters/agent')
26
24
  }
27
25
  }
@@ -0,0 +1,42 @@
1
+ 'use strict'
2
+
3
+ const http = require('http')
4
+ const https = require('https')
5
+ const { storage } = require('../../../../datadog-core')
6
+
7
+ const keepAlive = true
8
+ const maxSockets = 1
9
+
10
+ function createAgentClass (BaseAgent) {
11
+ class CustomAgent extends BaseAgent {
12
+ constructor () {
13
+ super({ keepAlive, maxSockets })
14
+ }
15
+
16
+ createConnection (...args) {
17
+ return this._noop(() => super.createConnection(...args))
18
+ }
19
+
20
+ keepSocketAlive (...args) {
21
+ return this._noop(() => super.keepSocketAlive(...args))
22
+ }
23
+
24
+ reuseSocket (...args) {
25
+ return this._noop(() => super.reuseSocket(...args))
26
+ }
27
+
28
+ _noop (callback) {
29
+ return storage.run({ noop: true }, callback)
30
+ }
31
+ }
32
+
33
+ return CustomAgent
34
+ }
35
+
36
+ const HttpAgent = createAgentClass(http.Agent)
37
+ const HttpsAgent = createAgentClass(https.Agent)
38
+
39
+ module.exports = {
40
+ httpAgent: new HttpAgent(),
41
+ HttpsAgent: new HttpsAgent()
42
+ }
@@ -2,7 +2,10 @@
2
2
 
3
3
  const fs = require('fs')
4
4
 
5
- const uuidSource = '[0-9a-f]{8}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{12}'
5
+ // The second part is the PCF / Garden regexp. We currently assume no suffix($) to avoid matching pod UIDs
6
+ // See https://github.com/DataDog/datadog-agent/blob/7.40.x/pkg/util/cgroups/reader.go#L50
7
+ const uuidSource =
8
+ '[0-9a-f]{8}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{12}|[0-9a-f]{8}(?:-[0-9a-f]{4}){4}$'
6
9
  const containerSource = '[0-9a-f]{64}'
7
10
  const taskSource = '[0-9a-f]{32}-\\d+'
8
11
  const entityReg = new RegExp(`.*(${uuidSource}|${containerSource}|${taskSource})(?:\\.scope)?$`, 'm')
@@ -8,14 +8,11 @@ const http = require('http')
8
8
  const https = require('https')
9
9
  const { parse: urlParse } = require('url')
10
10
  const docker = require('./docker')
11
+ const { httpAgent, httpsAgent } = require('./agents')
11
12
  const { storage } = require('../../../../datadog-core')
12
13
  const log = require('../../log')
13
14
 
14
- const keepAlive = true
15
- const maxSockets = 1
16
15
  const maxActiveRequests = 8
17
- const httpAgent = new http.Agent({ keepAlive, maxSockets })
18
- const httpsAgent = new https.Agent({ keepAlive, maxSockets })
19
16
  const containerId = docker.id()
20
17
 
21
18
  let activeRequests = 0