dd-trace 3.5.0 → 3.7.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 (94) hide show
  1. package/LICENSE-3rdparty.csv +2 -0
  2. package/index.d.ts +42 -4
  3. package/package.json +5 -3
  4. package/packages/datadog-instrumentations/src/cucumber.js +0 -2
  5. package/packages/datadog-instrumentations/src/elasticsearch.js +51 -47
  6. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +1 -1
  7. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
  8. package/packages/datadog-instrumentations/src/mariadb.js +43 -69
  9. package/packages/datadog-instrumentations/src/mocha.js +14 -18
  10. package/packages/datadog-instrumentations/src/opensearch.js +10 -0
  11. package/packages/datadog-instrumentations/src/pg.js +2 -1
  12. package/packages/datadog-instrumentations/src/rhea.js +20 -17
  13. package/packages/datadog-plugin-amqp10/src/consumer.js +32 -0
  14. package/packages/datadog-plugin-amqp10/src/index.js +11 -101
  15. package/packages/datadog-plugin-amqp10/src/producer.js +34 -0
  16. package/packages/datadog-plugin-amqp10/src/util.js +15 -0
  17. package/packages/datadog-plugin-amqplib/src/client.js +38 -0
  18. package/packages/datadog-plugin-amqplib/src/consumer.js +40 -0
  19. package/packages/datadog-plugin-amqplib/src/index.js +14 -102
  20. package/packages/datadog-plugin-amqplib/src/producer.js +37 -0
  21. package/packages/datadog-plugin-amqplib/src/util.js +14 -0
  22. package/packages/datadog-plugin-dns/src/index.js +16 -91
  23. package/packages/datadog-plugin-dns/src/lookup.js +40 -0
  24. package/packages/datadog-plugin-dns/src/lookup_service.js +24 -0
  25. package/packages/datadog-plugin-dns/src/resolve.js +24 -0
  26. package/packages/datadog-plugin-dns/src/reverse.js +21 -0
  27. package/packages/datadog-plugin-elasticsearch/src/index.js +7 -7
  28. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +25 -0
  29. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +42 -0
  30. package/packages/datadog-plugin-google-cloud-pubsub/src/index.js +14 -99
  31. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +34 -0
  32. package/packages/datadog-plugin-graphql/src/execute.js +73 -0
  33. package/packages/datadog-plugin-graphql/src/index.js +14 -176
  34. package/packages/datadog-plugin-graphql/src/parse.js +32 -0
  35. package/packages/datadog-plugin-graphql/src/resolve.js +70 -76
  36. package/packages/datadog-plugin-graphql/src/validate.js +28 -0
  37. package/packages/datadog-plugin-grpc/src/client.js +46 -55
  38. package/packages/datadog-plugin-grpc/src/index.js +7 -24
  39. package/packages/datadog-plugin-grpc/src/server.js +50 -52
  40. package/packages/datadog-plugin-grpc/src/util.js +15 -14
  41. package/packages/datadog-plugin-http/src/index.js +7 -22
  42. package/packages/datadog-plugin-http2/src/index.js +8 -26
  43. package/packages/datadog-plugin-jest/src/index.js +3 -0
  44. package/packages/datadog-plugin-kafkajs/src/consumer.js +42 -0
  45. package/packages/datadog-plugin-kafkajs/src/index.js +11 -87
  46. package/packages/datadog-plugin-kafkajs/src/producer.js +31 -0
  47. package/packages/datadog-plugin-mocha/src/index.js +2 -2
  48. package/packages/datadog-plugin-moleculer/src/client.js +22 -36
  49. package/packages/datadog-plugin-moleculer/src/index.js +8 -26
  50. package/packages/datadog-plugin-moleculer/src/server.js +18 -30
  51. package/packages/datadog-plugin-mongodb-core/src/index.js +1 -1
  52. package/packages/datadog-plugin-net/src/ipc.js +21 -0
  53. package/packages/datadog-plugin-net/src/tcp.js +46 -0
  54. package/packages/datadog-plugin-opensearch/src/index.js +11 -0
  55. package/packages/datadog-plugin-pg/src/index.js +2 -1
  56. package/packages/datadog-plugin-rhea/src/consumer.js +55 -0
  57. package/packages/datadog-plugin-rhea/src/index.js +11 -99
  58. package/packages/datadog-plugin-rhea/src/producer.js +45 -0
  59. package/packages/datadog-plugin-sharedb/src/index.js +22 -39
  60. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +1 -1
  61. package/packages/dd-trace/src/appsec/iast/index.js +4 -6
  62. package/packages/dd-trace/src/appsec/iast/path-line.js +3 -0
  63. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +2 -5
  64. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +2 -5
  65. package/packages/dd-trace/src/config.js +26 -6
  66. package/packages/dd-trace/src/constants.js +3 -0
  67. package/packages/dd-trace/src/dogstatsd.js +42 -10
  68. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +10 -2
  69. package/packages/dd-trace/src/exporters/agent/index.js +6 -2
  70. package/packages/dd-trace/src/exporters/agent/writer.js +2 -9
  71. package/packages/dd-trace/src/exporters/common/request.js +12 -0
  72. package/packages/dd-trace/src/exporters/span-stats/index.js +6 -2
  73. package/packages/dd-trace/src/format.js +13 -0
  74. package/packages/dd-trace/src/metrics.js +15 -2
  75. package/packages/dd-trace/src/opentracing/span.js +2 -1
  76. package/packages/dd-trace/src/plugins/client.js +3 -1
  77. package/packages/dd-trace/src/plugins/composite.js +26 -0
  78. package/packages/dd-trace/src/plugins/consumer.js +9 -0
  79. package/packages/dd-trace/src/plugins/incoming.js +7 -0
  80. package/packages/dd-trace/src/plugins/index.js +1 -0
  81. package/packages/dd-trace/src/plugins/outgoing.js +1 -1
  82. package/packages/dd-trace/src/plugins/producer.js +9 -0
  83. package/packages/dd-trace/src/plugins/server.js +9 -0
  84. package/packages/dd-trace/src/plugins/storage.js +0 -4
  85. package/packages/dd-trace/src/plugins/tracing.js +9 -9
  86. package/packages/dd-trace/src/profiling/config.js +8 -5
  87. package/packages/dd-trace/src/profiling/profiler.js +8 -1
  88. package/packages/dd-trace/src/span_processor.js +3 -0
  89. package/packages/dd-trace/src/span_sampler.js +80 -0
  90. package/packages/dd-trace/src/span_stats.js +2 -2
  91. package/packages/dd-trace/src/telemetry/dependencies.js +10 -6
  92. package/packages/dd-trace/src/telemetry/send-data.js +3 -1
  93. package/packages/dd-trace/src/tracer.js +6 -2
  94. package/packages/dd-trace/src/util.js +43 -1
@@ -20,6 +20,7 @@ require,methods,MIT,Copyright 2013-2014 TJ Holowaychuk
20
20
  require,module-details-from-path,MIT,Copyright 2016 Thomas Watson Steen
21
21
  require,opentracing,MIT,Copyright 2016 Resonance Labs Inc
22
22
  require,path-to-regexp,MIT,Copyright 2014 Blake Embrey
23
+ require,protobufjs,BSD-3-Clause,Copyright 2016 Daniel Wirtz
23
24
  require,retry,MIT,Copyright 2011 Tim Koschützki Felix Geisendörfer
24
25
  require,semver,ISC,Copyright Isaac Z. Schlueter and Contributors
25
26
  dev,@types/node,MIT,Copyright Authors
@@ -52,6 +53,7 @@ dev,multer,MIT,Copyright 2014 Hage Yaapa
52
53
  dev,msgpack-lite,MIT,Copyright 2015 Yusuke Kawasaki
53
54
  dev,nock,MIT,Copyright 2017 Pedro Teixeira and other contributors
54
55
  dev,nyc,ISC,Copyright 2015 Contributors
56
+ dev,pprof-format,MIT,Copyright 2022 Stephen Belanger
55
57
  dev,proxyquire,MIT,Copyright 2013 Thorsten Lorenz
56
58
  dev,rimraf,ISC,Copyright Isaac Z. Schlueter and Contributors
57
59
  dev,sinon,BSD-3-Clause,Copyright 2010-2017 Christian Johansen
package/index.d.ts CHANGED
@@ -176,7 +176,7 @@ export declare interface SamplingRule {
176
176
  /**
177
177
  * Sampling rate for this rule.
178
178
  */
179
- sampleRate: Number
179
+ sampleRate: number
180
180
 
181
181
  /**
182
182
  * Service on which to apply this rule. The rule will apply to all services if not provided.
@@ -189,6 +189,31 @@ export declare interface SamplingRule {
189
189
  name?: string | RegExp
190
190
  }
191
191
 
192
+ /**
193
+ * Span sampling rules to ingest single spans where the enclosing trace is dropped
194
+ */
195
+ export declare interface SpanSamplingRule {
196
+ /**
197
+ * Sampling rate for this rule. Will default to 1.0 (always) if not provided.
198
+ */
199
+ sampleRate?: number
200
+
201
+ /**
202
+ * Maximum number of spans matching a span sampling rule to be allowed per second.
203
+ */
204
+ maxPerSecond?: number
205
+
206
+ /**
207
+ * Service name or pattern on which to apply this rule. The rule will apply to all services if not provided.
208
+ */
209
+ service?: string
210
+
211
+ /**
212
+ * Operation name or pattern on which to apply this rule. The rule will apply to all operation names if not provided.
213
+ */
214
+ name?: string
215
+ }
216
+
192
217
  /**
193
218
  * List of options available to the tracer.
194
219
  */
@@ -272,7 +297,7 @@ export declare interface TracerOptions {
272
297
  * and controls the ingestion rate limit between the agent and the backend.
273
298
  * Defaults to deferring the decision to the agent.
274
299
  */
275
- rateLimit?: Number,
300
+ rateLimit?: number,
276
301
 
277
302
  /**
278
303
  * Sampling rules to apply to priority samplin. Each rule is a JSON,
@@ -283,6 +308,12 @@ export declare interface TracerOptions {
283
308
  */
284
309
  samplingRules?: SamplingRule[]
285
310
 
311
+ /**
312
+ * Span sampling rules that take effect when the enclosing trace is dropped, to ingest single spans
313
+ * @default []
314
+ */
315
+ spanSamplingRules?: SpanSamplingRule[]
316
+
286
317
  /**
287
318
  * Interval in milliseconds at which the tracer will submit traces to the agent.
288
319
  * @default 2000
@@ -598,6 +629,7 @@ interface Plugins {
598
629
  "mysql2": plugins.mysql2;
599
630
  "net": plugins.net;
600
631
  "next": plugins.next;
632
+ "opensearch": plugins.opensearch;
601
633
  "oracledb": plugins.oracledb;
602
634
  "paperplane": plugins.paperplane;
603
635
  "pg": plugins.pg;
@@ -730,7 +762,7 @@ declare namespace plugins {
730
762
  * status code as its only parameter and return `true` for success or `false`
731
763
  * for errors.
732
764
  *
733
- * @default code => code < 400
765
+ * @default code => code < 400 || code >= 500
734
766
  */
735
767
  validateStatus?: (code: number) => boolean;
736
768
 
@@ -764,7 +796,7 @@ declare namespace plugins {
764
796
  * status code as its only parameter and return `true` for success or `false`
765
797
  * for errors.
766
798
  *
767
- * @default code => code < 400
799
+ * @default code => code < 400 || code >= 500
768
800
  */
769
801
  validateStatus?: (code: number) => boolean;
770
802
  }
@@ -1255,6 +1287,12 @@ declare namespace plugins {
1255
1287
  };
1256
1288
  }
1257
1289
 
1290
+ /**
1291
+ * This plugin automatically instruments the
1292
+ * [opensearch](https://github.com/opensearch-project/opensearch-js) module.
1293
+ */
1294
+ interface opensearch extends elasticsearch {}
1295
+
1258
1296
  /**
1259
1297
  * This plugin automatically instruments the
1260
1298
  * [oracledb](https://github.com/oracle/node-oracledb) module.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "3.5.0",
3
+ "version": "3.7.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -59,8 +59,8 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "@datadog/native-appsec": "^1.2.1",
62
- "@datadog/native-metrics": "^1.4.3",
63
- "@datadog/pprof": "^1.0.2",
62
+ "@datadog/native-metrics": "^1.5.0",
63
+ "@datadog/pprof": "^1.1.0",
64
64
  "@datadog/sketches-js": "^2.1.0",
65
65
  "crypto-randomuuid": "^1.0.0",
66
66
  "diagnostics_channel": "^1.1.0",
@@ -79,6 +79,7 @@
79
79
  "module-details-from-path": "^1.0.3",
80
80
  "opentracing": ">=0.12.1",
81
81
  "path-to-regexp": "^0.1.2",
82
+ "protobufjs": "^7.1.2",
82
83
  "retry": "^0.10.1",
83
84
  "semver": "^5.5.0"
84
85
  },
@@ -113,6 +114,7 @@
113
114
  "multer": "^1.4.5-lts.1",
114
115
  "nock": "^11.3.3",
115
116
  "nyc": "^15.1.0",
117
+ "pprof-format": "^2.0.4",
116
118
  "proxyquire": "^1.8.0",
117
119
  "rimraf": "^3.0.0",
118
120
  "sinon": "^11.1.2",
@@ -142,5 +142,3 @@ addHook({
142
142
 
143
143
  return Runtime
144
144
  })
145
-
146
- module.exports = { pickleHook, testCaseHook }
@@ -7,76 +7,80 @@ const {
7
7
  } = require('./helpers/instrument')
8
8
  const shimmer = require('../../datadog-shimmer')
9
9
 
10
- const startCh = channel('apm:elasticsearch:query:start')
11
- const finishCh = channel('apm:elasticsearch:query:finish')
12
- const errorCh = channel('apm:elasticsearch:query:error')
13
-
14
10
  addHook({ name: '@elastic/transport', file: 'lib/Transport.js', versions: ['>=8'] }, (exports) => {
15
- shimmer.wrap(exports.default.prototype, 'request', wrapRequest)
11
+ shimmer.wrap(exports.default.prototype, 'request', createWrapRequest('elasticsearch'))
16
12
  return exports
17
13
  })
18
14
 
19
15
  addHook({ name: '@elastic/elasticsearch', file: 'lib/Transport.js', versions: ['>=5.6.16 <8', '>=8'] }, Transport => {
20
- shimmer.wrap(Transport.prototype, 'request', wrapRequest)
16
+ shimmer.wrap(Transport.prototype, 'request', createWrapRequest('elasticsearch'))
21
17
  return Transport
22
18
  })
23
19
 
24
20
  addHook({ name: 'elasticsearch', file: 'src/lib/transport.js', versions: ['>=10'] }, Transport => {
25
- shimmer.wrap(Transport.prototype, 'request', wrapRequest)
21
+ shimmer.wrap(Transport.prototype, 'request', createWrapRequest('elasticsearch'))
26
22
  return Transport
27
23
  })
28
24
 
29
- function wrapRequest (request) {
30
- return function (params, options, cb) {
31
- if (!startCh.hasSubscribers) {
32
- return request.apply(this, arguments)
33
- }
25
+ function createWrapRequest (name) {
26
+ const startCh = channel(`apm:${name}:query:start`)
27
+ const finishCh = channel(`apm:${name}:query:finish`)
28
+ const errorCh = channel(`apm:${name}:query:error`)
34
29
 
35
- if (!params) return request.apply(this, arguments)
30
+ return function wrapRequest (request) {
31
+ return function (params, options, cb) {
32
+ if (!startCh.hasSubscribers) {
33
+ return request.apply(this, arguments)
34
+ }
36
35
 
37
- const parentResource = new AsyncResource('bound-anonymous-fn')
38
- const asyncResource = new AsyncResource('bound-anonymous-fn')
36
+ if (!params) return request.apply(this, arguments)
39
37
 
40
- return asyncResource.runInAsyncScope(() => {
41
- startCh.publish({ params })
38
+ const parentResource = new AsyncResource('bound-anonymous-fn')
39
+ const asyncResource = new AsyncResource('bound-anonymous-fn')
42
40
 
43
- try {
44
- const lastIndex = arguments.length - 1
45
- cb = arguments[lastIndex]
41
+ return asyncResource.runInAsyncScope(() => {
42
+ startCh.publish({ params })
46
43
 
47
- if (typeof cb === 'function') {
48
- cb = parentResource.bind(cb)
44
+ try {
45
+ const lastIndex = arguments.length - 1
46
+ cb = arguments[lastIndex]
49
47
 
50
- arguments[lastIndex] = asyncResource.bind(function (error) {
51
- finish(params, error)
52
- return cb.apply(null, arguments)
53
- })
54
- return request.apply(this, arguments)
55
- } else {
56
- const promise = request.apply(this, arguments)
57
- if (promise && typeof promise.then === 'function') {
58
- const onResolve = asyncResource.bind(() => finish(params))
59
- const onReject = asyncResource.bind(e => finish(params, e))
48
+ if (typeof cb === 'function') {
49
+ cb = parentResource.bind(cb)
60
50
 
61
- promise.then(onResolve, onReject)
51
+ arguments[lastIndex] = asyncResource.bind(function (error) {
52
+ finish(params, error)
53
+ return cb.apply(null, arguments)
54
+ })
55
+ return request.apply(this, arguments)
62
56
  } else {
63
- finish(params)
57
+ const promise = request.apply(this, arguments)
58
+ if (promise && typeof promise.then === 'function') {
59
+ const onResolve = asyncResource.bind(() => finish(params))
60
+ const onReject = asyncResource.bind(e => finish(params, e))
61
+
62
+ promise.then(onResolve, onReject)
63
+ } else {
64
+ finish(params)
65
+ }
66
+ return promise
64
67
  }
65
- return promise
66
- }
67
- } catch (err) {
68
- err.stack // trigger getting the stack at the original throwing point
69
- errorCh.publish(err)
68
+ } catch (err) {
69
+ err.stack // trigger getting the stack at the original throwing point
70
+ errorCh.publish(err)
70
71
 
71
- throw err
72
- }
73
- })
72
+ throw err
73
+ }
74
+ })
75
+ }
74
76
  }
75
- }
76
77
 
77
- function finish (params, error) {
78
- if (error) {
79
- errorCh.publish(error)
78
+ function finish (params, error) {
79
+ if (error) {
80
+ errorCh.publish(error)
81
+ }
82
+ finishCh.publish({ params })
80
83
  }
81
- finishCh.publish({ params })
82
84
  }
85
+
86
+ module.exports = { createWrapRequest }
@@ -65,7 +65,7 @@ addHook({ name: '@google-cloud/pubsub', versions: ['>=1.2'] }, (obj) => {
65
65
  try {
66
66
  return emit.apply(this, arguments)
67
67
  } catch (err) {
68
- receiveErrorCh.publish({ err, message })
68
+ receiveErrorCh.publish(err)
69
69
  throw err
70
70
  }
71
71
  })
@@ -10,6 +10,7 @@ module.exports = {
10
10
  '@jest/core': () => require('../jest'),
11
11
  '@koa/router': () => require('../koa'),
12
12
  '@node-redis/client': () => require('../redis'),
13
+ '@opensearch-project/opensearch': () => require('../opensearch'),
13
14
  '@redis/client': () => require('../redis'),
14
15
  'amqp10': () => require('../amqp10'),
15
16
  'amqplib': () => require('../amqplib'),
@@ -8,82 +8,56 @@ const startCh = channel('apm:mariadb:query:start')
8
8
  const finishCh = channel('apm:mariadb:query:finish')
9
9
  const errorCh = channel('apm:mariadb:query:error')
10
10
 
11
- function wrapConnectionAddCommand (addCommand) {
12
- return function (cmd) {
13
- if (!startCh.hasSubscribers) return addCommand.apply(this, arguments)
11
+ function wrapCommandStart (start) {
12
+ return function () {
13
+ if (!startCh.hasSubscribers) return start.apply(this, arguments)
14
14
 
15
- const asyncResource = new AsyncResource('bound-anonymous-fn')
16
- const name = cmd && cmd.constructor && cmd.constructor.name
17
- const isCommand = typeof cmd.start === 'function'
18
- const isQuery = isCommand && (name === 'Execute' || name === 'Query')
19
-
20
- // TODO: consider supporting all commands and not just queries
21
- cmd.start = isQuery
22
- ? wrapStart(cmd, cmd.start, asyncResource, this.opts)
23
- : bindStart(cmd, cmd.start, asyncResource)
24
-
25
- return asyncResource.bind(addCommand, this).apply(this, arguments)
26
- }
27
- }
15
+ const callbackResource = new AsyncResource('bound-anonymous-fn')
28
16
 
29
- function bindStart (cmd, start, asyncResource) {
30
- return asyncResource.bind(function (packet, connection) {
31
- if (this.resolve) {
32
- this.resolve = asyncResource.bind(this.resolve)
33
- }
17
+ const resolve = callbackResource.bind(this.resolve)
18
+ const reject = callbackResource.bind(this.reject)
34
19
 
35
- if (this.reject) {
36
- this.reject = asyncResource.bind(this.reject)
37
- }
20
+ const asyncResource = new AsyncResource('bound-anonymous-fn')
38
21
 
39
- return start.apply(this, arguments)
40
- }, cmd)
22
+ shimmer.wrap(this, 'resolve', function wrapResolve () {
23
+ return function () {
24
+ asyncResource.runInAsyncScope(() => {
25
+ finishCh.publish()
26
+ })
27
+
28
+ return resolve.apply(this, arguments)
29
+ }
30
+ })
31
+
32
+ shimmer.wrap(this, 'reject', function wrapReject () {
33
+ return function (error) {
34
+ asyncResource.runInAsyncScope(() => {
35
+ errorCh.publish(error)
36
+ finishCh.publish()
37
+ })
38
+
39
+ return reject.apply(this, arguments)
40
+ }
41
+ })
42
+
43
+ return asyncResource.runInAsyncScope(() => {
44
+ startCh.publish({ sql: this.sql, conf: this.opts })
45
+ return start.apply(this, arguments)
46
+ })
47
+ }
41
48
  }
42
49
 
43
- function wrapStart (cmd, start, asyncResource, config) {
44
- const callbackResource = new AsyncResource('bound-anonymous-fn')
50
+ const name = 'mariadb'
51
+ const versions = ['>=2.0.3']
45
52
 
46
- return asyncResource.bind(function (packet, connection) {
47
- if (!this.resolve || !this.reject) return start.apply(this, arguments)
53
+ addHook({ name, file: 'lib/cmd/query.js', versions }, (Query) => {
54
+ shimmer.wrap(Query.prototype, 'start', wrapCommandStart)
48
55
 
49
- const sql = cmd.statement ? cmd.statement.query : cmd.sql
56
+ return Query
57
+ })
50
58
 
51
- startCh.publish({ sql, conf: config })
59
+ addHook({ name, file: 'lib/cmd/execute.js', versions }, (Query) => {
60
+ shimmer.wrap(Query.prototype, 'start', wrapCommandStart)
52
61
 
53
- const resolve = callbackResource.bind(this.resolve)
54
- const reject = callbackResource.bind(this.reject)
55
-
56
- this.resolve = asyncResource.bind(function () {
57
- finishCh.publish(undefined)
58
- resolve.apply(this, arguments)
59
- }, 'bound-anonymous-fn', this)
60
-
61
- this.reject = asyncResource.bind(function (error) {
62
- errorCh.publish(error)
63
- finishCh.publish(undefined)
64
- reject.apply(this, arguments)
65
- }, 'bound-anonymous-fn', this)
66
-
67
- this.start = start
68
-
69
- try {
70
- return start.apply(this, arguments)
71
- } catch (err) {
72
- errorCh.publish(err)
73
- }
74
- }, cmd)
75
- }
76
-
77
- addHook(
78
- {
79
- name: 'mariadb',
80
- file: 'lib/connection.js',
81
- versions: ['>=3']
82
- },
83
- (Connection) => {
84
- shimmer.wrap(Connection.prototype, 'addCommandEnable', wrapConnectionAddCommand)
85
- shimmer.wrap(Connection.prototype, 'addCommandEnablePipeline', wrapConnectionAddCommand)
86
-
87
- return Connection
88
- }
89
- )
62
+ return Query
63
+ })
@@ -7,8 +7,8 @@ const skipCh = channel('ci:mocha:test:skip')
7
7
  const testFinishCh = channel('ci:mocha:test:finish')
8
8
  const parameterizedTestCh = channel('ci:mocha:test:parameterize')
9
9
 
10
- const testRunStartCh = channel('ci:mocha:run:start')
11
- const testRunFinishCh = channel('ci:mocha:run:finish')
10
+ const testSessionStartCh = channel('ci:mocha:session:start')
11
+ const testSessionFinishCh = channel('ci:mocha:session:finish')
12
12
 
13
13
  const testSuiteStartCh = channel('ci:mocha:test-suite:start')
14
14
  const testSuiteFinishCh = channel('ci:mocha:test-suite:finish')
@@ -92,13 +92,13 @@ function mochaHook (Runner) {
92
92
  status = 'fail'
93
93
  }
94
94
  testFileToSuiteAr.clear()
95
- testRunFinishCh.publish(status)
95
+ testSessionFinishCh.publish(status)
96
96
  }))
97
97
 
98
98
  this.once('start', testRunAsyncResource.bind(function () {
99
99
  const processArgv = process.argv.slice(2).join(' ')
100
100
  const command = `mocha ${processArgv}`
101
- testRunStartCh.publish(command)
101
+ testSessionStartCh.publish(command)
102
102
  }))
103
103
 
104
104
  this.on('suite', function (suite) {
@@ -245,13 +245,6 @@ function mochaHook (Runner) {
245
245
  return run.apply(this, arguments)
246
246
  })
247
247
 
248
- shimmer.wrap(Runner.prototype, 'runTests', runTests => function () {
249
- if (!testRunFinishCh.hasSubscribers) {
250
- return runTests.apply(this, arguments)
251
- }
252
- return runTests.apply(this, arguments)
253
- })
254
-
255
248
  return Runner
256
249
  }
257
250
 
@@ -285,6 +278,9 @@ addHook({
285
278
  file: 'lib/runnable.js'
286
279
  }, (Runnable) => {
287
280
  shimmer.wrap(Runnable.prototype, 'run', run => function () {
281
+ if (!testStartCh.hasSubscribers) {
282
+ return run.apply(this, arguments)
283
+ }
288
284
  const isBeforeEach = this.parent._beforeEach.includes(this)
289
285
  const isAfterEach = this.parent._afterEach.includes(this)
290
286
 
@@ -300,13 +296,15 @@ addHook({
300
296
  const test = isTestHook ? this.ctx.currentTest : this
301
297
  const asyncResource = getTestAsyncResource(test)
302
298
 
303
- // we bind the test fn to the correct async resource
304
- const newFn = asyncResource.bind(this.fn)
299
+ if (asyncResource) {
300
+ // we bind the test fn to the correct async resource
301
+ const newFn = asyncResource.bind(this.fn)
305
302
 
306
- // we store the original function, not to lose it
307
- originalFns.set(newFn, this.fn)
303
+ // we store the original function, not to lose it
304
+ originalFns.set(newFn, this.fn)
308
305
 
309
- this.fn = newFn
306
+ this.fn = newFn
307
+ }
310
308
  }
311
309
 
312
310
  return run.apply(this, arguments)
@@ -318,5 +316,3 @@ addHook({
318
316
  name: 'mocha-each',
319
317
  versions: ['>=2.0.1']
320
318
  }, mochaEachHook)
321
-
322
- module.exports = { mochaHook, mochaEachHook }
@@ -0,0 +1,10 @@
1
+ 'use strict'
2
+
3
+ const { addHook } = require('./helpers/instrument')
4
+ const shimmer = require('../../datadog-shimmer')
5
+ const { createWrapRequest } = require('./elasticsearch')
6
+
7
+ addHook({ name: '@opensearch-project/opensearch', file: 'lib/Transport.js', versions: ['1.1.0'] }, Transport => {
8
+ shimmer.wrap(Transport.prototype, 'request', createWrapRequest('opensearch'))
9
+ return Transport
10
+ })
@@ -40,9 +40,10 @@ function wrapQuery (query) {
40
40
  const statement = pgQuery.text
41
41
  const callbackResource = new AsyncResource('bound-anonymous-fn')
42
42
  const asyncResource = new AsyncResource('bound-anonymous-fn')
43
+ const processId = this.processID
43
44
 
44
45
  return asyncResource.runInAsyncScope(() => {
45
- startCh.publish({ params: this.connectionParameters, statement })
46
+ startCh.publish({ params: this.connectionParameters, statement, processId })
46
47
 
47
48
  const finish = asyncResource.bind(function (error) {
48
49
  if (error) {
@@ -11,17 +11,22 @@ const circularBufferConstructor = Symbol('circularBufferConstructor')
11
11
  const inFlightDeliveries = Symbol('inFlightDeliveries')
12
12
 
13
13
  const patched = new WeakSet()
14
- const dispatchCh = channel('apm:rhea:dispatch')
15
- const errorCh = channel('apm:rhea:error')
16
- const finishCh = channel('apm:rhea:finish')
17
14
 
18
- const encodeCh = channel('apm:rhea:encode')
15
+ const startSendCh = channel('apm:rhea:send:start')
16
+ const encodeSendCh = channel('apm:rhea:send:encode')
17
+ const errorSendCh = channel('apm:rhea:send:error')
18
+ const finishSendCh = channel('apm:rhea:send:finish')
19
+
20
+ const startReceiveCh = channel('apm:rhea:receive:start')
21
+ const dispatchReceiveCh = channel('apm:rhea:receive:dispatch')
22
+ const errorReceiveCh = channel('apm:rhea:receive:error')
23
+ const finishReceiveCh = channel('apm:rhea:receive:finish')
19
24
 
20
25
  const contexts = new WeakMap()
21
26
 
22
27
  addHook({ name: 'rhea', versions: ['>=1'] }, rhea => {
23
28
  shimmer.wrap(rhea.message, 'encode', encode => function (msg) {
24
- encodeCh.publish(msg)
29
+ encodeSendCh.publish(msg)
25
30
  return encode.apply(this, arguments)
26
31
  })
27
32
 
@@ -29,9 +34,6 @@ addHook({ name: 'rhea', versions: ['>=1'] }, rhea => {
29
34
  })
30
35
 
31
36
  addHook({ name: 'rhea', versions: ['>=1'], file: 'lib/link.js' }, obj => {
32
- const startSendCh = channel('apm:rhea:send:start')
33
- const startReceiveCh = channel('apm:rhea:receive:start')
34
-
35
37
  const Sender = obj.Sender
36
38
  const Receiver = obj.Receiver
37
39
  shimmer.wrap(Sender.prototype, 'send', send => function (msg, tag, format) {
@@ -58,7 +60,7 @@ addHook({ name: 'rhea', versions: ['>=1'], file: 'lib/link.js' }, obj => {
58
60
  try {
59
61
  return delivery
60
62
  } catch (err) {
61
- errorCh.publish(err)
63
+ errorSendCh.publish(err)
62
64
 
63
65
  throw err
64
66
  }
@@ -87,7 +89,7 @@ addHook({ name: 'rhea', versions: ['>=1'], file: 'lib/link.js' }, obj => {
87
89
  try {
88
90
  return dispatch.apply(this, arguments)
89
91
  } catch (err) {
90
- errorCh.publish(err)
92
+ errorReceiveCh.publish(err)
91
93
 
92
94
  throw err
93
95
  }
@@ -111,8 +113,9 @@ addHook({ name: 'rhea', versions: ['>=1'], file: 'lib/connection.js' }, Connecti
111
113
  if (!asyncResource) return
112
114
 
113
115
  asyncResource.runInAsyncScope(() => {
114
- errorCh.publish(error)
115
- finish(delivery, null)
116
+ errorReceiveCh.publish(error)
117
+ beforeFinish(delivery, null)
118
+ finishReceiveCh.publish()
116
119
  })
117
120
  })
118
121
  }
@@ -148,7 +151,7 @@ function wrapDeliveryUpdate (obj, update) {
148
151
  const cb = asyncResource.bind(update)
149
152
  return AsyncResource.bind(function wrappedUpdate (settled, stateData) {
150
153
  const state = getStateFromData(stateData)
151
- dispatchCh.publish({ state })
154
+ dispatchReceiveCh.publish({ state })
152
155
  return cb.apply(this, arguments)
153
156
  })
154
157
  }
@@ -184,7 +187,8 @@ function patchCircularBuffer (proto, Session) {
184
187
  const state = remoteState && remoteState.constructor
185
188
  ? entry.remote_state.constructor.composite_type : undefined
186
189
  asyncResource.runInAsyncScope(() => {
187
- return finish(entry, state)
190
+ beforeFinish(entry, state)
191
+ finishSendCh.publish()
188
192
  })
189
193
  }
190
194
 
@@ -212,13 +216,12 @@ function addToInFlightDeliveries (connection, delivery) {
212
216
  deliveries.add(delivery)
213
217
  }
214
218
 
215
- function finish (delivery, state) {
219
+ function beforeFinish (delivery, state) {
216
220
  const obj = contexts.get(delivery)
217
221
  if (obj) {
218
222
  if (state) {
219
- dispatchCh.publish({ state })
223
+ dispatchReceiveCh.publish({ state })
220
224
  }
221
- finishCh.publish(undefined)
222
225
  if (obj.connection && obj.connection[inFlightDeliveries]) {
223
226
  obj.connection[inFlightDeliveries].delete(delivery)
224
227
  }
@@ -0,0 +1,32 @@
1
+ 'use strict'
2
+
3
+ const ConsumerPlugin = require('../../dd-trace/src/plugins/consumer')
4
+ const { getAddress, getShortName } = require('./util')
5
+
6
+ class Amqp10ConsumerPlugin extends ConsumerPlugin {
7
+ static get name () { return 'amqp10' }
8
+ static get system () { return 'amqp' }
9
+
10
+ start ({ link }) {
11
+ const source = getShortName(link)
12
+ const address = getAddress(link)
13
+
14
+ this.startSpan('amqp.receive', {
15
+ service: this.config.service || `${this.tracer._service}-amqp`,
16
+ resource: ['receive', source].filter(v => v).join(' '),
17
+ type: 'worker',
18
+ kind: 'consumer',
19
+ meta: {
20
+ 'amqp.link.source.address': source,
21
+ 'amqp.link.role': 'receiver',
22
+ 'amqp.link.name': link.name,
23
+ 'amqp.link.handle': link.handle,
24
+ 'amqp.connection.host': address.host,
25
+ 'amqp.connection.port': address.port,
26
+ 'amqp.connection.user': address.user
27
+ }
28
+ })
29
+ }
30
+ }
31
+
32
+ module.exports = Amqp10ConsumerPlugin