dd-trace 3.3.1 → 3.12.1

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 (198) hide show
  1. package/LICENSE-3rdparty.csv +8 -0
  2. package/README.md +108 -43
  3. package/ci/init.js +6 -1
  4. package/ext/exporters.d.ts +2 -1
  5. package/ext/exporters.js +2 -1
  6. package/index.d.ts +129 -36
  7. package/package.json +18 -9
  8. package/packages/datadog-instrumentations/src/body-parser.js +26 -0
  9. package/packages/datadog-instrumentations/src/cassandra-driver.js +7 -7
  10. package/packages/datadog-instrumentations/src/child-process.js +30 -0
  11. package/packages/datadog-instrumentations/src/connect.js +15 -15
  12. package/packages/datadog-instrumentations/src/cucumber.js +1 -3
  13. package/packages/datadog-instrumentations/src/elasticsearch.js +51 -47
  14. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +1 -1
  15. package/packages/datadog-instrumentations/src/helpers/hooks.js +9 -0
  16. package/packages/datadog-instrumentations/src/helpers/register.js +5 -0
  17. package/packages/datadog-instrumentations/src/http/server.js +20 -12
  18. package/packages/datadog-instrumentations/src/http2/server.js +67 -1
  19. package/packages/datadog-instrumentations/src/jest.js +182 -25
  20. package/packages/datadog-instrumentations/src/koa.js +32 -32
  21. package/packages/datadog-instrumentations/src/ldapjs.js +91 -0
  22. package/packages/datadog-instrumentations/src/mariadb.js +63 -0
  23. package/packages/datadog-instrumentations/src/memcached.js +1 -4
  24. package/packages/datadog-instrumentations/src/mocha.js +135 -24
  25. package/packages/datadog-instrumentations/src/next.js +10 -2
  26. package/packages/datadog-instrumentations/src/opensearch.js +10 -0
  27. package/packages/datadog-instrumentations/src/oracledb.js +8 -8
  28. package/packages/datadog-instrumentations/src/pg.js +7 -3
  29. package/packages/datadog-instrumentations/src/qs.js +24 -0
  30. package/packages/datadog-instrumentations/src/redis.js +12 -3
  31. package/packages/datadog-instrumentations/src/restify.js +5 -1
  32. package/packages/datadog-instrumentations/src/rhea.js +29 -15
  33. package/packages/datadog-instrumentations/src/router.js +23 -23
  34. package/packages/datadog-plugin-amqp10/src/consumer.js +32 -0
  35. package/packages/datadog-plugin-amqp10/src/index.js +11 -101
  36. package/packages/datadog-plugin-amqp10/src/producer.js +34 -0
  37. package/packages/datadog-plugin-amqp10/src/util.js +15 -0
  38. package/packages/datadog-plugin-amqplib/src/client.js +38 -0
  39. package/packages/datadog-plugin-amqplib/src/consumer.js +40 -0
  40. package/packages/datadog-plugin-amqplib/src/index.js +14 -102
  41. package/packages/datadog-plugin-amqplib/src/producer.js +37 -0
  42. package/packages/datadog-plugin-amqplib/src/util.js +14 -0
  43. package/packages/datadog-plugin-cassandra-driver/src/index.js +22 -60
  44. package/packages/datadog-plugin-cucumber/src/index.js +14 -33
  45. package/packages/datadog-plugin-cypress/src/plugin.js +2 -1
  46. package/packages/datadog-plugin-dns/src/index.js +16 -91
  47. package/packages/datadog-plugin-dns/src/lookup.js +40 -0
  48. package/packages/datadog-plugin-dns/src/lookup_service.js +24 -0
  49. package/packages/datadog-plugin-dns/src/resolve.js +24 -0
  50. package/packages/datadog-plugin-dns/src/reverse.js +21 -0
  51. package/packages/datadog-plugin-elasticsearch/src/index.js +24 -60
  52. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +24 -0
  53. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +41 -0
  54. package/packages/datadog-plugin-google-cloud-pubsub/src/index.js +14 -99
  55. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +33 -0
  56. package/packages/datadog-plugin-graphql/src/execute.js +73 -0
  57. package/packages/datadog-plugin-graphql/src/index.js +14 -176
  58. package/packages/datadog-plugin-graphql/src/parse.js +32 -0
  59. package/packages/datadog-plugin-graphql/src/resolve.js +70 -76
  60. package/packages/datadog-plugin-graphql/src/validate.js +28 -0
  61. package/packages/datadog-plugin-grpc/src/client.js +46 -55
  62. package/packages/datadog-plugin-grpc/src/index.js +7 -24
  63. package/packages/datadog-plugin-grpc/src/server.js +50 -52
  64. package/packages/datadog-plugin-grpc/src/util.js +15 -14
  65. package/packages/datadog-plugin-http/src/client.js +15 -5
  66. package/packages/datadog-plugin-http/src/index.js +7 -22
  67. package/packages/datadog-plugin-http/src/server.js +19 -3
  68. package/packages/datadog-plugin-http2/src/client.js +20 -1
  69. package/packages/datadog-plugin-http2/src/index.js +8 -26
  70. package/packages/datadog-plugin-http2/src/server.js +44 -0
  71. package/packages/datadog-plugin-jest/src/index.js +41 -65
  72. package/packages/datadog-plugin-kafkajs/src/consumer.js +42 -0
  73. package/packages/datadog-plugin-kafkajs/src/index.js +11 -87
  74. package/packages/datadog-plugin-kafkajs/src/producer.js +31 -0
  75. package/packages/datadog-plugin-mariadb/src/index.js +10 -0
  76. package/packages/datadog-plugin-memcached/src/index.js +17 -52
  77. package/packages/datadog-plugin-mocha/src/index.js +40 -60
  78. package/packages/datadog-plugin-moleculer/src/client.js +22 -36
  79. package/packages/datadog-plugin-moleculer/src/index.js +8 -26
  80. package/packages/datadog-plugin-moleculer/src/server.js +18 -30
  81. package/packages/datadog-plugin-mongodb-core/src/index.js +23 -51
  82. package/packages/datadog-plugin-mysql/src/index.js +23 -52
  83. package/packages/datadog-plugin-mysql2/src/index.js +1 -3
  84. package/packages/datadog-plugin-net/src/index.js +4 -0
  85. package/packages/datadog-plugin-net/src/ipc.js +21 -0
  86. package/packages/datadog-plugin-net/src/tcp.js +46 -0
  87. package/packages/datadog-plugin-next/src/index.js +3 -0
  88. package/packages/datadog-plugin-opensearch/src/index.js +11 -0
  89. package/packages/datadog-plugin-oracledb/src/index.js +29 -55
  90. package/packages/datadog-plugin-pg/src/index.js +27 -51
  91. package/packages/datadog-plugin-redis/src/index.js +29 -60
  92. package/packages/datadog-plugin-rhea/src/consumer.js +55 -0
  93. package/packages/datadog-plugin-rhea/src/index.js +11 -96
  94. package/packages/datadog-plugin-rhea/src/producer.js +45 -0
  95. package/packages/datadog-plugin-router/src/index.js +13 -2
  96. package/packages/datadog-plugin-sharedb/src/index.js +22 -39
  97. package/packages/datadog-plugin-tedious/src/index.js +20 -41
  98. package/packages/dd-trace/src/appsec/addresses.js +3 -1
  99. package/packages/dd-trace/src/appsec/blocking.js +44 -0
  100. package/packages/dd-trace/src/appsec/callbacks/ddwaf.js +8 -6
  101. package/packages/dd-trace/src/appsec/gateway/engine/engine.js +1 -1
  102. package/packages/dd-trace/src/appsec/gateway/engine/index.js +7 -2
  103. package/packages/dd-trace/src/appsec/gateway/engine/runner.js +0 -1
  104. package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +4 -1
  105. package/packages/dd-trace/src/appsec/iast/analyzers/command-injection-analyzer.js +11 -0
  106. package/packages/dd-trace/src/appsec/iast/analyzers/injection-analyzer.js +19 -0
  107. package/packages/dd-trace/src/appsec/iast/analyzers/ldap-injection-analyzer.js +11 -0
  108. package/packages/dd-trace/src/appsec/iast/analyzers/sql-injection-analyzer.js +13 -0
  109. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +43 -5
  110. package/packages/dd-trace/src/appsec/iast/iast-context.js +3 -1
  111. package/packages/dd-trace/src/appsec/iast/index.js +24 -8
  112. package/packages/dd-trace/src/appsec/iast/overhead-controller.js +20 -1
  113. package/packages/dd-trace/src/appsec/iast/path-line.js +17 -6
  114. package/packages/dd-trace/src/appsec/iast/taint-tracking/csi-methods.js +17 -0
  115. package/packages/dd-trace/src/appsec/iast/taint-tracking/filter.js +16 -0
  116. package/packages/dd-trace/src/appsec/iast/taint-tracking/index.js +18 -0
  117. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations.js +98 -0
  118. package/packages/dd-trace/src/appsec/iast/taint-tracking/origin-types.js +4 -0
  119. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +38 -0
  120. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +67 -0
  121. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +103 -0
  122. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +98 -30
  123. package/packages/dd-trace/src/appsec/index.js +79 -25
  124. package/packages/dd-trace/src/{plugins/util → appsec}/ip_blocklist.js +0 -0
  125. package/packages/dd-trace/src/appsec/ip_extractor.js +98 -0
  126. package/packages/dd-trace/src/appsec/recommended.json +134 -53
  127. package/packages/dd-trace/src/appsec/remote_config/capabilities.js +7 -0
  128. package/packages/dd-trace/src/appsec/remote_config/index.js +56 -0
  129. package/packages/dd-trace/src/appsec/remote_config/manager.js +264 -0
  130. package/packages/dd-trace/src/{exporters → appsec/remote_config}/scheduler.js +9 -9
  131. package/packages/dd-trace/src/appsec/rule_manager.js +61 -1
  132. package/packages/dd-trace/src/appsec/templates/blocked.html +99 -0
  133. package/packages/dd-trace/src/appsec/templates/blocked.json +8 -0
  134. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +66 -0
  135. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +9 -5
  136. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +19 -51
  137. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +10 -5
  138. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +202 -0
  139. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +51 -62
  140. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-itr-configuration.js +89 -0
  141. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +82 -0
  142. package/packages/dd-trace/src/config.js +119 -35
  143. package/packages/dd-trace/src/constants.js +9 -1
  144. package/packages/dd-trace/src/dogstatsd.js +42 -10
  145. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +10 -2
  146. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +0 -1
  147. package/packages/dd-trace/src/exporter.js +3 -0
  148. package/packages/dd-trace/src/exporters/agent/index.js +10 -2
  149. package/packages/dd-trace/src/exporters/agent/writer.js +2 -9
  150. package/packages/dd-trace/src/exporters/common/agent-info-exporter.js +82 -0
  151. package/packages/dd-trace/src/exporters/common/request.js +51 -1
  152. package/packages/dd-trace/src/exporters/span-stats/index.js +6 -2
  153. package/packages/dd-trace/src/format.js +29 -10
  154. package/packages/dd-trace/src/lambda/handler.js +72 -0
  155. package/packages/dd-trace/src/lambda/index.js +5 -0
  156. package/packages/dd-trace/src/lambda/runtime/errors.js +20 -0
  157. package/packages/dd-trace/src/lambda/runtime/patch.js +74 -0
  158. package/packages/dd-trace/src/lambda/runtime/ritm.js +138 -0
  159. package/packages/dd-trace/src/metrics.js +15 -2
  160. package/packages/dd-trace/src/opentracing/propagation/text_map.js +1 -5
  161. package/packages/dd-trace/src/opentracing/span.js +2 -1
  162. package/packages/dd-trace/src/opentracing/span_context.js +9 -0
  163. package/packages/dd-trace/src/plugin_manager.js +11 -17
  164. package/packages/dd-trace/src/plugins/cache.js +9 -0
  165. package/packages/dd-trace/src/plugins/ci_plugin.js +97 -0
  166. package/packages/dd-trace/src/plugins/client.js +9 -0
  167. package/packages/dd-trace/src/plugins/composite.js +26 -0
  168. package/packages/dd-trace/src/plugins/consumer.js +9 -0
  169. package/packages/dd-trace/src/plugins/database.js +55 -0
  170. package/packages/dd-trace/src/plugins/incoming.js +7 -0
  171. package/packages/dd-trace/src/plugins/index.js +3 -0
  172. package/packages/dd-trace/src/plugins/log_plugin.js +2 -2
  173. package/packages/dd-trace/src/plugins/outgoing.js +31 -0
  174. package/packages/dd-trace/src/plugins/plugin.js +3 -0
  175. package/packages/dd-trace/src/plugins/producer.js +9 -0
  176. package/packages/dd-trace/src/plugins/server.js +9 -0
  177. package/packages/dd-trace/src/plugins/storage.js +21 -0
  178. package/packages/dd-trace/src/plugins/tracing.js +94 -0
  179. package/packages/dd-trace/src/plugins/util/ci.js +40 -4
  180. package/packages/dd-trace/src/plugins/util/git.js +58 -18
  181. package/packages/dd-trace/src/plugins/util/test.js +71 -8
  182. package/packages/dd-trace/src/plugins/util/user-provided-git.js +14 -1
  183. package/packages/dd-trace/src/plugins/util/web.js +11 -114
  184. package/packages/dd-trace/src/priority_sampler.js +6 -2
  185. package/packages/dd-trace/src/profiling/config.js +11 -6
  186. package/packages/dd-trace/src/profiling/exporters/agent.js +4 -0
  187. package/packages/dd-trace/src/profiling/index.js +2 -2
  188. package/packages/dd-trace/src/profiling/profiler.js +43 -7
  189. package/packages/dd-trace/src/proxy.js +8 -16
  190. package/packages/dd-trace/src/ritm.js +25 -14
  191. package/packages/dd-trace/src/span_processor.js +17 -0
  192. package/packages/dd-trace/src/span_sampler.js +77 -0
  193. package/packages/dd-trace/src/span_stats.js +2 -2
  194. package/packages/dd-trace/src/telemetry/dependencies.js +21 -7
  195. package/packages/dd-trace/src/telemetry/index.js +7 -1
  196. package/packages/dd-trace/src/telemetry/send-data.js +3 -1
  197. package/packages/dd-trace/src/tracer.js +10 -5
  198. package/packages/dd-trace/src/util.js +43 -1
@@ -1,49 +1,35 @@
1
1
  'use strict'
2
2
 
3
- const { storage } = require('../../datadog-core')
4
- const Plugin = require('../../dd-trace/src/plugins/plugin')
3
+ const ClientPlugin = require('../../dd-trace/src/plugins/client')
5
4
  const { moleculerTags } = require('./util')
6
5
 
7
- class MoleculerClientPlugin extends Plugin {
8
- constructor (...args) {
9
- super(...args)
10
-
11
- this.addSub('apm:moleculer:call:start', ({ actionName, params, opts }) => {
12
- const store = storage.getStore()
13
- const childOf = store && store.span
14
- const span = this.tracer.startSpan('moleculer.call', {
15
- childOf,
16
- tags: {
17
- 'service.name': this.config.service || this.tracer._service,
18
- 'span.kind': 'client',
19
- 'resource.name': actionName
20
- }
21
- })
22
-
23
- this.tracer.inject(span, 'text_map', opts.meta)
24
-
25
- this.enter(span, store)
6
+ class MoleculerClientPlugin extends ClientPlugin {
7
+ static get name () { return 'moleculer' }
8
+ static get operation () { return 'call' }
9
+
10
+ start ({ actionName, opts }) {
11
+ const span = this.startSpan('moleculer.call', {
12
+ service: this.config.service,
13
+ resource: actionName,
14
+ kind: 'client'
26
15
  })
27
16
 
28
- this.addSub('apm:moleculer:call:finish', ({ broker, ctx }) => {
29
- const store = storage.getStore()
30
- const span = store.span
17
+ this.tracer.inject(span, 'text_map', opts.meta)
18
+ }
19
+
20
+ finish ({ broker, ctx }) {
21
+ const span = this.activeSpan
31
22
 
32
- if (ctx) {
33
- const endpoint = ctx.endpoint || {}
34
- const node = endpoint.node || {}
23
+ if (ctx) {
24
+ const endpoint = ctx.endpoint || {}
25
+ const node = endpoint.node || {}
35
26
 
36
- span.addTags({
37
- 'out.host': node.hostname,
38
- 'out.port': node.port,
39
- ...moleculerTags(broker, ctx, this.config)
40
- })
41
- }
27
+ this.addHost(node.hostname, node.port)
42
28
 
43
- span.finish()
44
- })
29
+ span.addTags(moleculerTags(broker, ctx, this.config))
30
+ }
45
31
 
46
- this.addSub('apm:moleculer:call:error', this.addError)
32
+ span.finish()
47
33
  }
48
34
  }
49
35
 
@@ -2,35 +2,17 @@
2
2
 
3
3
  // TODO: support https://moleculer.services/docs/0.13/actions.html#Streaming
4
4
 
5
- const Plugin = require('../../dd-trace/src/plugins/plugin')
6
5
  const MoleculerServerPlugin = require('./server')
7
6
  const MoleculerClientPlugin = require('./client')
8
-
9
- class MoleculerPlugin extends Plugin {
10
- static get name () {
11
- return 'moleculer'
12
- }
13
-
14
- constructor (...args) {
15
- super(...args)
16
-
17
- this.server = new MoleculerServerPlugin(...args)
18
- this.client = new MoleculerClientPlugin(...args)
19
- }
20
-
21
- configure (config) {
22
- const clientConfig = config.client === false ? false : {
23
- ...config,
24
- ...config.client
25
- }
26
-
27
- const serverConfig = config.server === false ? false : {
28
- ...config,
29
- ...config.server
7
+ const CompositePlugin = require('../../dd-trace/src/plugins/composite')
8
+
9
+ class MoleculerPlugin extends CompositePlugin {
10
+ static get name () { return 'moleculer' }
11
+ static get plugins () {
12
+ return {
13
+ server: MoleculerServerPlugin,
14
+ client: MoleculerClientPlugin
30
15
  }
31
-
32
- this.server.configure(serverConfig)
33
- this.client.configure(clientConfig)
34
16
  }
35
17
  }
36
18
 
@@ -1,38 +1,26 @@
1
1
  'use strict'
2
2
 
3
- const { storage } = require('../../datadog-core')
4
- const Plugin = require('../../dd-trace/src/plugins/plugin')
3
+ const ServerPlugin = require('../../dd-trace/src/plugins/server')
5
4
  const { moleculerTags } = require('./util')
6
5
 
7
- class MoleculerServerPlugin extends Plugin {
8
- constructor (...args) {
9
- super(...args)
10
-
11
- this.addSub('apm:moleculer:action:start', ({ action, ctx, broker }) => {
12
- const store = storage.getStore()
13
- const followsFrom = this.tracer.extract('text_map', ctx.meta)
14
- const span = this.tracer.startSpan('moleculer.action', {
15
- childOf: followsFrom || (store && store.span),
16
- tags: {
17
- 'service.name': this.config.service || this.tracer._service,
18
- 'span.type': 'web',
19
- 'span.kind': 'server',
20
- 'resource.name': action.name,
21
- ...moleculerTags(broker, ctx, this.config)
22
- }
23
- })
24
-
25
- this.enter(span, store)
26
- })
27
-
28
- this.addSub('apm:moleculer:action:finish', () => {
29
- const store = storage.getStore()
30
- const span = store.span
31
-
32
- span.finish()
6
+ class MoleculerServerPlugin extends ServerPlugin {
7
+ static get name () { return 'moleculer' }
8
+ static get operation () { return 'action' }
9
+
10
+ start ({ action, ctx, broker }) {
11
+ const followsFrom = this.tracer.extract('text_map', ctx.meta)
12
+
13
+ this.startSpan('moleculer.action', {
14
+ childOf: followsFrom || this.activeSpan,
15
+ service: this.config.service,
16
+ resource: action.name,
17
+ kind: 'server',
18
+ type: 'web',
19
+ meta: {
20
+ 'resource.name': action.name,
21
+ ...moleculerTags(broker, ctx, this.config)
22
+ }
33
23
  })
34
-
35
- this.addSub('apm:moleculer:action:error', this.addError)
36
24
  }
37
25
  }
38
26
 
@@ -1,54 +1,26 @@
1
1
  'use strict'
2
2
 
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
-
7
- class MongodbCorePlugin extends Plugin {
8
- static get name () {
9
- return 'mongodb-core'
10
- }
11
-
12
- constructor (...args) {
13
- super(...args)
14
-
15
- this.addSub(`apm:mongodb:query:start`, ({ ns, ops, options, name }) => {
16
- const query = getQuery(ops)
17
- const resource = truncate(getResource(ns, query, name))
18
- const store = storage.getStore()
19
- const childOf = store ? store.span : store
20
- const span = this.tracer.startSpan('mongodb.query', {
21
- childOf,
22
- tags: {
23
- 'service.name': this.config.service || `${this.tracer._service}-mongodb`,
24
- 'resource.name': resource,
25
- 'span.type': 'mongodb',
26
- 'span.kind': 'client',
27
- 'db.name': ns
28
- }
29
- })
30
-
31
- if (query) {
32
- span.setTag('mongodb.query', query)
33
- }
34
-
35
- if (options && options.host && options.port) {
36
- span.addTags({
37
- 'out.host': options.host,
38
- 'out.port': options.port
39
- })
3
+ const DatabasePlugin = require('../../dd-trace/src/plugins/database')
4
+
5
+ class MongodbCorePlugin extends DatabasePlugin {
6
+ static get name () { return 'mongodb-core' }
7
+ static get component () { return 'mongodb' }
8
+
9
+ start ({ ns, ops, options = {}, name }) {
10
+ const query = getQuery(ops)
11
+ const resource = truncate(getResource(this, ns, query, name))
12
+
13
+ this.startSpan('mongodb.query', {
14
+ service: this.config.service,
15
+ resource,
16
+ type: 'mongodb',
17
+ kind: 'client',
18
+ meta: {
19
+ 'db.name': ns,
20
+ 'mongodb.query': query,
21
+ 'out.host': options.host,
22
+ 'out.port': options.port
40
23
  }
41
-
42
- analyticsSampler.sample(span, this.config.measured)
43
- this.enter(span, store)
44
- })
45
-
46
- this.addSub(`apm:mongodb:query:error`, err => {
47
- storage.getStore().span.setTag('error', err)
48
- })
49
-
50
- this.addSub(`apm:mongodb:query:finish`, () => {
51
- storage.getStore().span.finish()
52
24
  })
53
25
  }
54
26
  }
@@ -59,10 +31,10 @@ function getQuery (cmd) {
59
31
  if (cmd.filter) return JSON.stringify(limitDepth(cmd.filter))
60
32
  }
61
33
 
62
- function getResource (ns, query, operationName) {
34
+ function getResource (plugin, ns, query, operationName) {
63
35
  const parts = [operationName, ns]
64
36
 
65
- if (query) {
37
+ if (plugin.config.queryInResourceName && query) {
66
38
  parts.push(query)
67
39
  }
68
40
 
@@ -107,7 +79,7 @@ function limitDepth (input) {
107
79
  let child = input[key]
108
80
 
109
81
  if (isBSON(child)) {
110
- child = child.toJSON()
82
+ child = typeof child.toJSON === 'function' ? child.toJSON() : '?'
111
83
  }
112
84
 
113
85
  if (depth >= 10 || shouldHide(child)) {
@@ -1,65 +1,36 @@
1
1
  'use strict'
2
2
 
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
-
7
- class MySQLPlugin extends Plugin {
8
- static get name () {
9
- return 'mysql'
10
- }
11
-
12
- constructor (...args) {
13
- super(...args)
14
-
15
- this.addSub(`apm:${this.constructor.name}:query:start`, ({ sql, conf: dbConfig }) => {
16
- const service = getServiceName(this.tracer, this.config, dbConfig)
17
- const store = storage.getStore()
18
- const childOf = store ? store.span : store
19
- const span = this.tracer.startSpan('mysql.query', {
20
- childOf,
21
- tags: {
22
- 'service.name': service,
23
- 'span.type': 'sql',
24
- 'span.kind': 'client',
25
- 'db.type': 'mysql',
26
- 'db.user': dbConfig.user,
27
- 'out.host': dbConfig.host,
28
- 'out.port': dbConfig.port,
29
- 'resource.name': sql
30
- }
31
- })
32
-
33
- if (dbConfig.database) {
34
- span.setTag('db.name', dbConfig.database)
35
- }
36
-
37
- analyticsSampler.sample(span, this.config.measured)
38
- this.enter(span, store)
39
- })
40
-
41
- this.addSub(`apm:${this.constructor.name}:query:error`, err => {
42
- if (err) {
43
- const span = storage.getStore().span
44
- span.setTag('error', err)
3
+ const DatabasePlugin = require('../../dd-trace/src/plugins/database')
4
+
5
+ class MySQLPlugin extends DatabasePlugin {
6
+ static get name () { return 'mysql' }
7
+ static get system () { return 'mysql' }
8
+
9
+ start ({ sql, conf: dbConfig }) {
10
+ const service = getServiceName(this.config, dbConfig)
11
+
12
+ this.startSpan(`${this.system}.query`, {
13
+ service,
14
+ resource: sql,
15
+ type: 'sql',
16
+ kind: 'client',
17
+ meta: {
18
+ 'db.type': this.system,
19
+ 'db.user': dbConfig.user,
20
+ 'db.name': dbConfig.database,
21
+ 'out.host': dbConfig.host,
22
+ 'out.port': dbConfig.port
45
23
  }
46
24
  })
47
-
48
- this.addSub(`apm:${this.constructor.name}:query:finish`, () => {
49
- const span = storage.getStore().span
50
- span.finish()
51
- })
52
25
  }
53
26
  }
54
27
 
55
- function getServiceName (tracer, config, dbConfig) {
28
+ function getServiceName (config, dbConfig) {
56
29
  if (typeof config.service === 'function') {
57
30
  return config.service(dbConfig)
58
- } else if (config.service) {
59
- return config.service
60
- } else {
61
- return `${tracer._service}-mysql`
62
31
  }
32
+
33
+ return config.service
63
34
  }
64
35
 
65
36
  module.exports = MySQLPlugin
@@ -3,9 +3,7 @@
3
3
  const MySQLPlugin = require('../../datadog-plugin-mysql/src')
4
4
 
5
5
  class MySQL2Plugin extends MySQLPlugin {
6
- static get name () {
7
- return 'mysql2'
8
- }
6
+ static get name () { return 'mysql2' }
9
7
  }
10
8
 
11
9
  module.exports = MySQL2Plugin
@@ -3,6 +3,7 @@
3
3
  const Plugin = require('../../dd-trace/src/plugins/plugin')
4
4
  const { storage } = require('../../datadog-core')
5
5
  const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
6
+ const { COMPONENT } = require('../../dd-trace/src/constants')
6
7
 
7
8
  class NetPlugin extends Plugin {
8
9
  static get name () {
@@ -19,6 +20,7 @@ class NetPlugin extends Plugin {
19
20
  const span = this.tracer.startSpan('ipc.connect', {
20
21
  childOf,
21
22
  tags: {
23
+ [COMPONENT]: this.constructor.name,
22
24
  'resource.name': options.path,
23
25
  'ipc.path': options.path,
24
26
  'span.kind': 'client',
@@ -45,6 +47,7 @@ class NetPlugin extends Plugin {
45
47
  const span = this.tracer.startSpan('tcp.connect', {
46
48
  childOf,
47
49
  tags: {
50
+ [COMPONENT]: this.constructor.name,
48
51
  'resource.name': [host, port].filter(val => val).join(':'),
49
52
  'tcp.remote.host': host,
50
53
  'tcp.remote.port': port,
@@ -67,6 +70,7 @@ class NetPlugin extends Plugin {
67
70
  this.addSub(`apm:net:tcp:connection`, ({ socket }) => {
68
71
  const span = storage.getStore().span
69
72
  span.addTags({
73
+ [COMPONENT]: this.constructor.name,
70
74
  'tcp.local.address': socket.localAddress,
71
75
  'tcp.local.port': socket.localPort
72
76
  })
@@ -0,0 +1,21 @@
1
+ 'use strict'
2
+
3
+ const ClientPlugin = require('../../dd-trace/src/plugins/client')
4
+
5
+ class NetIPCPlugin extends ClientPlugin {
6
+ static get name () { return 'net' }
7
+ static get operation () { return 'ipc' }
8
+
9
+ start ({ options }) {
10
+ this.startSpan('ipc.connect', {
11
+ service: this.config.service,
12
+ resource: options.path,
13
+ kind: 'client',
14
+ meta: {
15
+ 'ipc.path': options.path
16
+ }
17
+ })
18
+ }
19
+ }
20
+
21
+ module.exports = NetIPCPlugin
@@ -0,0 +1,46 @@
1
+ 'use strict'
2
+
3
+ const ClientPlugin = require('../../dd-trace/src/plugins/client')
4
+
5
+ class NetTCPPlugin extends ClientPlugin {
6
+ static get name () { return 'net' }
7
+ static get operation () { return 'tcp' }
8
+
9
+ constructor (...args) {
10
+ super(...args)
11
+
12
+ this.addTraceSub('connection', ({ socket }) => {
13
+ const span = this.activeSpan
14
+
15
+ span.addTags({
16
+ 'tcp.local.address': socket.localAddress,
17
+ 'tcp.local.port': socket.localPort
18
+ })
19
+ })
20
+ }
21
+
22
+ start ({ options }) {
23
+ const host = options.host || 'localhost'
24
+ const port = options.port || 0
25
+ const family = options.family || 4
26
+
27
+ this.startSpan('tcp.connect', {
28
+ service: this.config.service,
29
+ resource: [host, port].filter(val => val).join(':'),
30
+ kind: 'client',
31
+ meta: {
32
+ 'tcp.remote.host': host,
33
+ 'tcp.family': `IPv${family}`,
34
+ 'tcp.local.address': '',
35
+ 'out.host': host
36
+ },
37
+ metrics: {
38
+ 'tcp.remote.port': port,
39
+ 'tcp.local.port': 0,
40
+ 'out.port': port
41
+ }
42
+ })
43
+ }
44
+ }
45
+
46
+ module.exports = NetTCPPlugin
@@ -3,6 +3,7 @@
3
3
  const Plugin = require('../../dd-trace/src/plugins/plugin')
4
4
  const { storage } = require('../../datadog-core')
5
5
  const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
6
+ const { COMPONENT } = require('../../dd-trace/src/constants')
6
7
 
7
8
  class NextPlugin extends Plugin {
8
9
  static get name () {
@@ -20,6 +21,7 @@ class NextPlugin extends Plugin {
20
21
  const span = this.tracer.startSpan('next.request', {
21
22
  childOf,
22
23
  tags: {
24
+ [COMPONENT]: this.constructor.name,
23
25
  'service.name': this.config.service || this.tracer._service,
24
26
  'resource.name': req.method,
25
27
  'span.type': 'web',
@@ -67,6 +69,7 @@ class NextPlugin extends Plugin {
67
69
  const req = this._requests.get(span)
68
70
 
69
71
  span.addTags({
72
+ [COMPONENT]: this.constructor.name,
70
73
  'resource.name': `${req.method} ${page}`.trim(),
71
74
  'next.page': page
72
75
  })
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+
3
+ const ElasticsearchPlugin = require('../../datadog-plugin-elasticsearch/src')
4
+
5
+ class OpenSearchPlugin extends ElasticsearchPlugin {
6
+ static get name () {
7
+ return 'opensearch'
8
+ }
9
+ }
10
+
11
+ module.exports = OpenSearchPlugin
@@ -1,72 +1,46 @@
1
1
  'use strict'
2
2
 
3
- const Plugin = require('../../dd-trace/src/plugins/plugin')
4
- const { storage } = require('../../datadog-core')
5
- const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
3
+ const DatabasePlugin = require('../../dd-trace/src/plugins/database')
6
4
  const log = require('../../dd-trace/src/log')
7
5
 
8
- class OracledbPlugin extends Plugin {
9
- static get name () {
10
- return 'oracledb'
11
- }
6
+ class OracledbPlugin extends DatabasePlugin {
7
+ static get name () { return 'oracledb' }
8
+ static get system () { return 'oracle' }
12
9
 
13
- constructor (...args) {
14
- super(...args)
10
+ start ({ query, connAttrs }) {
11
+ const service = getServiceName(this.config, connAttrs)
12
+ const url = getUrl(connAttrs.connectString)
15
13
 
16
- this.addSub('apm:oracledb:execute:start', ({ query, connAttrs }) => {
17
- const service = getServiceName(this.tracer, this.config, connAttrs)
18
- let connectStringObj
19
- try {
20
- connectStringObj = new URL(`http://${connAttrs.connectString}`)
21
- } catch (e) {
22
- log.error(e)
23
- }
24
- const tags = {
25
- 'span.kind': 'client',
26
- 'span.type': 'sql',
27
- 'sql.query': query,
14
+ this.startSpan('oracle.query', {
15
+ service,
16
+ resource: query,
17
+ type: 'sql',
18
+ kind: 'client',
19
+ meta: {
28
20
  'db.user': this.config.user,
29
- 'resource.name': query,
30
- 'service.name': service
31
- }
32
- if (typeof connectStringObj !== 'undefined') {
33
- tags['db.instance'] = connectStringObj.pathname.substring(1)
34
- tags['db.hostname'] = connectStringObj.hostname
35
- tags['db.port'] = connectStringObj.port
36
- }
37
- const store = storage.getStore()
38
- const childOf = store ? store.span : store
39
- const span = this.tracer.startSpan('oracle.query', {
40
- childOf,
41
- tags
42
- })
43
- analyticsSampler.sample(span, this.config.measured)
44
- this.enter(span, store)
45
- })
46
-
47
- this.addSub('apm:oracledb:execute:error', err => {
48
- const store = storage.getStore()
49
- if (store && store.span) {
50
- store.span.setTag('error', err)
51
- }
52
- })
53
-
54
- this.addSub('apm:oracledb:execute:finish', () => {
55
- const store = storage.getStore()
56
- if (store && store.span) {
57
- store.span.finish()
21
+ 'db.instance': url.pathname && url.pathname.substring(1),
22
+ 'db.hostname': url.hostname,
23
+ 'db.port': url.port
58
24
  }
59
25
  })
60
26
  }
61
27
  }
62
28
 
63
- function getServiceName (tracer, config, connAttrs) {
29
+ function getServiceName (config, connAttrs) {
64
30
  if (typeof config.service === 'function') {
65
31
  return config.service(connAttrs)
66
- } else if (config.service) {
67
- return config.service
68
- } else {
69
- return `${tracer._service}-oracle`
32
+ }
33
+
34
+ return config.service
35
+ }
36
+
37
+ // TODO: Avoid creating an error since it's a heavy operation.
38
+ function getUrl (connectString) {
39
+ try {
40
+ return new URL(`http://${connectString}`)
41
+ } catch (e) {
42
+ log.error(e)
43
+ return {}
70
44
  }
71
45
  }
72
46