dd-trace 2.7.0 → 2.9.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 (91) hide show
  1. package/LICENSE-3rdparty.csv +1 -2
  2. package/ci/init.js +22 -6
  3. package/ci/jest/env.js +19 -7
  4. package/ext/tags.d.ts +1 -0
  5. package/ext/tags.js +2 -1
  6. package/index.d.ts +4 -2
  7. package/package.json +3 -5
  8. package/packages/datadog-core/src/storage/async_resource.js +1 -1
  9. package/packages/datadog-instrumentations/index.js +3 -0
  10. package/packages/datadog-instrumentations/src/amqp10.js +33 -32
  11. package/packages/datadog-instrumentations/src/amqplib.js +16 -11
  12. package/packages/datadog-instrumentations/src/aws-sdk.js +105 -0
  13. package/packages/datadog-instrumentations/src/cassandra-driver.js +53 -51
  14. package/packages/datadog-instrumentations/src/connect.js +5 -5
  15. package/packages/datadog-instrumentations/src/couchbase.js +41 -39
  16. package/packages/datadog-instrumentations/src/cucumber.js +38 -38
  17. package/packages/datadog-instrumentations/src/dns.js +20 -19
  18. package/packages/datadog-instrumentations/src/elasticsearch.js +30 -32
  19. package/packages/datadog-instrumentations/src/fastify.js +75 -87
  20. package/packages/datadog-instrumentations/src/hapi.js +210 -0
  21. package/packages/datadog-instrumentations/src/http/client.js +44 -44
  22. package/packages/datadog-instrumentations/src/http/server.js +15 -13
  23. package/packages/datadog-instrumentations/src/ioredis.js +16 -17
  24. package/packages/datadog-instrumentations/src/jest.js +5 -5
  25. package/packages/datadog-instrumentations/src/koa.js +13 -10
  26. package/packages/datadog-instrumentations/src/memcached.js +14 -12
  27. package/packages/datadog-instrumentations/src/mocha.js +37 -39
  28. package/packages/datadog-instrumentations/src/moleculer/client.js +46 -0
  29. package/packages/datadog-instrumentations/src/moleculer/server.js +59 -0
  30. package/packages/datadog-instrumentations/src/moleculer.js +4 -0
  31. package/packages/datadog-instrumentations/src/mongodb-core.js +29 -33
  32. package/packages/datadog-instrumentations/src/mysql.js +30 -29
  33. package/packages/datadog-instrumentations/src/mysql2.js +8 -9
  34. package/packages/datadog-instrumentations/src/net.js +23 -24
  35. package/packages/datadog-instrumentations/src/pg.js +30 -30
  36. package/packages/datadog-instrumentations/src/redis.js +49 -47
  37. package/packages/datadog-instrumentations/src/rhea.js +51 -49
  38. package/packages/datadog-instrumentations/src/router.js +5 -5
  39. package/packages/datadog-instrumentations/src/sharedb.js +20 -20
  40. package/packages/datadog-instrumentations/src/tedious.js +19 -19
  41. package/packages/datadog-plugin-amqp10/src/index.js +2 -7
  42. package/packages/datadog-plugin-amqplib/src/index.js +1 -2
  43. package/packages/datadog-plugin-aws-sdk/src/base.js +146 -0
  44. package/packages/datadog-plugin-aws-sdk/src/index.js +16 -106
  45. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +4 -2
  46. package/packages/datadog-plugin-aws-sdk/src/services/default.js +7 -0
  47. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +3 -1
  48. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +5 -4
  49. package/packages/datadog-plugin-aws-sdk/src/services/index.js +12 -0
  50. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +4 -3
  51. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +4 -3
  52. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +3 -1
  53. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +3 -1
  54. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +4 -3
  55. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +45 -6
  56. package/packages/datadog-plugin-cassandra-driver/src/index.js +1 -5
  57. package/packages/datadog-plugin-couchbase/src/index.js +3 -4
  58. package/packages/datadog-plugin-cucumber/src/index.js +1 -9
  59. package/packages/datadog-plugin-dns/src/index.js +3 -4
  60. package/packages/datadog-plugin-elasticsearch/src/index.js +1 -5
  61. package/packages/datadog-plugin-hapi/src/index.js +34 -3
  62. package/packages/datadog-plugin-http/src/client.js +1 -3
  63. package/packages/datadog-plugin-http/src/server.js +0 -4
  64. package/packages/datadog-plugin-http2/src/server.js +3 -1
  65. package/packages/datadog-plugin-jest/src/index.js +2 -3
  66. package/packages/datadog-plugin-kafkajs/src/index.js +0 -4
  67. package/packages/datadog-plugin-memcached/src/index.js +1 -5
  68. package/packages/datadog-plugin-mocha/src/index.js +3 -7
  69. package/packages/datadog-plugin-moleculer/src/client.js +34 -44
  70. package/packages/datadog-plugin-moleculer/src/index.js +32 -3
  71. package/packages/datadog-plugin-moleculer/src/server.js +28 -50
  72. package/packages/datadog-plugin-mongodb-core/src/index.js +1 -5
  73. package/packages/datadog-plugin-mysql/src/index.js +19 -12
  74. package/packages/datadog-plugin-net/src/index.js +3 -7
  75. package/packages/datadog-plugin-pg/src/index.js +1 -5
  76. package/packages/datadog-plugin-redis/src/index.js +1 -5
  77. package/packages/datadog-plugin-rhea/src/index.js +1 -5
  78. package/packages/datadog-plugin-router/src/index.js +1 -1
  79. package/packages/datadog-plugin-sharedb/src/index.js +1 -5
  80. package/packages/datadog-plugin-tedious/src/index.js +1 -5
  81. package/packages/dd-trace/lib/version.js +1 -1
  82. package/packages/dd-trace/src/appsec/callbacks/ddwaf.js +2 -1
  83. package/packages/dd-trace/src/appsec/index.js +3 -3
  84. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +3 -1
  85. package/packages/dd-trace/src/plugins/plugin.js +0 -8
  86. package/packages/dd-trace/src/plugins/util/test.js +5 -1
  87. package/packages/dd-trace/src/plugins/util/web.js +3 -1
  88. package/scripts/install_plugin_modules.js +25 -15
  89. package/packages/datadog-plugin-aws-sdk/src/helpers.js +0 -103
  90. package/packages/datadog-plugin-hapi/src/route.js +0 -75
  91. package/packages/datadog-plugin-hapi/src/server.js +0 -204
@@ -55,18 +55,15 @@ async function assertVersions () {
55
55
  const plugin = plugins[key]
56
56
  if (plugin.prototype instanceof Plugin) {
57
57
  const instrumentations = []
58
- const instrument = {
59
- addHook (instrumentation) {
60
- instrumentations.push(instrumentation)
61
- }
58
+ const name = plugin.name
59
+
60
+ try {
61
+ loadInstFile(`${name}/server.js`, instrumentations)
62
+ loadInstFile(`${name}/client.js`, instrumentations)
63
+ } catch (e) {
64
+ loadInstFile(`${name}.js`, instrumentations)
62
65
  }
63
- const instPath = path.join(
64
- __dirname,
65
- `../packages/datadog-instrumentations/src/${plugin.name}.js`
66
- )
67
- proxyquire.noPreserveCache()(instPath, {
68
- './helpers/instrument': instrument
69
- })
66
+
70
67
  return instrumentations
71
68
  } else {
72
69
  return plugin
@@ -81,15 +78,13 @@ async function assertVersions () {
81
78
  const externalNames = Object.keys(externals).filter(name => ~names.indexOf(name))
82
79
  for (const name of externalNames) {
83
80
  for (const inst of [].concat(externals[name])) {
84
- if (!inst.dep) {
85
- await assertInstrumentation(inst, true)
86
- }
81
+ await assertInstrumentation(inst, true)
87
82
  }
88
83
  }
89
84
  }
90
85
 
91
86
  async function assertInstrumentation (instrumentation, external) {
92
- const versions = [].concat(instrumentation.versions)
87
+ const versions = [].concat(instrumentation.versions || [])
93
88
  for (const version of versions) {
94
89
  if (version) {
95
90
  await assertModules(instrumentation.name, semver.coerce(version).version, external)
@@ -230,3 +225,18 @@ function sha1 (str) {
230
225
  shasum.update(str)
231
226
  return shasum.digest('hex')
232
227
  }
228
+
229
+ function loadInstFile (file, instrumentations) {
230
+ const instrument = {
231
+ addHook (instrumentation) {
232
+ instrumentations.push(instrumentation)
233
+ }
234
+ }
235
+
236
+ const instPath = path.join(__dirname, `../packages/datadog-instrumentations/src/${file}`)
237
+
238
+ proxyquire.noPreserveCache()(instPath, {
239
+ './helpers/instrument': instrument,
240
+ '../helpers/instrument': instrument
241
+ })
242
+ }
@@ -1,103 +0,0 @@
1
- 'use strict'
2
-
3
- const Tags = require('opentracing').Tags
4
-
5
- const services = {
6
- cloudwatchlogs: getService(require('./services/cloudwatchlogs')),
7
- dynamodb: getService(require('./services/dynamodb')),
8
- kinesis: getService(require('./services/kinesis')),
9
- lambda: getService(require('./services/lambda')),
10
- s3: getService(require('./services/s3')),
11
- redshift: getService(require('./services/redshift')),
12
- sns: getService(require('./services/sns')),
13
- sqs: getService(require('./services/sqs')),
14
- eventbridge: getService(require('./services/eventbridge'))
15
- }
16
-
17
- function getService (Service) {
18
- return new Service()
19
- }
20
-
21
- const helpers = {
22
- finish (config, span, response, err) {
23
- if (err) {
24
- span.setTag('error', err)
25
-
26
- if (err.requestId) {
27
- span.addTags({ 'aws.response.request_id': err.requestId })
28
- }
29
- }
30
-
31
- config.hooks.request(span, response)
32
-
33
- span.finish()
34
- },
35
-
36
- isEnabled (serviceIdentifier, config, request) {
37
- if (typeof config === 'boolean') {
38
- return config
39
- } else if (!config || typeof config !== 'object' || !services[serviceIdentifier]) {
40
- return true
41
- }
42
-
43
- return services[serviceIdentifier].isEnabled
44
- ? services[serviceIdentifier].isEnabled(config, request)
45
- : true
46
- },
47
-
48
- addResponseTags (span, response, serviceName) {
49
- if (!span) return
50
-
51
- if (response.request) {
52
- this.addServicesTags(span, response, serviceName)
53
- }
54
- },
55
-
56
- addServicesTags (span, response, serviceName) {
57
- if (!span) return
58
-
59
- const params = response.request.params
60
- const operation = response.request.operation
61
- const extraTags = services[serviceName] ? services[serviceName].generateTags(params, operation, response) : {}
62
- const tags = Object.assign({
63
- 'aws.response.request_id': response.requestId,
64
- 'resource.name': operation,
65
- 'span.kind': 'client'
66
- }, extraTags)
67
-
68
- span.addTags(tags)
69
- },
70
-
71
- responseExtract (serviceName, request, response, tracer) {
72
- if (services[serviceName] && services[serviceName].responseExtract) {
73
- const params = request.params
74
- const operation = request.operation
75
- return services[serviceName].responseExtract(params, operation, response, tracer)
76
- }
77
- },
78
-
79
- requestInject (span, request, serviceName, tracer) {
80
- if (!span) return
81
-
82
- const service = services[serviceName] && services[serviceName]
83
- if (service && service.requestInject) service.requestInject(span, request, tracer)
84
- },
85
-
86
- wrapCb (cb, serviceName, tags, request, tracer, childOf) {
87
- const awsHelpers = this
88
- return function wrappedCb (err, resp) {
89
- const maybeChildOf = awsHelpers.responseExtract(serviceName, request, resp, tracer)
90
- if (maybeChildOf) {
91
- const options = {
92
- childOf: maybeChildOf,
93
- tags: Object.assign({}, tags, { [Tags.SPAN_KIND]: 'server' })
94
- }
95
- return tracer.wrap('aws.response', options, cb).apply(this, arguments)
96
- } else {
97
- return tracer.scope().bind(cb, childOf).apply(this, arguments)
98
- }
99
- }
100
- }
101
- }
102
-
103
- module.exports = helpers
@@ -1,75 +0,0 @@
1
- 'use strict'
2
-
3
- const web = require('../../dd-trace/src/plugins/util/web')
4
-
5
- function createWrapRebuild () {
6
- return function wrapRebuild (rebuild) {
7
- return function rebuildWithTrace (event) {
8
- const result = rebuild.apply(this, arguments)
9
-
10
- if (this && Array.isArray(this._cycle)) {
11
- this._cycle = this._cycle.map(wrapMiddleware)
12
- }
13
-
14
- return result
15
- }
16
- }
17
- }
18
-
19
- function createWrapLifecycle () {
20
- return function wrapLifecycle (lifecycle) {
21
- return function lifecycleWithTrace () {
22
- const result = lifecycle.apply(this, arguments)
23
-
24
- if (Array.isArray(result)) return result.map(wrapMiddleware)
25
-
26
- return result
27
- }
28
- }
29
- }
30
-
31
- function wrapMiddleware (middleware) {
32
- if (typeof middleware !== 'function') return middleware
33
-
34
- return function (request, next) {
35
- if (!request || !request.raw) return middleware.apply(this, arguments)
36
-
37
- return web.reactivate(request.raw.req, () => middleware.apply(this, arguments))
38
- }
39
- }
40
-
41
- module.exports = [
42
- {
43
- name: '@hapi/hapi',
44
- versions: ['>=17.9'],
45
- file: 'lib/route.js',
46
- patch (Route, tracer, config) {
47
- this.wrap(Route.prototype, 'rebuild', createWrapRebuild(tracer, config))
48
- },
49
- unpatch (Route) {
50
- this.unwrap(Route.prototype, 'rebuild')
51
- }
52
- },
53
- {
54
- name: 'hapi',
55
- versions: ['>=10.4'],
56
- file: 'lib/route.js',
57
- patch (Route, tracer, config) {
58
- this.wrap(Route.prototype, 'rebuild', createWrapRebuild(tracer, config))
59
- },
60
- unpatch (Route) {
61
- this.unwrap(Route.prototype, 'rebuild')
62
- }
63
- },
64
- {
65
- name: 'hapi',
66
- versions: ['2 - 10.3'],
67
- file: 'lib/route.js',
68
- patch (Route, tracer, config) {
69
- this.wrap(Route.prototype, 'lifecycle', createWrapLifecycle(tracer, config))
70
- },
71
- unpatch (Route) {
72
- this.unwrap(Route.prototype, 'lifecycle')
73
- }
74
- }
75
- ]
@@ -1,204 +0,0 @@
1
- 'use strict'
2
-
3
- const web = require('../../dd-trace/src/plugins/util/web')
4
-
5
- function createWrapDispatch (tracer, config) {
6
- config = web.normalizeConfig(config)
7
-
8
- return function wrapDispatch (dispatch) {
9
- return function dispatchWithTrace (options) {
10
- const handler = dispatch.apply(this, arguments)
11
-
12
- if (typeof handler !== 'function') return handler
13
-
14
- return function (req, res) {
15
- return web.instrument(tracer, config, req, res, 'hapi.request', () => {
16
- return handler.apply(this, arguments)
17
- })
18
- }
19
- }
20
- }
21
- }
22
-
23
- function createWrapServer (tracer) {
24
- return function wrapServer (server) {
25
- return function serverWithTrace (options) {
26
- const app = server.apply(this, arguments)
27
-
28
- if (!app) return app
29
-
30
- if (typeof app.ext === 'function') {
31
- app.ext = createWrapExt(tracer)(app.ext)
32
- }
33
-
34
- if (typeof app.start === 'function') {
35
- app.start = createWrapStart(tracer)(app.start)
36
- }
37
-
38
- return app
39
- }
40
- }
41
- }
42
-
43
- function createWrapStart () {
44
- return function wrapStart (start) {
45
- return function startWithTrace () {
46
- if (this && typeof this.ext === 'function') {
47
- this.ext('onPreResponse', onPreResponse)
48
- }
49
-
50
- return start.apply(this, arguments)
51
- }
52
- }
53
- }
54
-
55
- function createWrapExt () {
56
- return function wrapExt (ext) {
57
- return function extWithTrace (events, method, options) {
58
- if (typeof events === 'object') {
59
- arguments[0] = wrapEvents(events)
60
- } else {
61
- arguments[1] = wrapExtension(method)
62
- }
63
-
64
- return ext.apply(this, arguments)
65
- }
66
- }
67
- }
68
-
69
- function wrapExtension (method) {
70
- return [].concat(method).map(wrapHandler)
71
- }
72
-
73
- function wrapEvents (events) {
74
- return [].concat(events).map(event => {
75
- if (!event || !event.method) return event
76
-
77
- return Object.assign({}, event, {
78
- method: wrapExtension(event.method)
79
- })
80
- })
81
- }
82
-
83
- function wrapHandler (handler) {
84
- if (typeof handler !== 'function') return handler
85
-
86
- return function (request, h) {
87
- if (!request || !request.raw) return handler.apply(this, arguments)
88
-
89
- return web.reactivate(request.raw.req, () => handler.apply(this, arguments))
90
- }
91
- }
92
-
93
- function onPreResponse (request, h) {
94
- if (!request || !request.raw) return reply(request, h)
95
-
96
- const req = request.raw.req
97
-
98
- web.addError(req, request.response)
99
-
100
- if (request.route) {
101
- web.enterRoute(req, request.route.path)
102
- }
103
-
104
- return reply(request, h)
105
- }
106
-
107
- function reply (request, h) {
108
- if (h.continue) {
109
- return typeof h.continue === 'function'
110
- ? h.continue()
111
- : h.continue
112
- } else if (typeof h === 'function') {
113
- return h()
114
- }
115
- }
116
-
117
- module.exports = [
118
- {
119
- name: '@hapi/hapi',
120
- versions: ['>=17.9'],
121
- patch (hapi, tracer, config) {
122
- this.wrap(hapi, ['server', 'Server'], createWrapServer(tracer, config))
123
- },
124
- unpatch (hapi) {
125
- this.unwrap(hapi, ['server', 'Server'])
126
- }
127
- },
128
- {
129
- name: 'hapi',
130
- versions: ['>=17'],
131
- patch (hapi, tracer, config) {
132
- this.wrap(hapi, ['server', 'Server'], createWrapServer(tracer, config))
133
- },
134
- unpatch (hapi) {
135
- this.unwrap(hapi, ['server', 'Server'])
136
- }
137
- },
138
- {
139
- name: 'hapi',
140
- versions: ['2 - 7.1', '8 - 16'],
141
- patch (hapi, tracer, config) {
142
- this.wrap(hapi.Server.prototype, 'start', createWrapStart(tracer, config))
143
- this.wrap(hapi.Server.prototype, 'ext', createWrapExt(tracer, config))
144
- },
145
- unpatch (hapi) {
146
- this.unwrap(hapi.Server.prototype, 'start')
147
- this.unwrap(hapi.Server.prototype, 'ext')
148
- }
149
- },
150
- {
151
- name: 'hapi',
152
- versions: ['^7.2'],
153
- patch (hapi, tracer, config) {
154
- this.wrap(hapi, 'createServer', createWrapServer(tracer, config))
155
- },
156
- unpatch (hapi) {
157
- this.unwrap(hapi, 'createServer')
158
- }
159
- },
160
- {
161
- name: '@hapi/hapi',
162
- versions: ['>=17.9'],
163
- file: 'lib/core.js',
164
- patch (Core, tracer, config) {
165
- this.wrap(Core.prototype, '_dispatch', createWrapDispatch(tracer, config))
166
- },
167
- unpatch (Core) {
168
- this.unwrap(Core.prototype, '_dispatch')
169
- }
170
- },
171
- {
172
- name: 'hapi',
173
- versions: ['7.2 - 16'],
174
- file: 'lib/connection.js',
175
- patch (Connection, tracer, config) {
176
- this.wrap(Connection.prototype, '_dispatch', createWrapDispatch(tracer, config))
177
- },
178
- unpatch (Connection) {
179
- this.unwrap(Connection.prototype, '_dispatch')
180
- }
181
- },
182
- {
183
- name: 'hapi',
184
- versions: ['>=17'],
185
- file: 'lib/core.js',
186
- patch (Core, tracer, config) {
187
- this.wrap(Core.prototype, '_dispatch', createWrapDispatch(tracer, config))
188
- },
189
- unpatch (Core) {
190
- this.unwrap(Core.prototype, '_dispatch')
191
- }
192
- },
193
- {
194
- name: 'hapi',
195
- versions: ['2 - 7.1'],
196
- file: 'lib/server.js',
197
- patch (Server, tracer, config) {
198
- this.wrap(Server.prototype, '_dispatch', createWrapDispatch(tracer, config))
199
- },
200
- unpatch (Server) {
201
- this.unwrap(Server.prototype, '_dispatch')
202
- }
203
- }
204
- ]