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,7 +3,7 @@
3
3
  const LogPlugin = require('../../dd-trace/src/plugins/log_plugin')
4
4
 
5
5
  class PaperplaneLoggerPlugin extends LogPlugin {
6
- static get name () {
6
+ static get id () {
7
7
  return 'paperplane'
8
8
  }
9
9
  }
@@ -4,7 +4,7 @@ const RouterPlugin = require('../../datadog-plugin-router/src')
4
4
  const web = require('../../dd-trace/src/plugins/util/web')
5
5
 
6
6
  class PaperplaneServerPlugin extends RouterPlugin {
7
- static get name () {
7
+ static get id () {
8
8
  return 'paperplane'
9
9
  }
10
10
 
@@ -1,9 +1,10 @@
1
1
  'use strict'
2
2
 
3
+ const { CLIENT_PORT_KEY } = require('../../dd-trace/src/constants')
3
4
  const DatabasePlugin = require('../../dd-trace/src/plugins/database')
4
5
 
5
6
  class PGPlugin extends DatabasePlugin {
6
- static get name () { return 'pg' }
7
+ static get id () { return 'pg' }
7
8
  static get operation () { return 'query' }
8
9
  static get system () { return 'postgres' }
9
10
 
@@ -22,7 +23,7 @@ class PGPlugin extends DatabasePlugin {
22
23
  'db.name': params.database,
23
24
  'db.user': params.user,
24
25
  'out.host': params.host,
25
- 'out.port': params.port
26
+ [CLIENT_PORT_KEY]: params.port
26
27
  }
27
28
  })
28
29
 
@@ -3,7 +3,7 @@
3
3
  const LogPlugin = require('../../dd-trace/src/plugins/log_plugin')
4
4
 
5
5
  class PinoPlugin extends LogPlugin {
6
- static get name () {
6
+ static get id () {
7
7
  return 'pino'
8
8
  }
9
9
  }
@@ -13,7 +13,7 @@ const { RESOURCE_NAME } = require('../../../ext/tags')
13
13
  const { COMPONENT } = require('../../dd-trace/src/constants')
14
14
 
15
15
  class PlaywrightPlugin extends CiPlugin {
16
- static get name () {
16
+ static get id () {
17
17
  return 'playwright'
18
18
  }
19
19
 
@@ -39,13 +39,14 @@ class PlaywrightPlugin extends CiPlugin {
39
39
  const testSuiteMetadata = getTestSuiteCommonTags(
40
40
  this.command,
41
41
  this.frameworkVersion,
42
- testSuite
42
+ testSuite,
43
+ 'playwright'
43
44
  )
44
45
 
45
46
  const testSuiteSpan = this.tracer.startSpan('playwright.test_suite', {
46
47
  childOf: this.testModuleSpan,
47
48
  tags: {
48
- [COMPONENT]: this.constructor.name,
49
+ [COMPONENT]: this.constructor.id,
49
50
  ...this.testEnvironmentMetadata,
50
51
  ...testSuiteMetadata
51
52
  }
@@ -87,7 +88,7 @@ class PlaywrightPlugin extends CiPlugin {
87
88
  childOf: span,
88
89
  startTime: stepStartTime,
89
90
  tags: {
90
- [COMPONENT]: this.constructor.name,
91
+ [COMPONENT]: this.constructor.id,
91
92
  'playwright.step': step.title,
92
93
  [RESOURCE_NAME]: step.title
93
94
  }
@@ -1,10 +1,11 @@
1
1
  'use strict'
2
2
 
3
+ const { CLIENT_PORT_KEY } = require('../../dd-trace/src/constants')
3
4
  const CachePlugin = require('../../dd-trace/src/plugins/cache')
4
5
  const urlFilter = require('../../dd-trace/src/plugins/util/urlfilter')
5
6
 
6
7
  class RedisPlugin extends CachePlugin {
7
- static get name () { return 'redis' }
8
+ static get id () { return 'redis' }
8
9
  static get system () { return 'redis' }
9
10
 
10
11
  start ({ db, command, args, connectionOptions = {}, connectionName }) {
@@ -20,7 +21,7 @@ class RedisPlugin extends CachePlugin {
20
21
  'db.name': db || '0',
21
22
  'redis.raw_command': formatCommand(command, args),
22
23
  'out.host': connectionOptions.host,
23
- 'out.port': connectionOptions.port
24
+ [CLIENT_PORT_KEY]: connectionOptions.port
24
25
  }
25
26
  })
26
27
  }
@@ -4,7 +4,7 @@ const RouterPlugin = require('../../datadog-plugin-router/src')
4
4
  const web = require('../../dd-trace/src/plugins/util/web')
5
5
 
6
6
  class RestifyPlugin extends RouterPlugin {
7
- static get name () {
7
+ static get id () {
8
8
  return 'restify'
9
9
  }
10
10
 
@@ -4,7 +4,7 @@ const ConsumerPlugin = require('../../dd-trace/src/plugins/consumer')
4
4
  const { storage } = require('../../datadog-core')
5
5
 
6
6
  class RheaConsumerPlugin extends ConsumerPlugin {
7
- static get name () { return 'rhea' }
7
+ static get id () { return 'rhea' }
8
8
 
9
9
  constructor (...args) {
10
10
  super(...args)
@@ -5,7 +5,7 @@ const ConsumerPlugin = require('./consumer')
5
5
  const CompositePlugin = require('../../dd-trace/src/plugins/composite')
6
6
 
7
7
  class RheaPlugin extends CompositePlugin {
8
- static get name () { return 'rhea' }
8
+ static get id () { return 'rhea' }
9
9
  static get plugins () {
10
10
  return {
11
11
  producer: ProducerPlugin,
@@ -1,9 +1,10 @@
1
1
  'use strict'
2
2
 
3
+ const { CLIENT_PORT_KEY } = require('../../dd-trace/src/constants')
3
4
  const ProducerPlugin = require('../../dd-trace/src/plugins/producer')
4
5
 
5
6
  class RheaProducerPlugin extends ProducerPlugin {
6
- static get name () { return 'rhea' }
7
+ static get id () { return 'rhea' }
7
8
  static get operation () { return 'send' }
8
9
 
9
10
  constructor (...args) {
@@ -24,7 +25,7 @@ class RheaProducerPlugin extends ProducerPlugin {
24
25
  'amqp.link.target.address': name,
25
26
  'amqp.link.role': 'sender',
26
27
  'out.host': host,
27
- 'out.port': port
28
+ [CLIENT_PORT_KEY]: port
28
29
  }
29
30
  })
30
31
  }
@@ -7,7 +7,7 @@ const { storage } = require('../../datadog-core')
7
7
  const { COMPONENT } = require('../../dd-trace/src/constants')
8
8
 
9
9
  class RouterPlugin extends WebPlugin {
10
- static get name () {
10
+ static get id () {
11
11
  return 'router'
12
12
  }
13
13
 
@@ -17,7 +17,7 @@ class RouterPlugin extends WebPlugin {
17
17
  this._storeStack = []
18
18
  this._contexts = new WeakMap()
19
19
 
20
- this.addSub(`apm:${this.constructor.name}:middleware:enter`, ({ req, name, route }) => {
20
+ this.addSub(`apm:${this.constructor.id}:middleware:enter`, ({ req, name, route }) => {
21
21
  const childOf = this._getActive(req) || this._getStoreSpan()
22
22
 
23
23
  if (!childOf) return
@@ -37,7 +37,7 @@ class RouterPlugin extends WebPlugin {
37
37
  web.setRoute(req, context.route)
38
38
  })
39
39
 
40
- this.addSub(`apm:${this.constructor.name}:middleware:next`, ({ req }) => {
40
+ this.addSub(`apm:${this.constructor.id}:middleware:next`, ({ req }) => {
41
41
  const context = this._contexts.get(req)
42
42
 
43
43
  if (!context) return
@@ -45,7 +45,7 @@ class RouterPlugin extends WebPlugin {
45
45
  context.stack.pop()
46
46
  })
47
47
 
48
- this.addSub(`apm:${this.constructor.name}:middleware:finish`, ({ req }) => {
48
+ this.addSub(`apm:${this.constructor.id}:middleware:finish`, ({ req }) => {
49
49
  const context = this._contexts.get(req)
50
50
 
51
51
  if (!context || context.middleware.length === 0) return
@@ -53,13 +53,13 @@ class RouterPlugin extends WebPlugin {
53
53
  context.middleware.pop().finish()
54
54
  })
55
55
 
56
- this.addSub(`apm:${this.constructor.name}:middleware:exit`, ({ req }) => {
56
+ this.addSub(`apm:${this.constructor.id}:middleware:exit`, ({ req }) => {
57
57
  const savedStore = this._storeStack.pop()
58
58
  const span = savedStore && savedStore.span
59
59
  this.enter(span, savedStore)
60
60
  })
61
61
 
62
- this.addSub(`apm:${this.constructor.name}:middleware:error`, ({ req, error }) => {
62
+ this.addSub(`apm:${this.constructor.id}:middleware:error`, ({ req, error }) => {
63
63
  web.addError(req, error)
64
64
 
65
65
  if (!this.config.middleware) return
@@ -104,10 +104,10 @@ class RouterPlugin extends WebPlugin {
104
104
  return childOf
105
105
  }
106
106
 
107
- const span = this.tracer.startSpan(`${this.constructor.name}.middleware`, {
107
+ const span = this.tracer.startSpan(`${this.constructor.id}.middleware`, {
108
108
  childOf,
109
109
  tags: {
110
- [COMPONENT]: this.constructor.name,
110
+ [COMPONENT]: this.constructor.id,
111
111
  'resource.name': name || '<anonymous>'
112
112
  }
113
113
  })
@@ -3,7 +3,7 @@
3
3
  const ServerPlugin = require('../../dd-trace/src/plugins/server')
4
4
 
5
5
  class SharedbPlugin extends ServerPlugin {
6
- static get name () { return 'sharedb' }
6
+ static get id () { return 'sharedb' }
7
7
 
8
8
  start ({ actionName, request }) {
9
9
  const span = this.startSpan('sharedb.request', {
@@ -1,9 +1,10 @@
1
1
  'use strict'
2
2
 
3
+ const { CLIENT_PORT_KEY } = require('../../dd-trace/src/constants')
3
4
  const DatabasePlugin = require('../../dd-trace/src/plugins/database')
4
5
 
5
6
  class TediousPlugin extends DatabasePlugin {
6
- static get name () { return 'tedious' }
7
+ static get id () { return 'tedious' }
7
8
  static get operation () { return 'request' } // TODO: change to match other database plugins
8
9
  static get system () { return 'mssql' }
9
10
 
@@ -17,7 +18,7 @@ class TediousPlugin extends DatabasePlugin {
17
18
  'db.type': 'mssql',
18
19
  'component': 'tedious',
19
20
  'out.host': connectionConfig.server,
20
- 'out.port': connectionConfig.options.port,
21
+ [CLIENT_PORT_KEY]: connectionConfig.options.port,
21
22
  'db.user': connectionConfig.userName || connectionConfig.authentication.options.userName,
22
23
  'db.name': connectionConfig.options.database,
23
24
  'db.instance': connectionConfig.options.instanceName
@@ -4,7 +4,7 @@ const Plugin = require('../../dd-trace/src/plugins/plugin')
4
4
  const web = require('../../dd-trace/src/plugins/util/web')
5
5
 
6
6
  class WebPlugin extends Plugin {
7
- static get name () {
7
+ static get id () {
8
8
  return 'web'
9
9
  }
10
10
 
@@ -3,7 +3,7 @@
3
3
  const LogPlugin = require('../../dd-trace/src/plugins/log_plugin')
4
4
 
5
5
  class WinstonPlugin extends LogPlugin {
6
- static get name () {
6
+ static get id () {
7
7
  return 'winston'
8
8
  }
9
9
  }
@@ -16,5 +16,7 @@ module.exports = {
16
16
  HTTP_INCOMING_REMOTE_IP: 'server.request.client_ip',
17
17
  HTTP_INCOMING_REMOTE_PORT: 'server.request.client_port',
18
18
 
19
- HTTP_CLIENT_IP: 'http.client_ip'
19
+ HTTP_CLIENT_IP: 'http.client_ip',
20
+
21
+ USER_ID: 'usr.id'
20
22
  }
@@ -1,8 +1,19 @@
1
1
  'use strict'
2
2
 
3
+ const log = require('../log')
3
4
  const fs = require('fs')
4
- let templateHtml, templateJson
5
- function block (req, res, topSpan, abortController) {
5
+
6
+ // TODO: move template loading to a proper spot.
7
+ let templateLoaded = false
8
+ let templateHtml = ''
9
+ let templateJson = ''
10
+
11
+ function block (req, res, rootSpan, abortController) {
12
+ if (res.headersSent) {
13
+ log.warn('Cannot send blocking response when headers have already been sent')
14
+ return
15
+ }
16
+
6
17
  let type
7
18
  let body
8
19
 
@@ -17,7 +28,7 @@ function block (req, res, topSpan, abortController) {
17
28
  body = templateJson
18
29
  }
19
30
 
20
- topSpan.addTags({
31
+ rootSpan.addTags({
21
32
  'appsec.blocked': 'true'
22
33
  })
23
34
 
@@ -26,19 +37,34 @@ function block (req, res, topSpan, abortController) {
26
37
  res.setHeader('Content-Length', Buffer.byteLength(body))
27
38
  res.end(body)
28
39
 
29
- abortController.abort()
40
+ if (abortController) {
41
+ abortController.abort()
42
+ }
30
43
  }
31
44
 
32
45
  function loadTemplates (config) {
33
- templateHtml = fs.readFileSync(config.appsec.blockedTemplateHtml)
34
- templateJson = fs.readFileSync(config.appsec.blockedTemplateJson)
46
+ if (!templateLoaded) {
47
+ templateHtml = fs.readFileSync(config.appsec.blockedTemplateHtml)
48
+ templateJson = fs.readFileSync(config.appsec.blockedTemplateJson)
49
+ templateLoaded = true
50
+ }
35
51
  }
36
52
 
37
53
  async function loadTemplatesAsync (config) {
38
- templateHtml = await fs.promises.readFile(config.appsec.blockedTemplateHtml)
39
- templateJson = await fs.promises.readFile(config.appsec.blockedTemplateJson)
54
+ if (!templateLoaded) {
55
+ templateHtml = await fs.promises.readFile(config.appsec.blockedTemplateHtml)
56
+ templateJson = await fs.promises.readFile(config.appsec.blockedTemplateJson)
57
+ templateLoaded = true
58
+ }
59
+ }
60
+
61
+ function resetTemplates () {
62
+ templateLoaded = false
40
63
  }
41
64
 
42
65
  module.exports = {
43
- block, loadTemplates, loadTemplatesAsync
66
+ block,
67
+ loadTemplates,
68
+ loadTemplatesAsync,
69
+ resetTemplates
44
70
  }
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const als = require('../als')
4
+ const log = require('../../../log')
4
5
 
5
6
  let lock = false // lock to prevent recursive calls to runSubscriptions
6
7
 
@@ -25,7 +26,7 @@ function runSubscriptions (subscriptions, params) {
25
26
  try {
26
27
  result = subscription.callback.method(params, store)
27
28
  } catch (err) {
28
- // TODO: log ?
29
+ log.warn(`Error running subscription ${err}`)
29
30
  }
30
31
 
31
32
  results.push(result)
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  module.exports = {
2
4
  'WEAK_CIPHER_ANALYZER': require('./weak-cipher-analyzer'),
3
5
  'WEAK_HASH_ANALYZER': require('./weak-hash-analyzer'),
@@ -2,7 +2,7 @@
2
2
 
3
3
  const Plugin = require('../../../../src/plugins/plugin')
4
4
  const { storage } = require('../../../../../datadog-core')
5
- const log = require('../../../log')
5
+ const iastLog = require('../iast-log')
6
6
  const { getFirstNonDDPathAndLine } = require('../path-line')
7
7
  const { createVulnerability, addVulnerability } = require('../vulnerability-reporter')
8
8
  const { getIastContext } = require('../iast-context')
@@ -19,7 +19,7 @@ class Analyzer extends Plugin {
19
19
  try {
20
20
  handler(message, name)
21
21
  } catch (e) {
22
- log.debug(e)
22
+ iastLog.errorAndPublish(e)
23
23
  }
24
24
  }
25
25
  }
@@ -1,8 +1,12 @@
1
1
  const IAST_CONTEXT_KEY = Symbol('_dd.iast.context')
2
2
  const IAST_TRANSACTION_ID = Symbol('_dd.iast.transactionId')
3
3
 
4
- function getIastContext (store) {
5
- return store && store[IAST_CONTEXT_KEY]
4
+ function getIastContext (store, topContext) {
5
+ let iastContext = store && store[IAST_CONTEXT_KEY]
6
+ if (!iastContext) {
7
+ iastContext = topContext && topContext[IAST_CONTEXT_KEY]
8
+ }
9
+ return iastContext
6
10
  }
7
11
 
8
12
  /* TODO Fix storage problem when the close event is called without
@@ -0,0 +1,111 @@
1
+ 'use strict'
2
+
3
+ const log = require('../../log')
4
+ const telemetryLogs = require('./telemetry/logs')
5
+ const { calculateDDBasePath } = require('../../util')
6
+
7
+ const ddBasePath = calculateDDBasePath(__dirname)
8
+ const EOL = '\n'
9
+ const STACK_FRAME_LINE_REGEX = /^\s*at\s/gm
10
+
11
+ function sanitize (logEntry, stack) {
12
+ if (!stack) return logEntry
13
+
14
+ let stackLines = stack.split(EOL)
15
+
16
+ const firstIndex = stackLines.findIndex(l => l.match(STACK_FRAME_LINE_REGEX))
17
+
18
+ const isDDCode = firstIndex > -1 && stackLines[firstIndex].includes(ddBasePath)
19
+ stackLines = stackLines
20
+ .filter((line, index) => (isDDCode && index < firstIndex) || line.includes(ddBasePath))
21
+ .map(line => line.replace(ddBasePath, ''))
22
+
23
+ logEntry.stack_trace = stackLines.join(EOL)
24
+
25
+ if (!isDDCode) {
26
+ logEntry.message = 'omitted'
27
+ }
28
+
29
+ return logEntry
30
+ }
31
+
32
+ function getTelemetryLog (data, level) {
33
+ try {
34
+ data = typeof data === 'function' ? data() : data
35
+
36
+ let message
37
+ if (typeof data !== 'object' || !data) {
38
+ message = String(data)
39
+ } else {
40
+ message = String(data.message || data)
41
+ }
42
+
43
+ let logEntry = {
44
+ message,
45
+ level
46
+ }
47
+
48
+ if (data.stack) {
49
+ logEntry = sanitize(logEntry, data.stack)
50
+ if (logEntry.stack_trace === '') {
51
+ return
52
+ }
53
+ }
54
+
55
+ return logEntry
56
+ } catch (e) {
57
+ log.error(e)
58
+ }
59
+ }
60
+
61
+ const iastLog = {
62
+ debug (data) {
63
+ log.debug(data)
64
+ return this
65
+ },
66
+
67
+ info (data) {
68
+ log.info(data)
69
+ return this
70
+ },
71
+
72
+ warn (data) {
73
+ log.warn(data)
74
+ return this
75
+ },
76
+
77
+ error (data) {
78
+ log.error(data)
79
+ return this
80
+ },
81
+
82
+ publish (data, level) {
83
+ if (telemetryLogs.isLevelEnabled(level)) {
84
+ const telemetryLog = getTelemetryLog(data, level)
85
+ telemetryLogs.publish(telemetryLog)
86
+ }
87
+ return this
88
+ },
89
+
90
+ debugAndPublish (data) {
91
+ this.debug(data)
92
+ return this.publish(data, 'DEBUG')
93
+ },
94
+
95
+ infoAndPublish (data) {
96
+ this.info(data)
97
+ return this.publish(data, 'DEBUG')
98
+ },
99
+
100
+ warnAndPublish (data) {
101
+ this.warn(data)
102
+ return this.publish(data, 'WARN')
103
+ },
104
+
105
+ errorAndPublish (data) {
106
+ this.error(data)
107
+ return this.publish(data, 'ERROR')
108
+ }
109
+ }
110
+
111
+ module.exports = iastLog
@@ -1,4 +1,4 @@
1
- const { sendVulnerabilities, setTracer } = require('./vulnerability-reporter')
1
+ const vulnerabilityReporter = require('./vulnerability-reporter')
2
2
  const { enableAllAnalyzers, disableAllAnalyzers } = require('./analyzers')
3
3
  const web = require('../../plugins/util/web')
4
4
  const { storage } = require('../../../../datadog-core')
@@ -6,7 +6,7 @@ const overheadController = require('./overhead-controller')
6
6
  const dc = require('diagnostics_channel')
7
7
  const iastContextFunctions = require('./iast-context')
8
8
  const { enableTaintTracking, disableTaintTracking, createTransaction, removeTransaction } = require('./taint-tracking')
9
-
9
+ const telemetryLogs = require('./telemetry/logs')
10
10
  const IAST_ENABLED_TAG_KEY = '_dd.iast.enabled'
11
11
 
12
12
  // TODO Change to `apm:http:server:request:[start|close]` when the subscription
@@ -21,7 +21,8 @@ function enable (config, _tracer) {
21
21
  requestClose.subscribe(onIncomingHttpRequestEnd)
22
22
  overheadController.configure(config.iast)
23
23
  overheadController.startGlobalContext()
24
- setTracer(_tracer)
24
+ vulnerabilityReporter.start(config, _tracer)
25
+ telemetryLogs.start()
25
26
  }
26
27
 
27
28
  function disable () {
@@ -30,6 +31,8 @@ function disable () {
30
31
  overheadController.finishGlobalContext()
31
32
  if (requestStart.hasSubscribers) requestStart.unsubscribe(onIncomingHttpRequestStart)
32
33
  if (requestClose.hasSubscribers) requestClose.unsubscribe(onIncomingHttpRequestEnd)
34
+ vulnerabilityReporter.stop()
35
+ telemetryLogs.stop()
33
36
  }
34
37
 
35
38
  function onIncomingHttpRequestStart (data) {
@@ -58,15 +61,16 @@ function onIncomingHttpRequestStart (data) {
58
61
  function onIncomingHttpRequestEnd (data) {
59
62
  if (data && data.req) {
60
63
  const store = storage.getStore()
61
- const iastContext = iastContextFunctions.getIastContext(storage.getStore())
64
+ const topContext = web.getContext(data.req)
65
+ const iastContext = iastContextFunctions.getIastContext(store, topContext)
62
66
  if (iastContext && iastContext.rootSpan) {
63
67
  const vulnerabilities = iastContext.vulnerabilities
64
68
  const rootSpan = iastContext.rootSpan
65
- sendVulnerabilities(vulnerabilities, rootSpan)
69
+ vulnerabilityReporter.sendVulnerabilities(vulnerabilities, rootSpan)
66
70
  removeTransaction(iastContext)
67
71
  }
68
72
  // TODO web.getContext(data.req) is required when the request is aborted
69
- if (iastContextFunctions.cleanIastContext(store, web.getContext(data.req), iastContext)) {
73
+ if (iastContextFunctions.cleanIastContext(store, topContext, iastContext)) {
70
74
  overheadController.releaseRequest()
71
75
  }
72
76
  }
@@ -1,5 +1,8 @@
1
+ 'use strict'
2
+
1
3
  const path = require('path')
2
4
  const process = require('process')
5
+ const { calculateDDBasePath } = require('../../util')
3
6
  const pathLine = {
4
7
  getFirstNonDDPathAndLine,
5
8
  getFirstNonDDPathAndLineFromCallsites, // Exported only for test purposes
@@ -19,12 +22,6 @@ const EXCLUDED_PATH_PREFIXES = [
19
22
  'async_hooks'
20
23
  ]
21
24
 
22
- function calculateDDBasePath (dirname) {
23
- const dirSteps = dirname.split(path.sep)
24
- const packagesIndex = dirSteps.lastIndexOf('packages')
25
- return dirSteps.slice(0, packagesIndex).join(path.sep) + path.sep
26
- }
27
-
28
25
  function getCallSiteInfo () {
29
26
  const previousPrepareStackTrace = Error.prepareStackTrace
30
27
  const previousStackTraceLimit = Error.stackTraceLimit
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const { enableRewriter, disableRewriter } = require('./rewriter')
2
4
  const { createTransaction, removeTransaction, enableTaintOperations, disableTaintOperations } = require('./operations')
3
5
  const taintTrackingPlugin = require('./plugin')
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const TaintedUtils = require('@datadog/native-iast-taint-tracking')
2
4
  const { IAST_TRANSACTION_ID } = require('../iast-context')
3
5
  const { TaintTracking, TaintTrackingDummy } = require('./taint-tracking-impl')
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  module.exports = {
2
4
  HTTP_REQUEST_BODY: 'http.request.body',
3
5
  HTTP_REQUEST_PARAMETER: 'http.request.parameter'
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const Plugin = require('../../../plugins/plugin')
2
4
  const { getIastContext } = require('../iast-context')
3
5
  const { storage } = require('../../../../../datadog-core')