dd-trace 2.0.0-appsec-beta.4 → 2.0.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 (82) hide show
  1. package/MIGRATING.md +65 -0
  2. package/ci/init.js +5 -1
  3. package/ci/jest/env.js +5 -1
  4. package/index.d.ts +31 -44
  5. package/package.json +5 -2
  6. package/packages/datadog-instrumentations/index.js +6 -0
  7. package/packages/datadog-instrumentations/src/bluebird.js +26 -0
  8. package/packages/datadog-instrumentations/src/dns.js +2 -2
  9. package/packages/datadog-instrumentations/src/helpers/instrument.js +24 -25
  10. package/packages/datadog-instrumentations/src/helpers/promise.js +29 -0
  11. package/packages/datadog-instrumentations/src/memcached.js +3 -5
  12. package/packages/datadog-instrumentations/src/mysql.js +67 -0
  13. package/packages/datadog-instrumentations/src/promise-js.js +15 -0
  14. package/packages/datadog-instrumentations/src/promise.js +14 -0
  15. package/packages/datadog-instrumentations/src/q.js +21 -0
  16. package/packages/datadog-instrumentations/src/when.js +14 -0
  17. package/packages/datadog-plugin-cucumber/src/index.js +4 -4
  18. package/packages/datadog-plugin-cypress/src/plugin.js +12 -2
  19. package/packages/datadog-plugin-cypress/src/support.js +21 -6
  20. package/packages/datadog-plugin-dns/src/index.js +1 -1
  21. package/packages/datadog-plugin-fs/src/index.js +7 -3
  22. package/packages/datadog-plugin-http/src/client.js +9 -24
  23. package/packages/datadog-plugin-http2/src/client.js +1 -24
  24. package/packages/datadog-plugin-http2/src/server.js +2 -2
  25. package/packages/datadog-plugin-jest/src/jest-environment.js +4 -4
  26. package/packages/datadog-plugin-jest/src/jest-jasmine2.js +2 -2
  27. package/packages/datadog-plugin-knex/src/index.js +3 -3
  28. package/packages/datadog-plugin-mocha/src/index.js +3 -2
  29. package/packages/datadog-plugin-moleculer/src/client.js +60 -0
  30. package/packages/datadog-plugin-moleculer/src/index.js +8 -0
  31. package/packages/datadog-plugin-moleculer/src/server.js +61 -0
  32. package/packages/datadog-plugin-moleculer/src/util.js +21 -0
  33. package/packages/datadog-plugin-mongoose/src/index.js +2 -2
  34. package/packages/datadog-plugin-mysql/src/index.js +37 -89
  35. package/packages/datadog-plugin-net/src/index.js +5 -0
  36. package/packages/datadog-plugin-pino/src/index.js +25 -1
  37. package/packages/datadog-plugin-router/src/index.js +28 -3
  38. package/packages/datadog-plugin-winston/src/index.js +30 -12
  39. package/packages/dd-trace/lib/version.js +1 -1
  40. package/packages/dd-trace/src/appsec/addresses.js +11 -4
  41. package/packages/dd-trace/src/appsec/callbacks/ddwaf.js +4 -7
  42. package/packages/dd-trace/src/appsec/gateway/als.js +1 -0
  43. package/packages/dd-trace/src/appsec/gateway/channels.js +3 -0
  44. package/packages/dd-trace/src/appsec/gateway/engine/engine.js +20 -30
  45. package/packages/dd-trace/src/appsec/gateway/engine/runner.js +2 -0
  46. package/packages/dd-trace/src/appsec/index.js +41 -25
  47. package/packages/dd-trace/src/appsec/recommended.json +5708 -1
  48. package/packages/dd-trace/src/appsec/reporter.js +27 -10
  49. package/packages/dd-trace/src/config.js +31 -27
  50. package/packages/dd-trace/src/constants.js +0 -2
  51. package/packages/dd-trace/src/exporters/agent/request.js +8 -0
  52. package/packages/dd-trace/src/format.js +14 -39
  53. package/packages/dd-trace/src/log.js +6 -15
  54. package/packages/dd-trace/src/noop/span_context.js +0 -1
  55. package/packages/dd-trace/src/noop/tracer.js +0 -6
  56. package/packages/dd-trace/src/opentracing/propagation/text_map.js +46 -47
  57. package/packages/dd-trace/src/opentracing/span.js +2 -7
  58. package/packages/dd-trace/src/opentracing/span_context.js +0 -3
  59. package/packages/dd-trace/src/opentracing/tracer.js +5 -23
  60. package/packages/dd-trace/src/plugins/index.js +1 -5
  61. package/packages/dd-trace/src/plugins/plugin.js +7 -1
  62. package/packages/dd-trace/src/plugins/util/test.js +9 -4
  63. package/packages/dd-trace/src/plugins/util/web.js +3 -3
  64. package/packages/dd-trace/src/profiling/config.js +5 -1
  65. package/packages/dd-trace/src/profiling/exporters/agent.js +33 -32
  66. package/packages/dd-trace/src/profiling/profiler.js +15 -6
  67. package/packages/dd-trace/src/profiling/profilers/cpu.js +1 -1
  68. package/packages/dd-trace/src/profiling/profilers/heap.js +3 -2
  69. package/packages/dd-trace/src/proxy.js +35 -35
  70. package/packages/dd-trace/src/span_processor.js +0 -7
  71. package/packages/dd-trace/src/tracer.js +5 -6
  72. package/scripts/install_plugin_modules.js +7 -0
  73. package/scripts/publish_docs.js +1 -1
  74. package/packages/datadog-plugin-bluebird/src/index.js +0 -69
  75. package/packages/datadog-plugin-promise/src/index.js +0 -17
  76. package/packages/datadog-plugin-promise-js/src/index.js +0 -20
  77. package/packages/datadog-plugin-q/src/index.js +0 -16
  78. package/packages/datadog-plugin-when/src/index.js +0 -17
  79. package/packages/dd-trace/src/appsec/gateway/dc_block.js +0 -68
  80. package/packages/dd-trace/src/plugins/util/promise.js +0 -31
  81. package/packages/dd-trace/src/profiling/mapper.js +0 -91
  82. package/packages/dd-trace/src/scope/noop/scope_manager.js +0 -28
@@ -1,17 +0,0 @@
1
- 'use strict'
2
-
3
- const tx = require('../../dd-trace/src/plugins/util/promise')
4
-
5
- module.exports = [
6
- {
7
- name: 'promise',
8
- file: 'lib/core.js',
9
- versions: ['>=7'],
10
- patch (Promise, tracer, config) {
11
- this.wrap(Promise.prototype, 'then', tx.createWrapThen(tracer, config))
12
- },
13
- unpatch (Promise) {
14
- this.unwrap(Promise.prototype, 'then')
15
- }
16
- }
17
- ]
@@ -1,20 +0,0 @@
1
- 'use strict'
2
-
3
- const tx = require('../../dd-trace/src/plugins/util/promise')
4
-
5
- module.exports = [
6
- {
7
- name: 'promise-js',
8
- versions: ['>=0.0.3'],
9
- patch (Promise, tracer, config) {
10
- if (Promise !== global.Promise) {
11
- this.wrap(Promise.prototype, 'then', tx.createWrapThen(tracer, config))
12
- }
13
- },
14
- unpatch (Promise) {
15
- if (Promise !== global.Promise) {
16
- this.unwrap(Promise.prototype, 'then')
17
- }
18
- }
19
- }
20
- ]
@@ -1,16 +0,0 @@
1
- 'use strict'
2
-
3
- const tx = require('../../dd-trace/src/plugins/util/promise')
4
-
5
- module.exports = [
6
- {
7
- name: 'q',
8
- versions: ['>=1'],
9
- patch (Q, tracer, config) {
10
- this.wrap(Q.makePromise.prototype, 'then', tx.createWrapThen(tracer, config))
11
- },
12
- unpatch (Q) {
13
- this.unwrap(Q.makePromise.prototype, 'then')
14
- }
15
- }
16
- ]
@@ -1,17 +0,0 @@
1
- 'use strict'
2
-
3
- const tx = require('../../dd-trace/src/plugins/util/promise')
4
-
5
- module.exports = [
6
- {
7
- name: 'when',
8
- file: 'lib/Promise.js',
9
- versions: ['>=3'],
10
- patch (Promise, tracer, config) {
11
- this.wrap(Promise.prototype, 'then', tx.createWrapThen(tracer, config))
12
- },
13
- unpatch (Promise) {
14
- this.unwrap(Promise.prototype, 'then')
15
- }
16
- }
17
- ]
@@ -1,68 +0,0 @@
1
- 'use strict'
2
-
3
- const dc = require('diagnostics_channel')
4
- const shimmer = require('shimmer')
5
-
6
- let protoCache
7
-
8
- function getActiveChannelPrototype () {
9
- if (protoCache) return protoCache
10
-
11
- const noop = () => {}
12
-
13
- const channel = dc.channel('dd-trace:temp_getproto')
14
-
15
- // We have to force the channel to switch to ActiveChannel prototype
16
- channel.subscribe(noop)
17
-
18
- const activeChannelPrototype = Object.getPrototypeOf(channel)
19
-
20
- channel.unsubscribe(noop)
21
-
22
- protoCache = activeChannelPrototype
23
-
24
- return activeChannelPrototype
25
- }
26
-
27
- function blockingPublish (data) {
28
- let firstError
29
-
30
- for (let i = 0; i < this._subscribers.length; i++) {
31
- try {
32
- const onMessage = this._subscribers[i]
33
- onMessage(data, this.name)
34
- } catch (err) {
35
- if (firstError === undefined && err instanceof DCBlockingError) {
36
- firstError = err
37
- } else {
38
- process.nextTick(() => {
39
- throw err
40
- })
41
- }
42
- }
43
- }
44
-
45
- if (firstError) throw firstError
46
- }
47
-
48
- function enable () {
49
- shimmer.wrap(getActiveChannelPrototype(), 'publish', (originalPublish) => {
50
- return blockingPublish
51
- })
52
- }
53
-
54
- function disable () {
55
- shimmer.unwrap(getActiveChannelPrototype(), 'publish')
56
- }
57
-
58
- class DCBlockingError extends Error {
59
- get name () {
60
- return this.constructor.name
61
- }
62
- }
63
-
64
- module.exports = {
65
- enable,
66
- disable,
67
- DCBlockingError
68
- }
@@ -1,31 +0,0 @@
1
- 'use strict'
2
-
3
- module.exports = {
4
- createWrapThen (tracer, config) {
5
- return function wrapThen (then) {
6
- return function thenWithTrace (onFulfilled, onRejected, onProgress) {
7
- arguments[0] = wrapCallback(tracer, onFulfilled)
8
- arguments[1] = wrapCallback(tracer, onRejected)
9
-
10
- // not standard but sometimes supported
11
- if (onProgress) {
12
- arguments[2] = wrapCallback(tracer, onProgress)
13
- }
14
-
15
- return then.apply(this, arguments)
16
- }
17
- }
18
- }
19
- }
20
-
21
- function wrapCallback (tracer, callback) {
22
- if (typeof callback !== 'function') return callback
23
-
24
- const span = tracer.scope().active()
25
-
26
- return function () {
27
- return tracer.scope().activate(span, () => {
28
- return callback.apply(this, arguments)
29
- })
30
- }
31
- }
@@ -1,91 +0,0 @@
1
- 'use strict'
2
-
3
- // TODO: use sourceRoot when set, possibly from source-map-resolve
4
-
5
- const fs = require('fs')
6
- const { SourceMapConsumer } = require('source-map')
7
- const sourceMapResolve = require('source-map-resolve')
8
- const { fileURLToPath, pathToFileURL } = require('url')
9
-
10
- class SourceMapper {
11
- constructor () {
12
- this._consumers = Object.create(null)
13
- this._sources = Object.create(null)
14
- }
15
-
16
- async getSource (callFrame) {
17
- const { url, lineNumber, columnNumber, functionName } = callFrame
18
- const key = `${url}:${functionName}:${lineNumber}:${columnNumber}`
19
-
20
- if (!this._sources[key]) {
21
- this._sources[key] = await this._getMapping(callFrame)
22
- }
23
-
24
- return this._sources[key]
25
- }
26
-
27
- async _getConsumer (url) {
28
- if (this._consumers[url] === undefined) {
29
- this._consumers[url] = this._createConsumer(url)
30
- }
31
-
32
- return this._consumers[url]
33
- }
34
-
35
- async _createConsumer (url) {
36
- try {
37
- const map = await this._resolve(url)
38
-
39
- return map ? new SourceMapConsumer(map) : null
40
- } catch (e) {
41
- return null
42
- }
43
- }
44
-
45
- async _getMapping (callFrame) {
46
- const { url, functionName, lineNumber, columnNumber } = callFrame
47
-
48
- // Runtime.CallFrame is 0-based for both line and column numbers.
49
- // When the line or column number is not known the value is -1.
50
- // https://chromedevtools.github.io/devtools-protocol/v8/Runtime/#type-CallFrame
51
- if (lineNumber < 0 || columnNumber < 0) return callFrame
52
-
53
- const consumer = await this._getConsumer(url)
54
-
55
- if (!consumer) return callFrame
56
-
57
- // SourceMapConsumer is 1-based for lines and 0-based for columns
58
- // https://github.com/mozilla/source-map/blob/0.7.3/lib/source-map-consumer.js#L464-L487
59
- const map = consumer.originalPositionFor({
60
- line: lineNumber + 1,
61
- column: columnNumber
62
- })
63
-
64
- if (!map || !map.source || !map.line) return callFrame
65
-
66
- return {
67
- url: pathToFileURL(map.source).href,
68
- lineNumber: map.line - 1, // reset to 0-based from 1-based
69
- columnNumber: map.column !== null ? map.column : -1,
70
- functionName: map.name || functionName
71
- }
72
- }
73
-
74
- async _resolve (url) {
75
- const filename = fileURLToPath(url)
76
- const code = (await fs.promises.readFile(filename)).toString()
77
-
78
- return new Promise((resolve, reject) => {
79
- sourceMapResolve.resolve(code, filename, fs.readFile, (error, result) => {
80
- if (!result || error) return resolve(null)
81
-
82
- result.map.sourcesContent = result.sourcesContent
83
- result.map.sources = result.sourcesResolved
84
-
85
- resolve(result.map)
86
- })
87
- })
88
- }
89
- }
90
-
91
- module.exports = { SourceMapper }
@@ -1,28 +0,0 @@
1
- 'use strict'
2
-
3
- const Span = require('opentracing').Span
4
- const Scope = require('./scope')
5
-
6
- let singleton = null
7
-
8
- const span = new Span()
9
-
10
- class ScopeManager {
11
- constructor () {
12
- if (!singleton) {
13
- singleton = this
14
- }
15
-
16
- return singleton
17
- }
18
-
19
- active () {
20
- return new Scope(span)
21
- }
22
-
23
- activate (span, finishSpanOnClose) {
24
- return new Scope(span, finishSpanOnClose)
25
- }
26
- }
27
-
28
- module.exports = ScopeManager