dd-trace 2.27.1 → 2.29.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
@@ -7,7 +7,7 @@ const { incomingHttpRequestStart, incomingHttpRequestEnd } = require('../../dd-t
7
7
  const { COMPONENT } = require('../../dd-trace/src/constants')
8
8
 
9
9
  class HttpServerPlugin extends Plugin {
10
- static get name () {
10
+ static get id () {
11
11
  return 'http'
12
12
  }
13
13
 
@@ -20,10 +20,10 @@ class HttpServerPlugin extends Plugin {
20
20
  const store = storage.getStore()
21
21
  const span = web.startSpan(this.tracer, this.config, req, res, 'http.request')
22
22
 
23
- span.setTag(COMPONENT, this.constructor.name)
23
+ span.setTag(COMPONENT, this.constructor.id)
24
24
 
25
25
  this._parentStore = store
26
- this.enter(span, { ...store, req })
26
+ this.enter(span, { ...store, req, res })
27
27
 
28
28
  const context = web.getContext(req)
29
29
 
@@ -9,7 +9,7 @@ const tags = require('../../../ext/tags')
9
9
  const kinds = require('../../../ext/kinds')
10
10
  const formats = require('../../../ext/formats')
11
11
  const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
12
- const { COMPONENT } = require('../../dd-trace/src/constants')
12
+ const { COMPONENT, CLIENT_PORT_KEY } = require('../../dd-trace/src/constants')
13
13
  const urlFilter = require('../../dd-trace/src/plugins/util/urlfilter')
14
14
 
15
15
  const HTTP_HEADERS = formats.HTTP_HEADERS
@@ -25,7 +25,7 @@ const HTTP2_HEADER_STATUS = ':status'
25
25
  const HTTP2_METHOD_GET = 'GET'
26
26
 
27
27
  class Http2ClientPlugin extends Plugin {
28
- static get name () {
28
+ static get id () {
29
29
  return 'http2'
30
30
  }
31
31
 
@@ -45,7 +45,8 @@ class Http2ClientPlugin extends Plugin {
45
45
  const span = this.tracer.startSpan('http.request', {
46
46
  childOf,
47
47
  tags: {
48
- [COMPONENT]: this.constructor.name,
48
+ [COMPONENT]: this.constructor.id,
49
+ [CLIENT_PORT_KEY]: parseInt(sessionDetails.port),
49
50
  [SPAN_KIND]: CLIENT,
50
51
  'service.name': getServiceName(this.tracer, this.config, sessionDetails),
51
52
  'resource.name': method,
@@ -5,7 +5,7 @@ const Http2ClientPlugin = require('./client')
5
5
  const CompositePlugin = require('../../dd-trace/src/plugins/composite')
6
6
 
7
7
  class Http2Plugin extends CompositePlugin {
8
- static get name () { return 'http2' }
8
+ static get id () { return 'http2' }
9
9
  static get plugins () {
10
10
  return {
11
11
  server: Http2ServerPlugin,
@@ -9,7 +9,7 @@ const { incomingHttpRequestStart } = require('../../dd-trace/src/appsec/gateway/
9
9
  const { COMPONENT } = require('../../dd-trace/src/constants')
10
10
 
11
11
  class Http2ServerPlugin extends Plugin {
12
- static get name () {
12
+ static get id () {
13
13
  return 'http2'
14
14
  }
15
15
 
@@ -20,9 +20,9 @@ class Http2ServerPlugin extends Plugin {
20
20
  const store = storage.getStore()
21
21
  const span = web.startSpan(this.tracer, this.config, req, res, 'web.request')
22
22
 
23
- span.setTag(COMPONENT, this.constructor.name)
23
+ span.setTag(COMPONENT, this.constructor.id)
24
24
 
25
- this.enter(span, { ...store, req })
25
+ this.enter(span, { ...store, req, res })
26
26
 
27
27
  const context = web.getContext(req)
28
28
 
@@ -3,7 +3,7 @@
3
3
  const RedisPlugin = require('../../datadog-plugin-redis/src')
4
4
 
5
5
  class IORedisPlugin extends RedisPlugin {
6
- static get name () {
6
+ static get id () {
7
7
  return 'ioredis'
8
8
  }
9
9
  }
@@ -5,43 +5,40 @@ const {
5
5
  TEST_STATUS,
6
6
  JEST_TEST_RUNNER,
7
7
  finishAllTraceSpans,
8
- getTestEnvironmentMetadata,
9
8
  getTestSuiteCommonTags,
10
9
  addIntelligentTestRunnerSpanTags,
11
10
  TEST_PARAMETERS,
12
- getCodeOwnersFileEntries,
13
11
  TEST_COMMAND,
14
12
  TEST_FRAMEWORK_VERSION
15
13
  } = require('../../dd-trace/src/plugins/util/test')
16
14
  const { COMPONENT } = require('../../dd-trace/src/constants')
15
+ const id = require('../../dd-trace/src/id')
16
+
17
+ const isJestWorker = !!process.env.JEST_WORKER_ID
17
18
 
18
19
  // https://github.com/facebook/jest/blob/d6ad15b0f88a05816c2fe034dd6900d28315d570/packages/jest-worker/src/types.ts#L38
19
20
  const CHILD_MESSAGE_END = 2
20
21
 
21
22
  class JestPlugin extends CiPlugin {
22
- static get name () {
23
+ static get id () {
23
24
  return 'jest'
24
25
  }
25
26
 
26
27
  constructor (...args) {
27
28
  super(...args)
28
29
 
29
- // Used to handle the end of a jest worker to be able to flush
30
- const handler = ([message]) => {
31
- if (message === CHILD_MESSAGE_END) {
32
- this.tracer._exporter.flush(() => {
33
- // eslint-disable-next-line
34
- // https://github.com/facebook/jest/blob/24ed3b5ecb419c023ee6fdbc838f07cc028fc007/packages/jest-worker/src/workers/processChild.ts#L118-L133
35
- // Only after the flush is done we clean up open handles
36
- // so the worker process can hopefully exit gracefully
30
+ if (isJestWorker) {
31
+ // Used to handle the end of a jest worker to be able to flush
32
+ const handler = ([message]) => {
33
+ if (message === CHILD_MESSAGE_END) {
34
+ this.testSuiteSpan.finish()
35
+ finishAllTraceSpans(this.testSuiteSpan)
36
+ this.tracer._exporter.flush()
37
37
  process.removeListener('message', handler)
38
- })
38
+ }
39
39
  }
40
+ process.on('message', handler)
40
41
  }
41
- process.on('message', handler)
42
-
43
- this.testEnvironmentMetadata = getTestEnvironmentMetadata('jest', this.config)
44
- this.codeOwnersEntries = getCodeOwnersFileEntries()
45
42
 
46
43
  this.addSub('ci:jest:session:finish', ({
47
44
  status,
@@ -88,18 +85,44 @@ class JestPlugin extends CiPlugin {
88
85
  'x-datadog-parent-id': testModuleId
89
86
  })
90
87
 
91
- const testSuiteMetadata = getTestSuiteCommonTags(testCommand, frameworkVersion, testSuite)
88
+ const testSuiteMetadata = getTestSuiteCommonTags(testCommand, frameworkVersion, testSuite, 'jest')
92
89
 
93
90
  this.testSuiteSpan = this.tracer.startSpan('jest.test_suite', {
94
91
  childOf: testSessionSpanContext,
95
92
  tags: {
96
- [COMPONENT]: this.constructor.name,
93
+ [COMPONENT]: this.constructor.id,
97
94
  ...this.testEnvironmentMetadata,
98
95
  ...testSuiteMetadata
99
96
  }
100
97
  })
101
98
  })
102
99
 
100
+ this.addSub('ci:jest:worker-report:trace', traces => {
101
+ const formattedTraces = JSON.parse(traces).map(trace =>
102
+ trace.map(span => ({
103
+ ...span,
104
+ span_id: id(span.span_id),
105
+ trace_id: id(span.trace_id),
106
+ parent_id: id(span.parent_id)
107
+ }))
108
+ )
109
+
110
+ formattedTraces.forEach(trace => {
111
+ this.tracer._exporter.export(trace)
112
+ })
113
+ })
114
+
115
+ this.addSub('ci:jest:worker-report:coverage', data => {
116
+ const formattedCoverages = JSON.parse(data).map(coverage => ({
117
+ traceId: id(coverage.traceId),
118
+ spanId: id(coverage.spanId),
119
+ files: coverage.files
120
+ }))
121
+ formattedCoverages.forEach(formattedCoverage => {
122
+ this.tracer._exporter.exportCoverage(formattedCoverage)
123
+ })
124
+ })
125
+
103
126
  this.addSub('ci:jest:test-suite:finish', ({ status, errorMessage }) => {
104
127
  this.testSuiteSpan.setTag(TEST_STATUS, status)
105
128
  if (errorMessage) {
@@ -109,6 +132,12 @@ class JestPlugin extends CiPlugin {
109
132
  // Suites potentially run in a different process than the session,
110
133
  // so calling finishAllTraceSpans on the session span is not enough
111
134
  finishAllTraceSpans(this.testSuiteSpan)
135
+ // Flushing within jest workers is cheap, as it's just interprocess communication
136
+ // We do not want to flush after every suite if jest is running tests serially,
137
+ // as every flush is an HTTP request.
138
+ if (isJestWorker) {
139
+ this.tracer._exporter.flush()
140
+ }
112
141
  })
113
142
 
114
143
  /**
@@ -117,7 +146,12 @@ class JestPlugin extends CiPlugin {
117
146
  * fetching the ITR config.
118
147
  */
119
148
  this.addSub('ci:jest:test-suite:code-coverage', (coverageFiles) => {
120
- this.tracer._exporter.exportCoverage({ span: this.testSuiteSpan, coverageFiles })
149
+ const formattedCoverage = {
150
+ traceId: this.testSuiteSpan.context()._traceId,
151
+ spanId: this.testSuiteSpan.context()._spanId,
152
+ files: coverageFiles
153
+ }
154
+ this.tracer._exporter.exportCoverage(formattedCoverage)
121
155
  })
122
156
 
123
157
  this.addSub('ci:jest:test:start', (test) => {
@@ -3,7 +3,7 @@
3
3
  const ConsumerPlugin = require('../../dd-trace/src/plugins/consumer')
4
4
 
5
5
  class KafkajsConsumerPlugin extends ConsumerPlugin {
6
- static get name () { return 'kafkajs' }
6
+ static get id () { return 'kafkajs' }
7
7
  static get operation () { return 'consume' }
8
8
 
9
9
  start ({ topic, partition, message }) {
@@ -5,7 +5,7 @@ const ConsumerPlugin = require('./consumer')
5
5
  const CompositePlugin = require('../../dd-trace/src/plugins/composite')
6
6
 
7
7
  class KafkajsPlugin extends CompositePlugin {
8
- static get name () { return 'kafkajs' }
8
+ static get id () { return 'kafkajs' }
9
9
  static get plugins () {
10
10
  return {
11
11
  producer: ProducerPlugin,
@@ -3,7 +3,7 @@
3
3
  const ProducerPlugin = require('../../dd-trace/src/plugins/producer')
4
4
 
5
5
  class KafkajsProducerPlugin extends ProducerPlugin {
6
- static get name () { return 'kafkajs' }
6
+ static get id () { return 'kafkajs' }
7
7
  static get operation () { return 'produce' }
8
8
 
9
9
  start ({ topic, messages }) {
@@ -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 KoaPlugin extends RouterPlugin {
7
- static get name () {
7
+ static get id () {
8
8
  return 'koa'
9
9
  }
10
10
 
@@ -1,10 +1,27 @@
1
1
  'use strict'
2
2
 
3
+ const { storage } = require('../../datadog-core')
3
4
  const MySQLPlugin = require('../../datadog-plugin-mysql/src')
4
5
 
6
+ let skippedStore
7
+
5
8
  class MariadbPlugin extends MySQLPlugin {
6
- static get name () { return 'mariadb' }
9
+ static get id () { return 'mariadb' }
7
10
  static get system () { return 'mariadb' }
11
+
12
+ constructor (...args) {
13
+ super(...args)
14
+
15
+ this.addSub(`apm:${this.component}:pool:skip`, () => {
16
+ skippedStore = storage.getStore()
17
+ storage.enterWith({ noop: true })
18
+ })
19
+
20
+ this.addSub(`apm:${this.component}:pool:unskip`, () => {
21
+ storage.enterWith(skippedStore)
22
+ skippedStore = undefined
23
+ })
24
+ }
8
25
  }
9
26
 
10
27
  module.exports = MariadbPlugin
@@ -1,9 +1,10 @@
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
 
5
6
  class MemcachedPlugin extends CachePlugin {
6
- static get name () { return 'memcached' }
7
+ static get id () { return 'memcached' }
7
8
 
8
9
  start ({ client, server, query }) {
9
10
  const address = getAddress(client, server, query)
@@ -16,7 +17,7 @@ class MemcachedPlugin extends CachePlugin {
16
17
  meta: {
17
18
  'memcached.command': query.command,
18
19
  'out.host': address[0],
19
- 'out.port': address[1]
20
+ [CLIENT_PORT_KEY]: address[1]
20
21
  }
21
22
  })
22
23
  }
@@ -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 MicrogatewayCorePlugin extends RouterPlugin {
7
- static get name () {
7
+ static get id () {
8
8
  return 'microgateway-core'
9
9
  }
10
10
 
@@ -15,7 +15,7 @@ const {
15
15
  const { COMPONENT } = require('../../dd-trace/src/constants')
16
16
 
17
17
  class MochaPlugin extends CiPlugin {
18
- static get name () {
18
+ static get id () {
19
19
  return 'mocha'
20
20
  }
21
21
 
@@ -35,10 +35,13 @@ class MochaPlugin extends CiPlugin {
35
35
  const relativeCoverageFiles = [...coverageFiles, suiteFile]
36
36
  .map(filename => getTestSuitePath(filename, this.sourceRoot))
37
37
 
38
- this.tracer._exporter.exportCoverage({
39
- span: testSuiteSpan,
40
- coverageFiles: relativeCoverageFiles
41
- })
38
+ const formattedCoverage = {
39
+ traceId: testSuiteSpan.context()._traceId,
40
+ spanId: testSuiteSpan.context()._spanId,
41
+ files: relativeCoverageFiles
42
+ }
43
+
44
+ this.tracer._exporter.exportCoverage(formattedCoverage)
42
45
  })
43
46
 
44
47
  this.addSub('ci:mocha:test-suite:start', (suite) => {
@@ -46,12 +49,13 @@ class MochaPlugin extends CiPlugin {
46
49
  const testSuiteMetadata = getTestSuiteCommonTags(
47
50
  this.command,
48
51
  this.frameworkVersion,
49
- getTestSuitePath(suite.file, this.sourceRoot)
52
+ getTestSuitePath(suite.file, this.sourceRoot),
53
+ 'mocha'
50
54
  )
51
55
  const testSuiteSpan = this.tracer.startSpan('mocha.test_suite', {
52
56
  childOf: this.testModuleSpan,
53
57
  tags: {
54
- [COMPONENT]: this.constructor.name,
58
+ [COMPONENT]: this.constructor.id,
55
59
  ...this.testEnvironmentMetadata,
56
60
  ...testSuiteMetadata
57
61
  }
@@ -128,7 +132,7 @@ class MochaPlugin extends CiPlugin {
128
132
  this._testNameToParams[name] = params
129
133
  })
130
134
 
131
- this.addSub('ci:mocha:session:finish', ({ status, isSuitesSkipped }) => {
135
+ this.addSub('ci:mocha:session:finish', ({ status, isSuitesSkipped, testCodeCoverageLinesTotal }) => {
132
136
  if (this.testSessionSpan) {
133
137
  const { isSuitesSkippingEnabled, isCodeCoverageEnabled } = this.itrConfig || {}
134
138
  this.testSessionSpan.setTag(TEST_STATUS, status)
@@ -137,7 +141,7 @@ class MochaPlugin extends CiPlugin {
137
141
  addIntelligentTestRunnerSpanTags(
138
142
  this.testSessionSpan,
139
143
  this.testModuleSpan,
140
- { isSuitesSkipped, isSuitesSkippingEnabled, isCodeCoverageEnabled }
144
+ { isSuitesSkipped, isSuitesSkippingEnabled, isCodeCoverageEnabled, testCodeCoverageLinesTotal }
141
145
  )
142
146
 
143
147
  this.testModuleSpan.finish()
@@ -4,7 +4,7 @@ const ClientPlugin = require('../../dd-trace/src/plugins/client')
4
4
  const { moleculerTags } = require('./util')
5
5
 
6
6
  class MoleculerClientPlugin extends ClientPlugin {
7
- static get name () { return 'moleculer' }
7
+ static get id () { return 'moleculer' }
8
8
  static get operation () { return 'call' }
9
9
 
10
10
  start ({ actionName, opts }) {
@@ -7,7 +7,7 @@ const MoleculerClientPlugin = require('./client')
7
7
  const CompositePlugin = require('../../dd-trace/src/plugins/composite')
8
8
 
9
9
  class MoleculerPlugin extends CompositePlugin {
10
- static get name () { return 'moleculer' }
10
+ static get id () { return 'moleculer' }
11
11
  static get plugins () {
12
12
  return {
13
13
  server: MoleculerServerPlugin,
@@ -4,7 +4,7 @@ const ServerPlugin = require('../../dd-trace/src/plugins/server')
4
4
  const { moleculerTags } = require('./util')
5
5
 
6
6
  class MoleculerServerPlugin extends ServerPlugin {
7
- static get name () { return 'moleculer' }
7
+ static get id () { return 'moleculer' }
8
8
  static get operation () { return 'action' }
9
9
 
10
10
  start ({ action, ctx, broker }) {
@@ -3,7 +3,7 @@
3
3
  const DatabasePlugin = require('../../dd-trace/src/plugins/database')
4
4
 
5
5
  class MongodbCorePlugin extends DatabasePlugin {
6
- static get name () { return 'mongodb-core' }
6
+ static get id () { return 'mongodb-core' }
7
7
  static get component () { return 'mongodb' }
8
8
 
9
9
  start ({ ns, ops, options = {}, name }) {
@@ -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 MySQLPlugin extends DatabasePlugin {
6
- static get name () { return 'mysql' }
7
+ static get id () { return 'mysql' }
7
8
  static get system () { return 'mysql' }
8
9
 
9
10
  start (payload) {
@@ -19,7 +20,7 @@ class MySQLPlugin extends DatabasePlugin {
19
20
  'db.user': payload.conf.user,
20
21
  'db.name': payload.conf.database,
21
22
  'out.host': payload.conf.host,
22
- 'out.port': payload.conf.port
23
+ [CLIENT_PORT_KEY]: payload.conf.port
23
24
  }
24
25
  })
25
26
  payload.sql = this.injectDbmQuery(payload.sql, service)
@@ -3,7 +3,7 @@
3
3
  const MySQLPlugin = require('../../datadog-plugin-mysql/src')
4
4
 
5
5
  class MySQL2Plugin extends MySQLPlugin {
6
- static get name () { return 'mysql2' }
6
+ static get id () { return 'mysql2' }
7
7
  }
8
8
 
9
9
  module.exports = MySQL2Plugin
@@ -1,89 +1,23 @@
1
1
  'use strict'
2
2
 
3
3
  const Plugin = require('../../dd-trace/src/plugins/plugin')
4
- const { storage } = require('../../datadog-core')
5
- const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
6
- const { COMPONENT } = require('../../dd-trace/src/constants')
4
+ const NetIPCPlugin = require('./ipc')
5
+ const NetTCPPlugin = require('./tcp')
7
6
 
8
7
  class NetPlugin extends Plugin {
9
- static get name () {
10
- return 'net'
11
- }
8
+ static get id () { return 'net' }
12
9
 
13
10
  constructor (...args) {
14
11
  super(...args)
15
12
 
16
- this.addSub(`apm:net:ipc:start`, ({ options }) => {
17
- const store = storage.getStore()
18
- const childOf = store ? store.span : store
19
-
20
- const span = this.tracer.startSpan('ipc.connect', {
21
- childOf,
22
- tags: {
23
- [COMPONENT]: this.constructor.name,
24
- 'resource.name': options.path,
25
- 'ipc.path': options.path,
26
- 'span.kind': 'client',
27
- 'service.name': this.config.service || this.tracer._service
28
- }
29
- })
30
-
31
- analyticsSampler.sample(span, this.config.measured)
32
- this.enter(span, store)
33
- })
34
-
35
- this.addSub(`apm:net:ipc:error`, errorHandler)
36
-
37
- this.addSub(`apm:net:ipc:finish`, defaultFinish)
38
-
39
- this.addSub(`apm:net:tcp:start`, ({ options }) => {
40
- const store = storage.getStore()
41
- const childOf = store ? store.span : store
42
-
43
- const host = options.host || 'localhost'
44
- const port = options.port || 0
45
- const family = options.family || 4
46
-
47
- const span = this.tracer.startSpan('tcp.connect', {
48
- childOf,
49
- tags: {
50
- [COMPONENT]: this.constructor.name,
51
- 'resource.name': [host, port].filter(val => val).join(':'),
52
- 'tcp.remote.host': host,
53
- 'tcp.remote.port': port,
54
- 'tcp.family': `IPv${family}`,
55
- 'out.host': host,
56
- 'out.port': port,
57
- 'span.kind': 'client',
58
- 'service.name': this.config.service || this.tracer._service
59
- }
60
- })
61
-
62
- analyticsSampler.sample(span, this.config.measured)
63
- this.enter(span, store)
64
- })
65
-
66
- this.addSub(`apm:net:tcp:error`, errorHandler)
67
-
68
- this.addSub(`apm:net:tcp:finish`, defaultFinish)
69
-
70
- this.addSub(`apm:net:tcp:connection`, ({ socket }) => {
71
- const span = storage.getStore().span
72
- span.addTags({
73
- [COMPONENT]: this.constructor.name,
74
- 'tcp.local.address': socket.localAddress,
75
- 'tcp.local.port': socket.localPort
76
- })
77
- })
13
+ this._ipc = new NetIPCPlugin(...args)
14
+ this._tcp = new NetTCPPlugin(...args)
78
15
  }
79
- }
80
-
81
- function defaultFinish () {
82
- storage.getStore().span.finish()
83
- }
84
16
 
85
- function errorHandler (error) {
86
- storage.getStore().span.setTag('error', error)
17
+ configure (config) {
18
+ this._ipc.configure(config)
19
+ this._tcp.configure(config)
20
+ }
87
21
  }
88
22
 
89
23
  module.exports = NetPlugin
@@ -3,7 +3,7 @@
3
3
  const ClientPlugin = require('../../dd-trace/src/plugins/client')
4
4
 
5
5
  class NetIPCPlugin extends ClientPlugin {
6
- static get name () { return 'net' }
6
+ static get id () { return 'net' }
7
7
  static get operation () { return 'ipc' }
8
8
 
9
9
  start ({ options }) {
@@ -1,9 +1,10 @@
1
1
  'use strict'
2
2
 
3
+ const { CLIENT_PORT_KEY } = require('../../dd-trace/src/constants')
3
4
  const ClientPlugin = require('../../dd-trace/src/plugins/client')
4
5
 
5
6
  class NetTCPPlugin extends ClientPlugin {
6
- static get name () { return 'net' }
7
+ static get id () { return 'net' }
7
8
  static get operation () { return 'tcp' }
8
9
 
9
10
  constructor (...args) {
@@ -37,7 +38,7 @@ class NetTCPPlugin extends ClientPlugin {
37
38
  metrics: {
38
39
  'tcp.remote.port': port,
39
40
  'tcp.local.port': 0,
40
- 'out.port': port
41
+ [CLIENT_PORT_KEY]: port
41
42
  }
42
43
  })
43
44
  }
@@ -6,7 +6,7 @@ const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
6
6
  const { COMPONENT } = require('../../dd-trace/src/constants')
7
7
 
8
8
  class NextPlugin extends Plugin {
9
- static get name () {
9
+ static get id () {
10
10
  return 'next'
11
11
  }
12
12
 
@@ -21,7 +21,7 @@ class NextPlugin extends Plugin {
21
21
  const span = this.tracer.startSpan('next.request', {
22
22
  childOf,
23
23
  tags: {
24
- [COMPONENT]: this.constructor.name,
24
+ [COMPONENT]: this.constructor.id,
25
25
  'service.name': this.config.service || this.tracer._service,
26
26
  'resource.name': req.method,
27
27
  'span.type': 'web',
@@ -69,7 +69,7 @@ class NextPlugin extends Plugin {
69
69
  const req = this._requests.get(span)
70
70
 
71
71
  span.addTags({
72
- [COMPONENT]: this.constructor.name,
72
+ [COMPONENT]: this.constructor.id,
73
73
  'resource.name': `${req.method} ${page}`.trim(),
74
74
  'next.page': page
75
75
  })
@@ -3,7 +3,7 @@
3
3
  const ElasticsearchPlugin = require('../../datadog-plugin-elasticsearch/src')
4
4
 
5
5
  class OpenSearchPlugin extends ElasticsearchPlugin {
6
- static get name () {
6
+ static get id () {
7
7
  return 'opensearch'
8
8
  }
9
9
  }
@@ -1,10 +1,11 @@
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
  const log = require('../../dd-trace/src/log')
5
6
 
6
7
  class OracledbPlugin extends DatabasePlugin {
7
- static get name () { return 'oracledb' }
8
+ static get id () { return 'oracledb' }
8
9
  static get system () { return 'oracle' }
9
10
 
10
11
  start ({ query, connAttrs }) {
@@ -20,7 +21,7 @@ class OracledbPlugin extends DatabasePlugin {
20
21
  'db.user': this.config.user,
21
22
  'db.instance': url.pathname && url.pathname.substring(1),
22
23
  'db.hostname': url.hostname,
23
- 'db.port': url.port
24
+ [CLIENT_PORT_KEY]: url.port
24
25
  }
25
26
  })
26
27
  }
@@ -5,7 +5,7 @@ const PaperplaneLoggerPlugin = require('./logger')
5
5
  const PaperplaneServerPlugin = require('./server')
6
6
 
7
7
  class PaperplanePlugin extends Plugin {
8
- static get name () {
8
+ static get id () {
9
9
  return 'paperplane'
10
10
  }
11
11