dd-trace 3.5.0 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/index.d.ts +40 -2
  2. package/package.json +1 -1
  3. package/packages/datadog-instrumentations/src/cucumber.js +0 -2
  4. package/packages/datadog-instrumentations/src/elasticsearch.js +51 -47
  5. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +1 -1
  6. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
  7. package/packages/datadog-instrumentations/src/mariadb.js +43 -69
  8. package/packages/datadog-instrumentations/src/mocha.js +14 -18
  9. package/packages/datadog-instrumentations/src/opensearch.js +10 -0
  10. package/packages/datadog-instrumentations/src/pg.js +2 -1
  11. package/packages/datadog-instrumentations/src/rhea.js +20 -17
  12. package/packages/datadog-plugin-amqp10/src/consumer.js +32 -0
  13. package/packages/datadog-plugin-amqp10/src/index.js +11 -101
  14. package/packages/datadog-plugin-amqp10/src/producer.js +34 -0
  15. package/packages/datadog-plugin-amqp10/src/util.js +15 -0
  16. package/packages/datadog-plugin-amqplib/src/client.js +38 -0
  17. package/packages/datadog-plugin-amqplib/src/consumer.js +40 -0
  18. package/packages/datadog-plugin-amqplib/src/index.js +14 -102
  19. package/packages/datadog-plugin-amqplib/src/producer.js +37 -0
  20. package/packages/datadog-plugin-amqplib/src/util.js +14 -0
  21. package/packages/datadog-plugin-dns/src/index.js +16 -91
  22. package/packages/datadog-plugin-dns/src/lookup.js +40 -0
  23. package/packages/datadog-plugin-dns/src/lookup_service.js +24 -0
  24. package/packages/datadog-plugin-dns/src/resolve.js +24 -0
  25. package/packages/datadog-plugin-dns/src/reverse.js +21 -0
  26. package/packages/datadog-plugin-elasticsearch/src/index.js +7 -7
  27. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +25 -0
  28. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +42 -0
  29. package/packages/datadog-plugin-google-cloud-pubsub/src/index.js +14 -99
  30. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +34 -0
  31. package/packages/datadog-plugin-graphql/src/execute.js +73 -0
  32. package/packages/datadog-plugin-graphql/src/index.js +14 -176
  33. package/packages/datadog-plugin-graphql/src/parse.js +32 -0
  34. package/packages/datadog-plugin-graphql/src/resolve.js +70 -76
  35. package/packages/datadog-plugin-graphql/src/validate.js +28 -0
  36. package/packages/datadog-plugin-grpc/src/client.js +46 -55
  37. package/packages/datadog-plugin-grpc/src/index.js +7 -24
  38. package/packages/datadog-plugin-grpc/src/server.js +50 -52
  39. package/packages/datadog-plugin-grpc/src/util.js +15 -14
  40. package/packages/datadog-plugin-http/src/index.js +7 -22
  41. package/packages/datadog-plugin-http2/src/index.js +8 -26
  42. package/packages/datadog-plugin-jest/src/index.js +3 -0
  43. package/packages/datadog-plugin-kafkajs/src/consumer.js +42 -0
  44. package/packages/datadog-plugin-kafkajs/src/index.js +11 -87
  45. package/packages/datadog-plugin-kafkajs/src/producer.js +31 -0
  46. package/packages/datadog-plugin-mocha/src/index.js +2 -2
  47. package/packages/datadog-plugin-moleculer/src/client.js +22 -36
  48. package/packages/datadog-plugin-moleculer/src/index.js +8 -26
  49. package/packages/datadog-plugin-moleculer/src/server.js +18 -30
  50. package/packages/datadog-plugin-net/src/ipc.js +21 -0
  51. package/packages/datadog-plugin-net/src/tcp.js +46 -0
  52. package/packages/datadog-plugin-opensearch/src/index.js +11 -0
  53. package/packages/datadog-plugin-pg/src/index.js +2 -1
  54. package/packages/datadog-plugin-rhea/src/consumer.js +55 -0
  55. package/packages/datadog-plugin-rhea/src/index.js +11 -99
  56. package/packages/datadog-plugin-rhea/src/producer.js +45 -0
  57. package/packages/datadog-plugin-sharedb/src/index.js +22 -39
  58. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +1 -1
  59. package/packages/dd-trace/src/appsec/iast/index.js +4 -6
  60. package/packages/dd-trace/src/appsec/iast/path-line.js +3 -0
  61. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +2 -5
  62. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +2 -5
  63. package/packages/dd-trace/src/config.js +26 -6
  64. package/packages/dd-trace/src/constants.js +3 -0
  65. package/packages/dd-trace/src/dogstatsd.js +42 -10
  66. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +10 -2
  67. package/packages/dd-trace/src/exporters/agent/writer.js +2 -9
  68. package/packages/dd-trace/src/exporters/common/request.js +12 -0
  69. package/packages/dd-trace/src/format.js +13 -0
  70. package/packages/dd-trace/src/metrics.js +10 -2
  71. package/packages/dd-trace/src/plugins/client.js +3 -1
  72. package/packages/dd-trace/src/plugins/composite.js +26 -0
  73. package/packages/dd-trace/src/plugins/consumer.js +9 -0
  74. package/packages/dd-trace/src/plugins/incoming.js +7 -0
  75. package/packages/dd-trace/src/plugins/index.js +1 -0
  76. package/packages/dd-trace/src/plugins/outgoing.js +1 -1
  77. package/packages/dd-trace/src/plugins/producer.js +9 -0
  78. package/packages/dd-trace/src/plugins/server.js +9 -0
  79. package/packages/dd-trace/src/plugins/storage.js +0 -4
  80. package/packages/dd-trace/src/plugins/tracing.js +9 -9
  81. package/packages/dd-trace/src/profiling/profiler.js +8 -1
  82. package/packages/dd-trace/src/span_processor.js +3 -0
  83. package/packages/dd-trace/src/span_sampler.js +80 -0
  84. package/packages/dd-trace/src/tracer.js +6 -2
  85. package/packages/dd-trace/src/util.js +43 -1
@@ -0,0 +1,25 @@
1
+ 'use strict'
2
+
3
+ const ClientPlugin = require('../../dd-trace/src/plugins/client')
4
+
5
+ class GoogleCloudPubsubClientPlugin extends ClientPlugin {
6
+ static get name () { return 'google-cloud-pubsub' }
7
+ static get operation () { return 'request' }
8
+
9
+ start ({ cfg, projectId }) {
10
+ if (cfg.method === 'publish') return
11
+
12
+ this.startSpan('pubsub.request', {
13
+ service: this.config.service || `${this.tracer._service}-pubsub`,
14
+ resource: [cfg.method, cfg.reqOpts.name].filter(x => x).join(' '),
15
+ kind: 'client',
16
+ meta: {
17
+ 'component': '@google-cloud/pubsub',
18
+ 'pubsub.method': cfg.method,
19
+ 'gcloud.project_id': projectId
20
+ }
21
+ })
22
+ }
23
+ }
24
+
25
+ module.exports = GoogleCloudPubsubClientPlugin
@@ -0,0 +1,42 @@
1
+ 'use strict'
2
+
3
+ const ConsumerPlugin = require('../../dd-trace/src/plugins/consumer')
4
+
5
+ class GoogleCloudPubsubConsumerPlugin extends ConsumerPlugin {
6
+ static get name () { return 'google-cloud-pubsub' }
7
+ static get operation () { return 'receive' }
8
+
9
+ start ({ message }) {
10
+ const subscription = message._subscriber._subscription
11
+ const topic = subscription.metadata && subscription.metadata.topic
12
+ const childOf = this.tracer.extract('text_map', message.attributes) || null
13
+
14
+ this.startSpan('pubsub.receive', {
15
+ childOf,
16
+ service: this.config.service,
17
+ resource: topic,
18
+ kind: 'consumer',
19
+ type: 'worker',
20
+ meta: {
21
+ 'component': '@google-cloud/pubsub',
22
+ 'gcloud.project_id': subscription.pubsub.projectId,
23
+ 'pubsub.topic': topic
24
+ },
25
+ metrics: {
26
+ 'pubsub.ack': 0
27
+ }
28
+ })
29
+ }
30
+
31
+ finish (message) {
32
+ const span = this.activeSpan
33
+
34
+ if (message.message._handled) {
35
+ span.setTag('pubsub.ack', 1)
36
+ }
37
+
38
+ span.finish()
39
+ }
40
+ }
41
+
42
+ module.exports = GoogleCloudPubsubConsumerPlugin
@@ -1,104 +1,19 @@
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
- const messageSpans = new WeakMap()
8
- class GoogleCloudPubsubPlugin extends Plugin {
9
- static get name () {
10
- return 'google-cloud-pubsub'
11
- }
12
-
13
- constructor (...args) {
14
- super(...args)
15
-
16
- this.addSub(`apm:google-cloud-pubsub:request:start`, ({ cfg, projectId, messages }) => {
17
- const store = storage.getStore()
18
- const childOf = store ? store.span : store
19
- const topic = getTopic(cfg)
20
- const tags = {
21
- component: '@google-cloud/pubsub',
22
- 'resource.name': [cfg.method, topic].filter(x => x).join(' '),
23
- 'service.name': this.config.service || `${this.tracer._service}-pubsub`,
24
- 'span.kind': 'client',
25
- 'pubsub.method': cfg.method,
26
- 'gcloud.project_id': projectId,
27
- 'pubsub.topic': topic
28
- }
29
- if (cfg.method === 'publish') {
30
- tags['span.kind'] = 'producer'
31
- }
32
- const span = this.tracer.startSpan('pubsub.request', {
33
- childOf,
34
- tags
35
- })
36
-
37
- analyticsSampler.sample(span, this.config.measured)
38
- this.enter(span, store)
39
-
40
- for (const msg of messages) {
41
- if (!msg.attributes) {
42
- msg.attributes = {}
43
- }
44
- this.tracer.inject(span, 'text_map', msg.attributes)
45
- }
46
- })
47
-
48
- this.addSub(`apm:google-cloud-pubsub:receive:start`, ({ message }) => {
49
- const store = storage.getStore()
50
- const subscription = message._subscriber._subscription
51
- const topic = subscription.metadata && subscription.metadata.topic
52
- const childOf = this.tracer.extract('text_map', message.attributes)
53
- const tags = {
54
- component: '@google-cloud/pubsub',
55
- 'resource.name': topic,
56
- 'service.name': this.config.service || this.tracer._service,
57
- 'gcloud.project_id': subscription.pubsub.projectId,
58
- 'pubsub.topic': topic,
59
- 'span.kind': 'consumer',
60
- 'span.type': 'worker'
61
- }
62
-
63
- const span = this.tracer.startSpan('pubsub.receive', {
64
- childOf,
65
- tags
66
- })
67
-
68
- analyticsSampler.sample(span, this.config.measured, true)
69
- this.enter(span, store)
70
-
71
- messageSpans.set(message, span)
72
- })
73
-
74
- this.addSub(`apm:google-cloud-pubsub:request:error`, err => {
75
- const span = storage.getStore().span
76
- span.setTag('error', err)
77
- })
78
-
79
- this.addSub(`apm:google-cloud-pubsub:request:finish`, () => {
80
- const span = storage.getStore().span
81
- span.finish()
82
- })
83
-
84
- this.addSub(`apm:google-cloud-pubsub:receive:error`, ({ err, message }) => {
85
- const span = messageSpans.get(message)
86
- if (!span) return undefined
87
- span.setTag('error', err)
88
- })
89
-
90
- this.addSub(`apm:google-cloud-pubsub:receive:finish`, ({ message }) => {
91
- const span = messageSpans.get(message)
92
- if (!span) return
93
- span.setTag('pubsub.ack', message._handled ? 1 : 0)
94
- span.finish()
95
- })
96
- }
97
- }
98
-
99
- function getTopic (cfg) {
100
- if (cfg.reqOpts) {
101
- return cfg.reqOpts[cfg.method === 'createTopic' ? 'name' : 'topic']
3
+ const ProducerPlugin = require('./producer')
4
+ const ConsumerPlugin = require('./consumer')
5
+ const ClientPlugin = require('./client')
6
+ const CompositePlugin = require('../../dd-trace/src/plugins/composite')
7
+
8
+ // TODO: Consider splitting channels for publish/receive in the instrumentation.
9
+ class GoogleCloudPubsubPlugin extends CompositePlugin {
10
+ static get name () { return 'google-cloud-pubsub' }
11
+ static get plugins () {
12
+ return {
13
+ producer: ProducerPlugin,
14
+ consumer: ConsumerPlugin,
15
+ client: ClientPlugin
16
+ }
102
17
  }
103
18
  }
104
19
 
@@ -0,0 +1,34 @@
1
+ 'use strict'
2
+
3
+ const ProducerPlugin = require('../../dd-trace/src/plugins/producer')
4
+
5
+ class GoogleCloudPubsubProducerPlugin extends ProducerPlugin {
6
+ static get name () { return 'google-cloud-pubsub' }
7
+ static get operation () { return 'request' }
8
+
9
+ start ({ cfg, projectId, messages }) {
10
+ if (cfg.method !== 'publish') return
11
+
12
+ const topic = cfg.reqOpts.topic
13
+ const span = this.startSpan('pubsub.request', { // TODO: rename
14
+ service: this.config.service || `${this.tracer._service}-pubsub`,
15
+ resource: `${cfg.method} ${topic}`,
16
+ kind: 'producer',
17
+ meta: {
18
+ 'component': '@google-cloud/pubsub',
19
+ 'gcloud.project_id': projectId,
20
+ 'pubsub.method': cfg.method, // TODO: remove
21
+ 'pubsub.topic': topic
22
+ }
23
+ })
24
+
25
+ for (const msg of messages) {
26
+ if (!msg.attributes) {
27
+ msg.attributes = {}
28
+ }
29
+ this.tracer.inject(span, 'text_map', msg.attributes)
30
+ }
31
+ }
32
+ }
33
+
34
+ module.exports = GoogleCloudPubsubProducerPlugin
@@ -0,0 +1,73 @@
1
+ 'use strict'
2
+
3
+ const TracingPlugin = require('../../dd-trace/src/plugins/tracing')
4
+
5
+ let tools
6
+
7
+ class GraphQLExecutePlugin extends TracingPlugin {
8
+ static get name () { return 'graphql' }
9
+ static get operation () { return 'execute' }
10
+
11
+ start ({ operation, args, docSource }) {
12
+ const type = operation && operation.operation
13
+ const name = operation && operation.name && operation.name.value
14
+ const document = args.document
15
+ const source = this.config.source && document && docSource
16
+
17
+ const span = this.startSpan('graphql.execute', {
18
+ service: this.config.service,
19
+ resource: getSignature(document, name, type, this.config.signature),
20
+ kind: 'server',
21
+ type: 'graphql',
22
+ meta: {
23
+ 'graphql.operation.type': type,
24
+ 'graphql.operation.name': name,
25
+ 'graphql.source': source
26
+ }
27
+ })
28
+
29
+ addVariableTags(this.config, span, args.variableValues)
30
+ }
31
+
32
+ finish ({ res, args }) {
33
+ const span = this.activeSpan
34
+ this.config.hooks.execute(span, args, res)
35
+ span.finish()
36
+ }
37
+ }
38
+
39
+ // span-related
40
+
41
+ function addVariableTags (config, span, variableValues) {
42
+ const tags = {}
43
+
44
+ if (variableValues && config.variables) {
45
+ const variables = config.variables(variableValues)
46
+ for (const param in variables) {
47
+ tags[`graphql.variables.${param}`] = variables[param]
48
+ }
49
+ }
50
+
51
+ span.addTags(tags)
52
+ }
53
+
54
+ function getSignature (document, operationName, operationType, calculate) {
55
+ if (calculate !== false && tools !== false) {
56
+ try {
57
+ try {
58
+ tools = tools || require('./tools')
59
+ } catch (e) {
60
+ tools = false
61
+ throw e
62
+ }
63
+
64
+ return tools.defaultEngineReportingSignature(document, operationName)
65
+ } catch (e) {
66
+ // safety net
67
+ }
68
+ }
69
+
70
+ return [operationType, operationName].filter(val => val).join(' ')
71
+ }
72
+
73
+ module.exports = GraphQLExecutePlugin
@@ -1,111 +1,25 @@
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 CompositePlugin = require('../../dd-trace/src/plugins/composite')
6
4
  const log = require('../../dd-trace/src/log')
5
+ const GraphQLExecutePlugin = require('./execute')
6
+ const GraphQLParsePlugin = require('./parse')
7
+ const GraphQLValidatePlugin = require('./validate')
7
8
  const GraphQLResolvePlugin = require('./resolve')
8
9
 
9
- let tools
10
- class GraphQLPlugin extends Plugin {
11
- static get name () {
12
- return 'graphql'
13
- }
14
-
15
- constructor (...args) {
16
- super(...args)
17
-
18
- /** Execute Subs */
19
-
20
- // resolve plugin separated for disabling purposes
21
- this.resolve = new GraphQLResolvePlugin(...args)
22
-
23
- this.addSub('apm:graphql:execute:start', ({ operation, args, docSource }) => {
24
- const store = storage.getStore()
25
- const span = startSpan('execute', this.config, this.tracer, store)
26
-
27
- // process add tags
28
- addExecutionTags(span, this.config, operation, args.document)
29
- addDocumentTags(span, args.document, this.config, docSource)
30
- addVariableTags(this.config, span, args.variableValues)
31
-
32
- analyticsSampler.sample(span, this.config.measured, true)
33
-
34
- this.enter(span, store)
35
- })
36
-
37
- this.addSub('apm:graphql:execute:error', this.addError)
38
-
39
- this.addSub('apm:graphql:execute:finish', ({ res, args }) => {
40
- const span = storage.getStore().span
41
- this.config.hooks.execute(span, args, res)
42
- span.finish()
43
- })
44
-
45
- /** Parser Subs */
46
-
47
- this.addSub('apm:graphql:parser:start', () => {
48
- const store = storage.getStore()
49
- const span = startSpan('parse', this.config, this.tracer, store)
50
-
51
- analyticsSampler.sample(span, this.config.measured, true)
52
- this.enter(span, store)
53
- })
54
-
55
- this.addSub('apm:graphql:parser:finish', ({ source, document, docSource }) => {
56
- const span = storage.getStore().span
57
-
58
- const tags = {}
59
- if (this.config.source && document) {
60
- tags['graphql.source'] = docSource
61
- }
62
-
63
- span.addTags(tags)
64
-
65
- this.config.hooks.parse(span, source, document)
66
-
67
- span.finish()
68
- })
69
-
70
- this.addSub('apm:graphql:parser:error', this.addError)
71
-
72
- /** Validate Subs */
73
-
74
- this.addSub('apm:graphql:validate:start', ({ docSource, document }) => {
75
- const store = storage.getStore()
76
- const span = startSpan('validate', this.config, this.tracer, store)
77
-
78
- analyticsSampler.sample(span, this.config.measured, true)
79
-
80
- if (document && document.loc) {
81
- const tags = {}
82
- if (this.config.source && document) {
83
- tags['graphql.source'] = docSource
84
- }
85
-
86
- span.addTags(tags)
87
- }
88
-
89
- this.enter(span, store)
90
- })
91
-
92
- this.addSub('apm:graphql:validate:finish', ({ document, errors }) => {
93
- const span = storage.getStore().span
94
- this.config.hooks.validate(span, document, errors)
95
- span.finish()
96
- })
97
-
98
- this.addSub('apm:graphql:validate:error', this.addError)
10
+ class GraphQLPlugin extends CompositePlugin {
11
+ static get name () { return 'graphql' }
12
+ static get plugins () {
13
+ return {
14
+ execute: GraphQLExecutePlugin,
15
+ parse: GraphQLParsePlugin,
16
+ validate: GraphQLValidatePlugin,
17
+ resolve: GraphQLResolvePlugin
18
+ }
99
19
  }
100
20
 
101
21
  configure (config) {
102
- const validated = validateConfig(config)
103
-
104
- // this will disable resolve subscribers if `config.depth` is set to 0
105
- const resolveConfig = validated.depth === 0 ? false : validated
106
- this.resolve.configure(resolveConfig)
107
-
108
- return super.configure(validated)
22
+ return super.configure(validateConfig(config))
109
23
  }
110
24
  }
111
25
 
@@ -155,80 +69,4 @@ function pick (obj, selectors) {
155
69
  return Object.fromEntries(Object.entries(obj).filter(([key]) => selectors.includes(key)))
156
70
  }
157
71
 
158
- // span-related
159
-
160
- function startSpan (name, conf, tracer, store, options) {
161
- const service = conf.service || tracer._service
162
- const childOf = store ? store.span : store
163
- options = options || {}
164
- return tracer.startSpan(`graphql.${name}`, {
165
- childOf: options.childOf || childOf,
166
- startTime: options.startTime,
167
- tags: {
168
- 'service.name': service,
169
- 'span.type': 'graphql'
170
- }
171
- })
172
- }
173
-
174
- function addExecutionTags (span, config, operation, document) {
175
- const type = operation && operation.operation
176
- const name = operation && operation.name && operation.name.value
177
- const tags = {
178
- 'resource.name': getSignature(document, name, type, config.signature)
179
- }
180
-
181
- if (type) {
182
- tags['graphql.operation.type'] = type
183
- }
184
-
185
- if (name) {
186
- tags['graphql.operation.name'] = name
187
- }
188
-
189
- span.addTags(tags)
190
- }
191
-
192
- function addDocumentTags (span, document, config, docSource) {
193
- const tags = {}
194
-
195
- if (config.source && document) {
196
- tags['graphql.source'] = docSource
197
- }
198
-
199
- span.addTags(tags)
200
- }
201
-
202
- function addVariableTags (config, span, variableValues) {
203
- const tags = {}
204
-
205
- if (variableValues && config.variables) {
206
- const variables = config.variables(variableValues)
207
- for (const param in variables) {
208
- tags[`graphql.variables.${param}`] = variables[param]
209
- }
210
- }
211
-
212
- span.addTags(tags)
213
- }
214
-
215
- function getSignature (document, operationName, operationType, calculate) {
216
- if (calculate !== false && tools !== false) {
217
- try {
218
- try {
219
- tools = tools || require('./tools')
220
- } catch (e) {
221
- tools = false
222
- throw e
223
- }
224
-
225
- return tools.defaultEngineReportingSignature(document, operationName)
226
- } catch (e) {
227
- // safety net
228
- }
229
- }
230
-
231
- return [operationType, operationName].filter(val => val).join(' ')
232
- }
233
-
234
72
  module.exports = GraphQLPlugin
@@ -0,0 +1,32 @@
1
+ 'use strict'
2
+
3
+ const TracingPlugin = require('../../dd-trace/src/plugins/tracing')
4
+
5
+ class GraphQLParsePlugin extends TracingPlugin {
6
+ static get name () { return 'graphql' }
7
+ static get operation () { return 'parser' }
8
+
9
+ start () {
10
+ this.startSpan('graphql.parse', {
11
+ service: this.config.service,
12
+ type: 'graphql',
13
+ meta: {
14
+ 'graphql.source': ''
15
+ }
16
+ })
17
+ }
18
+
19
+ finish ({ source, document, docSource }) {
20
+ const span = this.activeSpan
21
+
22
+ if (this.config.source && document) {
23
+ span.setTag('graphql.source', docSource)
24
+ }
25
+
26
+ this.config.hooks.parse(span, source, document)
27
+
28
+ span.finish()
29
+ }
30
+ }
31
+
32
+ module.exports = GraphQLParsePlugin