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
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * Modifications copyright 2022 Datadog, Inc.
4
+ *
5
+ * Some functions are part of aws-lambda-nodejs-runtime-interface-client
6
+ * https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/main/src/utils/UserFunction.ts
7
+ */
8
+ 'use strict'
9
+
10
+ const fs = require('fs')
11
+ const path = require('path')
12
+
13
+ const log = require('../../log')
14
+ const Hook = require('../../../../datadog-instrumentations/src/helpers/hook')
15
+ const instrumentations = require('../../../../datadog-instrumentations/src/helpers/instrumentations')
16
+ const {
17
+ filename,
18
+ pathSepExpr
19
+ } = require('../../../../datadog-instrumentations/src/helpers/register')
20
+
21
+ /**
22
+ * Breaks the full handler string into two pieces: the module root
23
+ * and the actual handler string.
24
+ *
25
+ * @param {string} fullHandler user's lambda handler, commonly stored in `DD_LAMBDA_HANDLER`.
26
+ * @returns {string[]} an array containing the module root and the handler string.
27
+ *
28
+ * ```js
29
+ * _extractModuleRootAndHandler('./api/src/index.nested.handler')
30
+ * // => ['./api/src', 'index.nested.handler']
31
+ * ```
32
+ */
33
+ function _extractModuleRootAndHandler (fullHandler) {
34
+ const handlerString = path.basename(fullHandler)
35
+ const moduleRoot = fullHandler.substring(0, fullHandler.indexOf(handlerString))
36
+
37
+ return [moduleRoot, handlerString]
38
+ }
39
+
40
+ /**
41
+ * Splits the handler string into two pieces: the module name
42
+ * and the path to the handler function.
43
+ *
44
+ * @param {string} handler a handler string containing the module and the handler path.
45
+ * @returns {string[]} an array containing the module name and the handler path.
46
+ *
47
+ * ```js
48
+ * _extractModuleNameAndHandlerPath('index.nested.handler')
49
+ * // => ['index', 'nested.handler']
50
+ * ```
51
+ */
52
+ function _extractModuleNameAndHandlerPath (handler) {
53
+ const FUNCTION_EXPR = /^([^.]*)\.(.*)$/
54
+ const match = handler.match(FUNCTION_EXPR)
55
+ if (!match || match.length !== 3) {
56
+ // Malformed Handler Name
57
+ return // TODO: throw error
58
+ }
59
+ return [match[1], match[2]] // [module, handler-path]
60
+ }
61
+
62
+ /**
63
+ * Returns the correct path of the file to be patched
64
+ * when required.
65
+ *
66
+ * @param {*} lambdaStylePath the path comprised of the `LAMBDA_TASK_ROOT`,
67
+ * the root of the module of the Lambda handler, and the module name.
68
+ * @returns the lambdaStylePath with the appropiate extension for the hook.
69
+ */
70
+ function _getLambdaFilePath (lambdaStylePath) {
71
+ let lambdaFilePath = lambdaStylePath
72
+ if (fs.existsSync(lambdaStylePath + '.js')) {
73
+ lambdaFilePath += '.js'
74
+ } else if (fs.existsSync(lambdaStylePath + '.mjs')) {
75
+ lambdaFilePath += '.mjs'
76
+ } else if (fs.existsSync(lambdaStylePath + '.cjs')) {
77
+ lambdaFilePath += '.cjs'
78
+ }
79
+ return lambdaFilePath
80
+ }
81
+
82
+ /**
83
+ * Register a hook for the Lambda handler to be executed when
84
+ * the file is required.
85
+ */
86
+ const registerLambdaHook = () => {
87
+ const lambdaTaskRoot = process.env.LAMBDA_TASK_ROOT
88
+ const originalLambdaHandler = process.env.DD_LAMBDA_HANDLER
89
+
90
+ if (originalLambdaHandler !== undefined) {
91
+ const [moduleRoot, moduleAndHandler] = _extractModuleRootAndHandler(originalLambdaHandler)
92
+ const [_module] = _extractModuleNameAndHandlerPath(moduleAndHandler)
93
+
94
+ const lambdaStylePath = path.resolve(lambdaTaskRoot, moduleRoot, _module)
95
+ const lambdaFilePath = _getLambdaFilePath(lambdaStylePath)
96
+
97
+ Hook([lambdaFilePath], (moduleExports) => {
98
+ require('./patch')
99
+
100
+ for (const { hook } of instrumentations[lambdaFilePath]) {
101
+ try {
102
+ moduleExports = hook(moduleExports)
103
+ } catch (e) {
104
+ log.error(e)
105
+ }
106
+ }
107
+
108
+ return moduleExports
109
+ })
110
+ } else {
111
+ const moduleToPatch = 'datadog-lambda-js'
112
+ Hook([moduleToPatch], (moduleExports, moduleName, _) => {
113
+ moduleName = moduleName.replace(pathSepExpr, '/')
114
+
115
+ require('./patch')
116
+
117
+ for (const { name, file, hook } of instrumentations[moduleToPatch]) {
118
+ const fullFilename = filename(name, file)
119
+ if (moduleName === fullFilename) {
120
+ try {
121
+ moduleExports = hook(moduleExports)
122
+ } catch (e) {
123
+ log.error(e)
124
+ }
125
+ }
126
+ }
127
+
128
+ return moduleExports
129
+ })
130
+ }
131
+ }
132
+
133
+ module.exports = {
134
+ _extractModuleRootAndHandler,
135
+ _extractModuleNameAndHandlerPath,
136
+ _getLambdaFilePath,
137
+ registerLambdaHook
138
+ }
@@ -2,6 +2,7 @@
2
2
 
3
3
  // TODO: capture every second and flush every 10 seconds
4
4
 
5
+ const { URL, format } = require('url')
5
6
  const v8 = require('v8')
6
7
  const os = require('os')
7
8
  const Client = require('./dogstatsd')
@@ -48,11 +49,23 @@ module.exports = {
48
49
  nativeMetrics = null
49
50
  }
50
51
 
51
- client = new Client({
52
+ const clientConfig = {
52
53
  host: config.dogstatsd.hostname,
53
54
  port: config.dogstatsd.port,
54
55
  tags
55
- })
56
+ }
57
+
58
+ if (config.url) {
59
+ clientConfig.metricsProxyUrl = config.url
60
+ } else if (config.port) {
61
+ clientConfig.metricsProxyUrl = new URL(format({
62
+ protocol: 'http:',
63
+ hostname: config.hostname || 'localhost',
64
+ port: config.port
65
+ }))
66
+ }
67
+
68
+ client = new Client(clientConfig)
56
69
 
57
70
  time = process.hrtime()
58
71
 
@@ -130,11 +130,7 @@ class TextMapPropagator {
130
130
 
131
131
  _injectTraceparent (spanContext, carrier) {
132
132
  if (!this._config.experimental.traceparent) return
133
-
134
- const sampling = spanContext._sampling.priority >= AUTO_KEEP ? '01' : '00'
135
- const traceId = spanContext._traceId.toString(16).padStart(32, '0')
136
- const spanId = spanContext._spanId.toString(16).padStart(16, '0')
137
- carrier[traceparentKey] = `01-${traceId}-${spanId}-${sampling}`
133
+ carrier[traceparentKey] = spanContext.toTraceparent()
138
134
  }
139
135
 
140
136
  _extractSpanContext (carrier) {
@@ -1,7 +1,8 @@
1
1
  'use strict'
2
2
 
3
3
  // TODO (new internal tracer): use DC events for lifecycle metrics and test them
4
- const now = require('perf_hooks').performance.now
4
+ const { performance } = require('perf_hooks')
5
+ const now = performance.now.bind(performance)
5
6
  const dateNow = Date.now
6
7
  const semver = require('semver')
7
8
  const SpanContext = require('./span_context')
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ const { AUTO_KEEP } = require('../../../../ext/priority')
4
+
3
5
  class DatadogSpanContext {
4
6
  constructor (props) {
5
7
  props = props || {}
@@ -27,6 +29,13 @@ class DatadogSpanContext {
27
29
  toSpanId () {
28
30
  return this._spanId.toString(10)
29
31
  }
32
+
33
+ toTraceparent () {
34
+ const sampling = this._sampling.priority >= AUTO_KEEP ? '01' : '00'
35
+ const traceId = this._traceId.toString(16).padStart(32, '0')
36
+ const spanId = this._spanId.toString(16).padStart(16, '0')
37
+ return `01-${traceId}-${spanId}-${sampling}`
38
+ }
30
39
  }
31
40
 
32
41
  module.exports = DatadogSpanContext
@@ -9,6 +9,10 @@ const loadChannel = channel('dd-trace:instrumentation:load')
9
9
 
10
10
  // instrument everything that needs Plugin System V2 instrumentation
11
11
  require('../../datadog-instrumentations')
12
+ if (process.env.AWS_LAMBDA_FUNCTION_NAME !== undefined) {
13
+ // instrument lambda environment
14
+ require('./lambda')
15
+ }
12
16
 
13
17
  const { DD_TRACE_DISABLED_PLUGINS } = process.env
14
18
 
@@ -120,10 +124,9 @@ module.exports = class PluginManager {
120
124
  logInjection,
121
125
  serviceMapping,
122
126
  queryStringObfuscation,
123
- clientIpHeaderDisabled,
124
- clientIpHeader,
125
- isIntelligentTestRunnerEnabled,
126
- experimental
127
+ site,
128
+ url,
129
+ dbmPropagationMode
127
130
  } = this._tracerConfig
128
131
 
129
132
  const sharedConfig = {}
@@ -136,24 +139,15 @@ module.exports = class PluginManager {
136
139
  sharedConfig.queryStringObfuscation = queryStringObfuscation
137
140
  }
138
141
 
139
- if (clientIpHeaderDisabled !== undefined) {
140
- sharedConfig.clientIpHeaderDisabled = clientIpHeaderDisabled
141
- }
142
-
143
- if (clientIpHeader !== undefined) {
144
- sharedConfig.clientIpHeader = clientIpHeader
145
- }
146
-
147
- if (experimental) {
148
- sharedConfig.isAgentlessEnabled = experimental.exporter === 'datadog'
149
- }
150
-
151
- sharedConfig.isIntelligentTestRunnerEnabled = isIntelligentTestRunnerEnabled
142
+ sharedConfig.dbmPropagationMode = dbmPropagationMode
152
143
 
153
144
  if (serviceMapping && serviceMapping[name]) {
154
145
  sharedConfig.service = serviceMapping[name]
155
146
  }
156
147
 
148
+ sharedConfig.site = site
149
+ sharedConfig.url = url
150
+
157
151
  return sharedConfig
158
152
  }
159
153
  }
@@ -0,0 +1,9 @@
1
+ 'use strict'
2
+
3
+ const StoragePlugin = require('./storage')
4
+
5
+ class CachePlugin extends StoragePlugin {
6
+ static get operation () { return 'command' }
7
+ }
8
+
9
+ module.exports = CachePlugin
@@ -0,0 +1,97 @@
1
+ const {
2
+ getTestEnvironmentMetadata,
3
+ getCodeOwnersFileEntries,
4
+ getTestParentSpan,
5
+ getTestCommonTags,
6
+ getCodeOwnersForFilename,
7
+ TEST_CODE_OWNERS,
8
+ CI_APP_ORIGIN
9
+ } = require('./util/test')
10
+ const { COMPONENT } = require('../constants')
11
+
12
+ const Plugin = require('./plugin')
13
+
14
+ module.exports = class CiPlugin extends Plugin {
15
+ constructor (...args) {
16
+ super(...args)
17
+
18
+ this.addSub(`ci:${this.constructor.name}:itr-configuration`, ({ onDone }) => {
19
+ if (!this.tracer._exporter || !this.tracer._exporter.getItrConfiguration) {
20
+ return onDone({ err: new Error('CI Visibility was not initialized correctly') })
21
+ }
22
+ this.tracer._exporter.getItrConfiguration(this.testConfiguration, (err, itrConfig) => {
23
+ if (!err) {
24
+ this.itrConfig = itrConfig
25
+ }
26
+ onDone({ err, itrConfig })
27
+ })
28
+ })
29
+
30
+ this.addSub(`ci:${this.constructor.name}:test-suite:skippable`, ({ onDone }) => {
31
+ if (!this.tracer._exporter || !this.tracer._exporter.getSkippableSuites) {
32
+ return onDone({ err: new Error('CI Visibility was not initialized correctly') })
33
+ }
34
+ this.tracer._exporter.getSkippableSuites(this.testConfiguration, (err, skippableSuites) => {
35
+ onDone({ err, skippableSuites })
36
+ })
37
+ })
38
+ }
39
+
40
+ configure (config) {
41
+ super.configure(config)
42
+ this.testEnvironmentMetadata = getTestEnvironmentMetadata(this.constructor.name, this.config)
43
+ this.codeOwnersEntries = getCodeOwnersFileEntries()
44
+
45
+ const {
46
+ 'git.repository_url': repositoryUrl,
47
+ 'git.commit.sha': sha,
48
+ 'os.version': osVersion,
49
+ 'os.platform': osPlatform,
50
+ 'os.architecture': osArchitecture,
51
+ 'runtime.name': runtimeName,
52
+ 'runtime.version': runtimeVersion,
53
+ 'git.branch': branch
54
+ } = this.testEnvironmentMetadata
55
+
56
+ this.testConfiguration = {
57
+ repositoryUrl,
58
+ sha,
59
+ osVersion,
60
+ osPlatform,
61
+ osArchitecture,
62
+ runtimeName,
63
+ runtimeVersion,
64
+ branch
65
+ }
66
+ }
67
+
68
+ startTestSpan (name, suite, extraTags, childOf) {
69
+ const parent = childOf || getTestParentSpan(this.tracer)
70
+ const testCommonTags = getTestCommonTags(name, suite, this.tracer._version)
71
+
72
+ const testTags = {
73
+ ...testCommonTags,
74
+ [COMPONENT]: this.constructor.name,
75
+ ...extraTags
76
+ }
77
+
78
+ const codeOwners = getCodeOwnersForFilename(suite, this.codeOwnersEntries)
79
+
80
+ if (codeOwners) {
81
+ testTags[TEST_CODE_OWNERS] = codeOwners
82
+ }
83
+
84
+ const testSpan = this.tracer
85
+ .startSpan(`${this.constructor.name}.test`, {
86
+ childOf: parent,
87
+ tags: {
88
+ ...this.testEnvironmentMetadata,
89
+ ...testTags
90
+ }
91
+ })
92
+
93
+ testSpan.context()._trace.origin = CI_APP_ORIGIN
94
+
95
+ return testSpan
96
+ }
97
+ }
@@ -0,0 +1,9 @@
1
+ 'use strict'
2
+
3
+ const OutgoingPlugin = require('./outgoing')
4
+
5
+ class ClientPlugin extends OutgoingPlugin {
6
+ static get operation () { return 'request' }
7
+ }
8
+
9
+ module.exports = ClientPlugin
@@ -0,0 +1,26 @@
1
+ 'use strict'
2
+
3
+ const Plugin = require('./plugin')
4
+
5
+ class CompositePlugin extends Plugin {
6
+ constructor (...args) {
7
+ super(...args)
8
+
9
+ for (const [name, PluginClass] of Object.entries(this.constructor.plugins)) {
10
+ this[name] = new PluginClass(...args)
11
+ }
12
+ }
13
+
14
+ configure (config) {
15
+ for (const name in this.constructor.plugins) {
16
+ const pluginConfig = config[name] === false ? false : {
17
+ ...config,
18
+ ...config[name]
19
+ }
20
+
21
+ this[name].configure(pluginConfig)
22
+ }
23
+ }
24
+ }
25
+
26
+ module.exports = CompositePlugin
@@ -0,0 +1,9 @@
1
+ 'use strict'
2
+
3
+ const IncomingPlugin = require('./incoming')
4
+
5
+ class ConsumerPlugin extends IncomingPlugin {
6
+ static get operation () { return 'receive' }
7
+ }
8
+
9
+ module.exports = ConsumerPlugin
@@ -0,0 +1,55 @@
1
+ 'use strict'
2
+
3
+ const StoragePlugin = require('./storage')
4
+
5
+ class DatabasePlugin extends StoragePlugin {
6
+ static get operation () { return 'query' }
7
+
8
+ constructor (...args) {
9
+ super(...args)
10
+ this.serviceTags = {
11
+ dddbs: '',
12
+ encodedDddbs: '',
13
+ dde: '',
14
+ encodedDde: '',
15
+ ddps: '',
16
+ encodedDdps: '',
17
+ ddpv: '',
18
+ encodedDdpv: ''
19
+ }
20
+ }
21
+ encodingServiceTags (serviceTag, encodeATag, spanConfig) {
22
+ if (serviceTag !== spanConfig) {
23
+ this.serviceTags[serviceTag] = spanConfig
24
+ this.serviceTags[encodeATag] = encodeURIComponent(spanConfig)
25
+ }
26
+ }
27
+
28
+ createDBMPropagationCommentService (serviceName) {
29
+ this.encodingServiceTags('dddbs', 'encodedDddbs', serviceName)
30
+ this.encodingServiceTags('dde', 'encodedDde', this.tracer._env)
31
+ this.encodingServiceTags('ddps', 'encodedDdps', this.tracer._service)
32
+ this.encodingServiceTags('ddpv', 'encodedDdpv', this.tracer._version)
33
+
34
+ const { encodedDddbs, encodedDde, encodedDdps, encodedDdpv } = this.serviceTags
35
+
36
+ return `dddbs='${encodedDddbs}',dde='${encodedDde}',` +
37
+ `ddps='${encodedDdps}',ddpv='${encodedDdpv}'`
38
+ }
39
+
40
+ injectDbmQuery (query, serviceName) {
41
+ if (this.config.dbmPropagationMode === 'disabled') {
42
+ return query
43
+ }
44
+ const servicePropagation = this.createDBMPropagationCommentService(serviceName)
45
+ if (this.config.dbmPropagationMode === 'service') {
46
+ return `/*${servicePropagation}*/ ${query}`
47
+ } else if (this.config.dbmPropagationMode === 'full') {
48
+ this.activeSpan.setTag('_dd.dbm_trace_injected', 'true')
49
+ const traceparent = this.activeSpan._spanContext.toTraceparent()
50
+ return `/*${servicePropagation},traceparent='${traceparent}'*/ ${query}`
51
+ }
52
+ }
53
+ }
54
+
55
+ module.exports = DatabasePlugin
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+
3
+ const TracingPlugin = require('./tracing')
4
+
5
+ class IncomingPlugin extends TracingPlugin {}
6
+
7
+ module.exports = IncomingPlugin
@@ -10,6 +10,8 @@ module.exports = {
10
10
  get '@jest/core' () { return require('../../../datadog-plugin-jest/src') },
11
11
  get '@koa/router' () { return require('../../../datadog-plugin-koa/src') },
12
12
  get '@node-redis/client' () { return require('../../../datadog-plugin-redis/src') },
13
+ get '@opensearch-project/opensearch' () { return require('../../../datadog-plugin-opensearch/src') },
14
+ get '@redis/client' () { return require('../../../datadog-plugin-redis/src') },
13
15
  get 'amqp10' () { return require('../../../datadog-plugin-amqp10/src') },
14
16
  get 'amqplib' () { return require('../../../datadog-plugin-amqplib/src') },
15
17
  get 'aws-sdk' () { return require('../../../datadog-plugin-aws-sdk/src') },
@@ -38,6 +40,7 @@ module.exports = {
38
40
  get 'koa' () { return require('../../../datadog-plugin-koa/src') },
39
41
  get 'koa-router' () { return require('../../../datadog-plugin-koa/src') },
40
42
  get 'kafkajs' () { return require('../../../datadog-plugin-kafkajs/src') },
43
+ get 'mariadb' () { return require('../../../datadog-plugin-mariadb/src') },
41
44
  get 'memcached' () { return require('../../../datadog-plugin-memcached/src') },
42
45
  get 'microgateway-core' () { return require('../../../datadog-plugin-microgateway-core/src') },
43
46
  get 'mocha' () { return require('../../../datadog-plugin-mocha/src') },
@@ -43,8 +43,8 @@ module.exports = class LogPlugin extends Plugin {
43
43
  const store = storage.getStore()
44
44
  const span = store && store.span
45
45
 
46
- if (!span) return
47
-
46
+ // NOTE: This needs to run whether or not there is a span
47
+ // so service, version, and env will always get injected.
48
48
  const holder = {}
49
49
  this.tracer.inject(span, LOG, holder)
50
50
  arg.message = messageProxy(arg.message, holder)
@@ -0,0 +1,31 @@
1
+ 'use strict'
2
+
3
+ const TracingPlugin = require('./tracing')
4
+
5
+ // TODO: Exit span on finish when AsyncResource instances are removed.
6
+ class OutgoingPlugin extends TracingPlugin {
7
+ constructor (...args) {
8
+ super(...args)
9
+
10
+ this.addTraceSub('connect', message => {
11
+ this.connect(message)
12
+ })
13
+ }
14
+
15
+ connect (url) {
16
+ this.addHost(url.hostname, url.port)
17
+ }
18
+
19
+ addHost (hostname, port) {
20
+ const span = this.activeSpan
21
+
22
+ if (!span) return
23
+
24
+ span.addTags({
25
+ 'out.host': hostname,
26
+ 'out.port': port
27
+ })
28
+ }
29
+ }
30
+
31
+ module.exports = OutgoingPlugin
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ // TODO: move anything related to tracing to TracingPlugin instead
4
+
3
5
  const dc = require('diagnostics_channel')
4
6
  const { storage } = require('../../../datadog-core')
5
7
 
@@ -39,6 +41,7 @@ module.exports = class Plugin {
39
41
  storage.enterWith({ ...store, span })
40
42
  }
41
43
 
44
+ // TODO: Implement filters on resource name for all plugins.
42
45
  /** Prevents creation of spans here and for all async descendants. */
43
46
  skip () {
44
47
  storage.enterWith({ noop: true })
@@ -0,0 +1,9 @@
1
+ 'use strict'
2
+
3
+ const OutgoingPlugin = require('./outgoing')
4
+
5
+ class ProducerPlugin extends OutgoingPlugin {
6
+ static get operation () { return 'publish' }
7
+ }
8
+
9
+ module.exports = ProducerPlugin
@@ -0,0 +1,9 @@
1
+ 'use strict'
2
+
3
+ const IncomingPlugin = require('./incoming')
4
+
5
+ class ServerPlugin extends IncomingPlugin {
6
+ static get operation () { return 'request' }
7
+ }
8
+
9
+ module.exports = ServerPlugin
@@ -0,0 +1,21 @@
1
+ 'use strict'
2
+
3
+ const ClientPlugin = require('./client')
4
+
5
+ class StoragePlugin extends ClientPlugin {
6
+ constructor (...args) {
7
+ super(...args)
8
+
9
+ this.system = this.constructor.system || this.component
10
+ }
11
+
12
+ startSpan (name, options) {
13
+ if (!options.service && this.system) {
14
+ options.service = `${this.tracer._service}-${this.system}`
15
+ }
16
+
17
+ return super.startSpan(name, options)
18
+ }
19
+ }
20
+
21
+ module.exports = StoragePlugin