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,72 +1,63 @@
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
- const Tags = require('../../../ext/tags')
3
+ const ClientPlugin = require('../../dd-trace/src/plugins/client')
7
4
  const { TEXT_MAP } = require('../../../ext/formats')
8
- const { addMethodTags, addMetadataTags, getFilter } = require('./util')
9
-
10
- class GrpcClientPlugin extends Plugin {
11
- static get name () {
12
- return 'grpc'
13
- }
14
-
15
- constructor (...args) {
16
- super(...args)
17
-
18
- this.addSub('apm:grpc:client:request:start', ({ metadata, path, type }) => {
19
- const metadataFilter = this.config.metadataFilter
20
- const store = storage.getStore()
21
- const childOf = store && store.span
22
- const span = this.tracer.startSpan('grpc.client', {
23
- childOf,
24
- tags: {
25
- [Tags.SPAN_KIND]: 'client',
26
- 'span.type': 'http',
27
- 'resource.name': path,
28
- 'service.name': this.config.service || this.tracer._service,
29
- 'component': 'grpc'
30
- }
31
- })
32
-
33
- addMethodTags(span, path, type)
34
-
35
- if (metadata) {
36
- addMetadataTags(span, metadata, metadataFilter, 'request')
37
- inject(this.tracer, span, metadata)
5
+ const { addMetadataTags, getFilter, getMethodMetadata } = require('./util')
6
+
7
+ class GrpcClientPlugin extends ClientPlugin {
8
+ static get name () { return 'grpc' }
9
+ static get operation () { return 'client:request' }
10
+
11
+ start ({ metadata, path, type }) {
12
+ const metadataFilter = this.config.metadataFilter
13
+ const method = getMethodMetadata(path, type)
14
+ const span = this.startSpan('grpc.client', {
15
+ service: this.config.service,
16
+ resource: path,
17
+ kind: 'client',
18
+ type: 'http',
19
+ meta: {
20
+ 'component': 'grpc',
21
+ 'grpc.method.kind': method.kind,
22
+ 'grpc.method.path': method.path,
23
+ 'grpc.method.name': method.name,
24
+ 'grpc.method.service': method.service,
25
+ 'grpc.method.package': method.package
26
+ },
27
+ metrics: {
28
+ 'grpc.status.code': 0
38
29
  }
39
-
40
- analyticsSampler.sample(span, this.config.measured)
41
-
42
- this.enter(span, store)
43
30
  })
44
31
 
45
- this.addSub('apm:grpc:client:request:error', error => {
46
- const store = storage.getStore()
32
+ if (metadata) {
33
+ addMetadataTags(span, metadata, metadataFilter, 'request')
34
+ inject(this.tracer, span, metadata)
35
+ }
36
+ }
47
37
 
48
- if (!store || !store.span) return
38
+ error (error) {
39
+ const span = this.activeSpan
49
40
 
50
- this.addCode(store.span, error.code)
51
- this.addError(error)
52
- })
41
+ if (!span) return
53
42
 
54
- this.addSub('apm:grpc:client:request:finish', ({ code, metadata }) => {
55
- const store = storage.getStore()
43
+ this.addCode(span, error.code)
44
+ this.addError(error)
45
+ }
56
46
 
57
- if (!store || !store.span) return
47
+ finish ({ code, metadata }) {
48
+ const span = this.activeSpan
58
49
 
59
- const span = store.span
60
- const metadataFilter = this.config.metadataFilter
50
+ if (!span) return
61
51
 
62
- this.addCode(span, code)
52
+ const metadataFilter = this.config.metadataFilter
63
53
 
64
- if (metadata && metadataFilter) {
65
- addMetadataTags(span, metadata, metadataFilter, 'response')
66
- }
54
+ this.addCode(span, code)
67
55
 
68
- store.span.finish()
69
- })
56
+ if (metadata && metadataFilter) {
57
+ addMetadataTags(span, metadata, metadataFilter, 'response')
58
+ }
59
+
60
+ span.finish()
70
61
  }
71
62
 
72
63
  configure (config) {
@@ -1,33 +1,16 @@
1
1
  'use strict'
2
2
 
3
- const Plugin = require('../../dd-trace/src/plugins/plugin')
4
3
  const GrpcServerPlugin = require('./server')
5
4
  const GrpcClientPlugin = require('./client')
5
+ const CompositePlugin = require('../../dd-trace/src/plugins/composite')
6
6
 
7
- class GrpcPlugin extends Plugin {
8
- static get name () {
9
- return 'grpc'
10
- }
11
-
12
- constructor (...args) {
13
- super(...args)
14
- this.server = new GrpcServerPlugin(...args)
15
- this.client = new GrpcClientPlugin(...args)
16
- }
17
-
18
- configure (config) {
19
- const clientConfig = config.client === false ? false : {
20
- ...config,
21
- ...config.client
7
+ class GrpcPlugin extends CompositePlugin {
8
+ static get name () { return 'grpc' }
9
+ static get plugins () {
10
+ return {
11
+ server: GrpcServerPlugin,
12
+ client: GrpcClientPlugin
22
13
  }
23
-
24
- const serverConfig = config.server === false ? false : {
25
- ...config,
26
- ...config.server
27
- }
28
-
29
- this.server.configure(serverConfig)
30
- this.client.configure(clientConfig)
31
14
  }
32
15
  }
33
16
 
@@ -1,76 +1,74 @@
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
- const Tags = require('../../../ext/tags')
3
+ const ServerPlugin = require('../../dd-trace/src/plugins/server')
7
4
  const { TEXT_MAP } = require('../../../ext/formats')
8
- const { addMethodTags, addMetadataTags, getFilter } = require('./util')
5
+ const { addMetadataTags, getFilter, getMethodMetadata } = require('./util')
9
6
 
10
- class GrpcServerPlugin extends Plugin {
11
- static get name () {
12
- return 'http'
13
- }
7
+ class GrpcServerPlugin extends ServerPlugin {
8
+ static get name () { return 'grpc' }
9
+ static get operation () { return 'server:request' }
14
10
 
15
11
  constructor (...args) {
16
12
  super(...args)
17
13
 
18
- this.addSub('apm:grpc:server:request:start', ({ name, metadata, type }) => {
19
- const metadataFilter = this.config.metadataFilter
20
- const store = storage.getStore()
21
- const childOf = extract(this.tracer, metadata)
22
- const span = this.tracer.startSpan('grpc.server', {
23
- childOf,
24
- tags: {
25
- [Tags.SPAN_KIND]: 'server',
26
- 'span.type': 'web',
27
- 'resource.name': name,
28
- 'service.name': this.config.service || this.tracer._service,
29
- 'component': 'grpc'
30
- }
31
- })
32
-
33
- addMethodTags(span, name, type)
34
- addMetadataTags(span, metadata, metadataFilter, 'request')
35
-
36
- analyticsSampler.sample(span, this.config.measured, true)
37
-
38
- this.enter(span, store)
39
- })
14
+ this.addTraceSub('update', ({ code }) => {
15
+ const span = this.activeSpan
40
16
 
41
- this.addSub('apm:grpc:server:request:error', error => {
42
- const store = storage.getStore()
17
+ if (!span) return
43
18
 
44
- if (!store || !store.span) return
19
+ this.addCode(span, code)
20
+ })
21
+ }
45
22
 
46
- this.addCode(store.span, error.code)
47
- this.addError(error)
23
+ start ({ name, metadata, type }) {
24
+ const metadataFilter = this.config.metadataFilter
25
+ const childOf = extract(this.tracer, metadata)
26
+ const method = getMethodMetadata(name, type)
27
+ const span = this.startSpan('grpc.server', {
28
+ childOf,
29
+ service: this.config.service,
30
+ resource: name,
31
+ kind: 'server',
32
+ type: 'web',
33
+ meta: {
34
+ 'component': 'grpc',
35
+ 'grpc.method.kind': method.kind,
36
+ 'grpc.method.path': method.path,
37
+ 'grpc.method.name': method.name,
38
+ 'grpc.method.service': method.service,
39
+ 'grpc.method.package': method.package
40
+ },
41
+ metrics: {
42
+ 'grpc.status.code': 0
43
+ }
48
44
  })
49
45
 
50
- this.addSub('apm:grpc:server:request:update', ({ code }) => {
51
- const store = storage.getStore()
46
+ addMetadataTags(span, metadata, metadataFilter, 'request')
47
+ }
48
+
49
+ error (error) {
50
+ const span = this.activeSpan
52
51
 
53
- if (!store || !store.span) return
52
+ if (!span) return
54
53
 
55
- this.addCode(store.span, code)
56
- })
54
+ this.addCode(span, error.code)
55
+ this.addError(error)
56
+ }
57
57
 
58
- this.addSub('apm:grpc:server:request:finish', ({ code, trailer } = {}) => {
59
- const store = storage.getStore()
58
+ finish ({ code, trailer } = {}) {
59
+ const span = this.activeSpan
60
60
 
61
- if (!store || !store.span) return
61
+ if (!span) return
62
62
 
63
- const span = store.span
64
- const metadataFilter = this.config.metadataFilter
63
+ const metadataFilter = this.config.metadataFilter
65
64
 
66
- this.addCode(span, code)
65
+ this.addCode(span, code)
67
66
 
68
- if (trailer && metadataFilter) {
69
- addMetadataTags(span, trailer, metadataFilter, 'response')
70
- }
67
+ if (trailer && metadataFilter) {
68
+ addMetadataTags(span, trailer, metadataFilter, 'response')
69
+ }
71
70
 
72
- store.span.finish()
73
- })
71
+ span.finish()
74
72
  }
75
73
 
76
74
  configure (config) {
@@ -4,13 +4,16 @@ const pick = require('lodash.pick')
4
4
  const log = require('../../dd-trace/src/log')
5
5
 
6
6
  module.exports = {
7
- addMethodTags (span, path, kind) {
8
- if (typeof path !== 'string') return
7
+ getMethodMetadata (path, kind) {
8
+ const tags = {
9
+ path,
10
+ kind,
11
+ name: '',
12
+ service: '',
13
+ package: ''
14
+ }
9
15
 
10
- span.addTags({
11
- 'grpc.method.path': path,
12
- 'grpc.method.kind': kind
13
- })
16
+ if (typeof path !== 'string') return tags
14
17
 
15
18
  const methodParts = path.split('/')
16
19
 
@@ -20,16 +23,14 @@ module.exports = {
20
23
  const service = serviceParts.pop()
21
24
  const pkg = serviceParts.join('.')
22
25
 
23
- span.addTags({
24
- 'grpc.method.name': name,
25
- 'grpc.method.service': service,
26
- 'grpc.method.package': pkg
27
- })
26
+ tags.name = name
27
+ tags.service = service
28
+ tags.package = pkg
28
29
  } else {
29
- span.addTags({
30
- 'grpc.method.name': methodParts[methodParts.length - 1]
31
- })
30
+ tags.name = methodParts[methodParts.length - 1]
32
31
  }
32
+
33
+ return tags
33
34
  },
34
35
 
35
36
  addMetadataTags (span, metadata, filter, type) {
@@ -9,6 +9,7 @@ const HTTP_HEADERS = formats.HTTP_HEADERS
9
9
  const urlFilter = require('../../dd-trace/src/plugins/util/urlfilter')
10
10
  const log = require('../../dd-trace/src/log')
11
11
  const url = require('url')
12
+ const { COMPONENT, ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')
12
13
 
13
14
  const HTTP_STATUS_CODE = tags.HTTP_STATUS_CODE
14
15
  const HTTP_REQUEST_HEADERS = tags.HTTP_REQUEST_HEADERS
@@ -31,12 +32,14 @@ class HttpClientPlugin extends Plugin {
31
32
  const host = options.port ? `${hostname}:${options.port}` : hostname
32
33
  const path = options.path ? options.path.split(/[?#]/)[0] : '/'
33
34
  const uri = `${protocol}//${host}${path}`
35
+ const allowed = this.config.filter(uri)
34
36
 
35
37
  const method = (options.method || 'GET').toUpperCase()
36
- const childOf = store ? store.span : store
38
+ const childOf = store && allowed ? store.span : null
37
39
  const span = this.tracer.startSpan('http.request', {
38
40
  childOf,
39
41
  tags: {
42
+ [COMPONENT]: this.constructor.name,
40
43
  'span.kind': 'client',
41
44
  'service.name': getServiceName(this.tracer, this.config, options),
42
45
  'resource.name': method,
@@ -46,6 +49,11 @@ class HttpClientPlugin extends Plugin {
46
49
  }
47
50
  })
48
51
 
52
+ // TODO: Figure out a better way to do this for any span.
53
+ if (!allowed) {
54
+ span._spanContext._trace.record = false
55
+ }
56
+
49
57
  if (!(hasAmazonSignature(options) || !this.config.propagationFilter(uri))) {
50
58
  this.tracer.inject(span, HTTP_HEADERS, options.headers)
51
59
  }
@@ -85,9 +93,9 @@ function errorHandler (err) {
85
93
 
86
94
  if (err) {
87
95
  span.addTags({
88
- 'error.type': err.name,
89
- 'error.msg': err.message,
90
- 'error.stack': err.stack
96
+ [ERROR_TYPE]: err.name,
97
+ [ERROR_MESSAGE]: err.message,
98
+ [ERROR_STACK]: err.stack
91
99
  })
92
100
  } else {
93
101
  span.setTag('error', 1)
@@ -109,19 +117,21 @@ function addRequestHeaders (req, span, config) {
109
117
  const value = req.getHeader(key)
110
118
 
111
119
  if (value) {
112
- span.setTag(`${HTTP_REQUEST_HEADERS}.${key}`, value)
120
+ span.setTag(`${HTTP_REQUEST_HEADERS}.${key}`, Array.isArray(value) ? value.toString() : value)
113
121
  }
114
122
  })
115
123
  }
116
124
 
117
125
  function normalizeClientConfig (config) {
118
126
  const validateStatus = getStatusValidator(config)
127
+ const filter = getFilter(config)
119
128
  const propagationFilter = getFilter({ blocklist: config.propagationBlocklist })
120
129
  const headers = getHeaders(config)
121
130
  const hooks = getHooks(config)
122
131
 
123
132
  return Object.assign({}, config, {
124
133
  validateStatus,
134
+ filter,
125
135
  propagationFilter,
126
136
  headers,
127
137
  hooks
@@ -1,31 +1,16 @@
1
1
  'use strict'
2
2
 
3
- const Plugin = require('../../dd-trace/src/plugins/plugin')
4
3
  const HttpServerPlugin = require('./server')
5
4
  const HttpClientPlugin = require('./client')
5
+ const CompositePlugin = require('../../dd-trace/src/plugins/composite')
6
6
 
7
- class HttpPlugin extends Plugin {
8
- static get name () {
9
- return 'http'
10
- }
11
- constructor (...args) {
12
- super(...args)
13
- this.server = new HttpServerPlugin(...args)
14
- this.client = new HttpClientPlugin(...args)
15
- }
16
- configure (config) {
17
- const clientConfig = config.client === false ? false : {
18
- ...config,
19
- ...config.client
7
+ class HttpPlugin extends CompositePlugin {
8
+ static get name () { return 'http' }
9
+ static get plugins () {
10
+ return {
11
+ server: HttpServerPlugin,
12
+ client: HttpClientPlugin
20
13
  }
21
-
22
- const serverConfig = config.server === false ? false : {
23
- ...config,
24
- ...config.server
25
- }
26
-
27
- this.server.configure(serverConfig)
28
- this.client.configure(clientConfig)
29
14
  }
30
15
  }
31
16
 
@@ -3,7 +3,8 @@
3
3
  const Plugin = require('../../dd-trace/src/plugins/plugin')
4
4
  const { storage } = require('../../datadog-core')
5
5
  const web = require('../../dd-trace/src/plugins/util/web')
6
- const { incomingHttpRequestStart } = require('../../dd-trace/src/appsec/gateway/channels')
6
+ const { incomingHttpRequestStart, incomingHttpRequestEnd } = require('../../dd-trace/src/appsec/gateway/channels')
7
+ const { COMPONENT } = require('../../dd-trace/src/constants')
7
8
 
8
9
  class HttpServerPlugin extends Plugin {
9
10
  static get name () {
@@ -13,10 +14,15 @@ class HttpServerPlugin extends Plugin {
13
14
  constructor (...args) {
14
15
  super(...args)
15
16
 
16
- this.addSub('apm:http:server:request:start', ({ req, res }) => {
17
+ this._parentStore = undefined
18
+
19
+ this.addSub('apm:http:server:request:start', ({ req, res, abortController }) => {
17
20
  const store = storage.getStore()
18
21
  const span = web.startSpan(this.tracer, this.config, req, res, 'web.request')
19
22
 
23
+ span.setTag(COMPONENT, this.constructor.name)
24
+
25
+ this._parentStore = store
20
26
  this.enter(span, { ...store, req })
21
27
 
22
28
  const context = web.getContext(req)
@@ -27,7 +33,7 @@ class HttpServerPlugin extends Plugin {
27
33
  }
28
34
 
29
35
  if (incomingHttpRequestStart.hasSubscribers) {
30
- incomingHttpRequestStart.publish({ req, res })
36
+ incomingHttpRequestStart.publish({ req, res, abortController })
31
37
  }
32
38
  })
33
39
 
@@ -35,11 +41,21 @@ class HttpServerPlugin extends Plugin {
35
41
  web.addError(error)
36
42
  })
37
43
 
44
+ this.addSub('apm:http:server:request:exit', ({ req }) => {
45
+ const span = this._parentStore && this._parentStore.span
46
+ this.enter(span, this._parentStore)
47
+ this._parentStore = undefined
48
+ })
49
+
38
50
  this.addSub('apm:http:server:request:finish', ({ req }) => {
39
51
  const context = web.getContext(req)
40
52
 
41
53
  if (!context || !context.res) return // Not created by a http.Server instance.
42
54
 
55
+ if (incomingHttpRequestEnd.hasSubscribers) {
56
+ incomingHttpRequestEnd.publish({ req, res: context.res })
57
+ }
58
+
43
59
  web.finishAll(context)
44
60
  })
45
61
  }
@@ -9,6 +9,8 @@ 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')
13
+ const urlFilter = require('../../dd-trace/src/plugins/util/urlfilter')
12
14
 
13
15
  const HTTP_HEADERS = formats.HTTP_HEADERS
14
16
  const HTTP_STATUS_CODE = tags.HTTP_STATUS_CODE
@@ -36,12 +38,14 @@ class Http2ClientPlugin extends Plugin {
36
38
  const pathname = path.split(/[?#]/)[0]
37
39
  const method = headers[HTTP2_HEADER_METHOD] || HTTP2_METHOD_GET
38
40
  const uri = `${sessionDetails.protocol}//${sessionDetails.host}:${sessionDetails.port}${pathname}`
41
+ const allowed = this.config.filter(uri)
39
42
 
40
43
  const store = storage.getStore()
41
- const childOf = store ? store.span : store
44
+ const childOf = store && allowed ? store.span : null
42
45
  const span = this.tracer.startSpan('http.request', {
43
46
  childOf,
44
47
  tags: {
48
+ [COMPONENT]: this.constructor.name,
45
49
  [SPAN_KIND]: CLIENT,
46
50
  'service.name': getServiceName(this.tracer, this.config, sessionDetails),
47
51
  'resource.name': method,
@@ -51,6 +55,11 @@ class Http2ClientPlugin extends Plugin {
51
55
  }
52
56
  })
53
57
 
58
+ // TODO: Figure out a better way to do this for any span.
59
+ if (!allowed) {
60
+ span._spanContext._trace.record = false
61
+ }
62
+
54
63
  addHeaderTags(span, headers, HTTP_REQUEST_HEADERS, this.config)
55
64
 
56
65
  if (!hasAmazonSignature(headers, path)) {
@@ -155,14 +164,24 @@ function getStatusValidator (config) {
155
164
 
156
165
  function normalizeConfig (config) {
157
166
  const validateStatus = getStatusValidator(config)
167
+ const filter = getFilter(config)
158
168
  const headers = getHeaders(config)
159
169
 
160
170
  return Object.assign({}, config, {
161
171
  validateStatus,
172
+ filter,
162
173
  headers
163
174
  })
164
175
  }
165
176
 
177
+ function getFilter (config) {
178
+ config = Object.assign({}, config, {
179
+ blocklist: config.blocklist || []
180
+ })
181
+
182
+ return urlFilter.getFilter(config)
183
+ }
184
+
166
185
  function addHeaderTags (span, headers, prefix, config) {
167
186
  if (!headers) return
168
187
 
@@ -1,34 +1,16 @@
1
1
  'use strict'
2
2
 
3
- const Plugin = require('../../dd-trace/src/plugins/plugin')
4
3
  const Http2ServerPlugin = require('./server')
5
4
  const Http2ClientPlugin = require('./client')
6
-
7
- class Http2Plugin extends Plugin {
8
- static get name () {
9
- return 'http2'
10
- }
11
-
12
- constructor (...args) {
13
- super(...args)
14
-
15
- this.server = new Http2ServerPlugin(...args)
16
- this.client = new Http2ClientPlugin(...args)
17
- }
18
-
19
- configure (config) {
20
- const clientConfig = config.client === false ? false : {
21
- ...config,
22
- ...config.client
23
- }
24
-
25
- const serverConfig = config.server === false ? false : {
26
- ...config,
27
- ...config.server
5
+ const CompositePlugin = require('../../dd-trace/src/plugins/composite')
6
+
7
+ class Http2Plugin extends CompositePlugin {
8
+ static get name () { return 'http2' }
9
+ static get plugins () {
10
+ return {
11
+ server: Http2ServerPlugin,
12
+ client: Http2ClientPlugin
28
13
  }
29
-
30
- this.server.configure(serverConfig)
31
- this.client.configure(clientConfig)
32
14
  }
33
15
  }
34
16
 
@@ -3,11 +3,55 @@
3
3
  // Plugin temporarily disabled. See https://github.com/DataDog/dd-trace-js/issues/312
4
4
 
5
5
  const Plugin = require('../../dd-trace/src/plugins/plugin')
6
+ const { storage } = require('../../datadog-core')
7
+ const web = require('../../dd-trace/src/plugins/util/web')
8
+ const { incomingHttpRequestStart } = require('../../dd-trace/src/appsec/gateway/channels')
9
+ const { COMPONENT } = require('../../dd-trace/src/constants')
6
10
 
7
11
  class Http2ServerPlugin extends Plugin {
8
12
  static get name () {
9
13
  return 'http2'
10
14
  }
15
+
16
+ constructor (...args) {
17
+ super(...args)
18
+
19
+ this.addSub('apm:http2:server:request:start', ({ req, res }) => {
20
+ const store = storage.getStore()
21
+ const span = web.startSpan(this.tracer, this.config, req, res, 'web.request')
22
+
23
+ span.setTag(COMPONENT, this.constructor.name)
24
+
25
+ this.enter(span, { ...store, req })
26
+
27
+ const context = web.getContext(req)
28
+
29
+ if (!context.instrumented) {
30
+ context.res.writeHead = web.wrapWriteHead(context)
31
+ context.instrumented = true
32
+ }
33
+
34
+ if (incomingHttpRequestStart.hasSubscribers) {
35
+ incomingHttpRequestStart.publish({ req, res })
36
+ }
37
+ })
38
+
39
+ this.addSub('apm:http2:server:request:error', (error) => {
40
+ web.addError(error)
41
+ })
42
+
43
+ this.addSub('apm:http2:server:request:finish', ({ req }) => {
44
+ const context = web.getContext(req)
45
+
46
+ if (!context || !context.res) return // Not created by a http.Server instance.
47
+
48
+ web.finishAll(context)
49
+ })
50
+ }
51
+
52
+ configure (config) {
53
+ return super.configure(web.normalizeConfig(config))
54
+ }
11
55
  }
12
56
 
13
57
  module.exports = Http2ServerPlugin