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.
- package/MIGRATING.md +65 -0
- package/ci/init.js +5 -1
- package/ci/jest/env.js +5 -1
- package/index.d.ts +31 -44
- package/package.json +5 -2
- package/packages/datadog-instrumentations/index.js +6 -0
- package/packages/datadog-instrumentations/src/bluebird.js +26 -0
- package/packages/datadog-instrumentations/src/dns.js +2 -2
- package/packages/datadog-instrumentations/src/helpers/instrument.js +24 -25
- package/packages/datadog-instrumentations/src/helpers/promise.js +29 -0
- package/packages/datadog-instrumentations/src/memcached.js +3 -5
- package/packages/datadog-instrumentations/src/mysql.js +67 -0
- package/packages/datadog-instrumentations/src/promise-js.js +15 -0
- package/packages/datadog-instrumentations/src/promise.js +14 -0
- package/packages/datadog-instrumentations/src/q.js +21 -0
- package/packages/datadog-instrumentations/src/when.js +14 -0
- package/packages/datadog-plugin-cucumber/src/index.js +4 -4
- package/packages/datadog-plugin-cypress/src/plugin.js +12 -2
- package/packages/datadog-plugin-cypress/src/support.js +21 -6
- package/packages/datadog-plugin-dns/src/index.js +1 -1
- package/packages/datadog-plugin-fs/src/index.js +7 -3
- package/packages/datadog-plugin-http/src/client.js +9 -24
- package/packages/datadog-plugin-http2/src/client.js +1 -24
- package/packages/datadog-plugin-http2/src/server.js +2 -2
- package/packages/datadog-plugin-jest/src/jest-environment.js +4 -4
- package/packages/datadog-plugin-jest/src/jest-jasmine2.js +2 -2
- package/packages/datadog-plugin-knex/src/index.js +3 -3
- package/packages/datadog-plugin-mocha/src/index.js +3 -2
- package/packages/datadog-plugin-moleculer/src/client.js +60 -0
- package/packages/datadog-plugin-moleculer/src/index.js +8 -0
- package/packages/datadog-plugin-moleculer/src/server.js +61 -0
- package/packages/datadog-plugin-moleculer/src/util.js +21 -0
- package/packages/datadog-plugin-mongoose/src/index.js +2 -2
- package/packages/datadog-plugin-mysql/src/index.js +37 -89
- package/packages/datadog-plugin-net/src/index.js +5 -0
- package/packages/datadog-plugin-pino/src/index.js +25 -1
- package/packages/datadog-plugin-router/src/index.js +28 -3
- package/packages/datadog-plugin-winston/src/index.js +30 -12
- package/packages/dd-trace/lib/version.js +1 -1
- package/packages/dd-trace/src/appsec/addresses.js +11 -4
- package/packages/dd-trace/src/appsec/callbacks/ddwaf.js +4 -7
- package/packages/dd-trace/src/appsec/gateway/als.js +1 -0
- package/packages/dd-trace/src/appsec/gateway/channels.js +3 -0
- package/packages/dd-trace/src/appsec/gateway/engine/engine.js +20 -30
- package/packages/dd-trace/src/appsec/gateway/engine/runner.js +2 -0
- package/packages/dd-trace/src/appsec/index.js +41 -25
- package/packages/dd-trace/src/appsec/recommended.json +5708 -1
- package/packages/dd-trace/src/appsec/reporter.js +27 -10
- package/packages/dd-trace/src/config.js +31 -27
- package/packages/dd-trace/src/constants.js +0 -2
- package/packages/dd-trace/src/exporters/agent/request.js +8 -0
- package/packages/dd-trace/src/format.js +14 -39
- package/packages/dd-trace/src/log.js +6 -15
- package/packages/dd-trace/src/noop/span_context.js +0 -1
- package/packages/dd-trace/src/noop/tracer.js +0 -6
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +46 -47
- package/packages/dd-trace/src/opentracing/span.js +2 -7
- package/packages/dd-trace/src/opentracing/span_context.js +0 -3
- package/packages/dd-trace/src/opentracing/tracer.js +5 -23
- package/packages/dd-trace/src/plugins/index.js +1 -5
- package/packages/dd-trace/src/plugins/plugin.js +7 -1
- package/packages/dd-trace/src/plugins/util/test.js +9 -4
- package/packages/dd-trace/src/plugins/util/web.js +3 -3
- package/packages/dd-trace/src/profiling/config.js +5 -1
- package/packages/dd-trace/src/profiling/exporters/agent.js +33 -32
- package/packages/dd-trace/src/profiling/profiler.js +15 -6
- package/packages/dd-trace/src/profiling/profilers/cpu.js +1 -1
- package/packages/dd-trace/src/profiling/profilers/heap.js +3 -2
- package/packages/dd-trace/src/proxy.js +35 -35
- package/packages/dd-trace/src/span_processor.js +0 -7
- package/packages/dd-trace/src/tracer.js +5 -6
- package/scripts/install_plugin_modules.js +7 -0
- package/scripts/publish_docs.js +1 -1
- package/packages/datadog-plugin-bluebird/src/index.js +0 -69
- package/packages/datadog-plugin-promise/src/index.js +0 -17
- package/packages/datadog-plugin-promise-js/src/index.js +0 -20
- package/packages/datadog-plugin-q/src/index.js +0 -16
- package/packages/datadog-plugin-when/src/index.js +0 -17
- package/packages/dd-trace/src/appsec/gateway/dc_block.js +0 -68
- package/packages/dd-trace/src/plugins/util/promise.js +0 -31
- package/packages/dd-trace/src/profiling/mapper.js +0 -91
- package/packages/dd-trace/src/scope/noop/scope_manager.js +0 -28
package/MIGRATING.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Migrating
|
|
2
|
+
|
|
3
|
+
This guide describes the steps to upgrade dd-trace from a major version to the
|
|
4
|
+
next. If you are having any issues related to migrating, please feel free to
|
|
5
|
+
open an issue or contact our [support](https://www.datadoghq.com/support/) team.
|
|
6
|
+
|
|
7
|
+
## 1.0 to 2.0
|
|
8
|
+
|
|
9
|
+
### Configuration
|
|
10
|
+
|
|
11
|
+
The following configuraton options are no longer available programmatically and
|
|
12
|
+
must be configured using these environment variables:
|
|
13
|
+
|
|
14
|
+
* `enabled` -> `DD_TRACE_ENABLED=true|false`
|
|
15
|
+
* `debug` -> `DD_TRACE_DEBUG=true|false`
|
|
16
|
+
|
|
17
|
+
If environment variables were already used for these options, no action is
|
|
18
|
+
needed.
|
|
19
|
+
|
|
20
|
+
The following configuration options were completely removed and will no longer
|
|
21
|
+
have any effect:
|
|
22
|
+
|
|
23
|
+
* `scope`
|
|
24
|
+
|
|
25
|
+
Startup logs are now disabled by default and can be enabled if needed with
|
|
26
|
+
`DD_TRACE_STARTUP_LOGS=true`.
|
|
27
|
+
|
|
28
|
+
### Removed APIs
|
|
29
|
+
|
|
30
|
+
The original scope manager has been replaced several years ago and has now been
|
|
31
|
+
removed. Any code referencing `tracer.scopeManager()` should be removed or
|
|
32
|
+
replaced with `tracer.scope()` which is documented
|
|
33
|
+
[here](https://datadoghq.dev/dd-trace-js/#scope-manager).
|
|
34
|
+
|
|
35
|
+
### Nested objects as tags
|
|
36
|
+
|
|
37
|
+
Support for nested objects as tags as been removed. When adding an object as a
|
|
38
|
+
tag value, only properties that exist on that object directly will be added as
|
|
39
|
+
tags. If nested properties are also needed, these should be added by hand.
|
|
40
|
+
|
|
41
|
+
For example:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
const obj = {
|
|
45
|
+
a: 'foo',
|
|
46
|
+
b: {
|
|
47
|
+
c: 'bar'
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 1.0
|
|
52
|
+
span.setTag('test', obj) // add test.a and test.b.c
|
|
53
|
+
|
|
54
|
+
// 2.0
|
|
55
|
+
span.setTag('test', obj) // add test.a
|
|
56
|
+
span.setTag('test.b', obj.b) // add test.b.c
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Arrays are no longer supported and must be converted to string manually.
|
|
60
|
+
|
|
61
|
+
### Outgoing request filtering
|
|
62
|
+
|
|
63
|
+
Outgoing request filtering is no longer supported and is now only available for
|
|
64
|
+
incoming requests. This means that the `blocklist` and `allowlist` options on
|
|
65
|
+
the `http` integration no longer have any effect.
|
package/ci/init.js
CHANGED
package/ci/jest/env.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
const tracer = require('../../packages/dd-trace')
|
|
2
|
+
const { ORIGIN_KEY } = require('../../packages/dd-trace/src/constants')
|
|
2
3
|
|
|
3
4
|
tracer.init({
|
|
4
5
|
startupLogs: false,
|
|
5
|
-
flushInterval: 400000
|
|
6
|
+
flushInterval: 400000,
|
|
7
|
+
tags: {
|
|
8
|
+
[ORIGIN_KEY]: 'ciapp-test'
|
|
9
|
+
}
|
|
6
10
|
})
|
|
7
11
|
|
|
8
12
|
tracer.use('fs', false)
|
package/index.d.ts
CHANGED
|
@@ -268,8 +268,7 @@ export declare interface TracerOptions {
|
|
|
268
268
|
version?: string;
|
|
269
269
|
|
|
270
270
|
/**
|
|
271
|
-
*
|
|
272
|
-
* @default 1
|
|
271
|
+
* Controls the ingestion sample rate (between 0 and 1) between the agent and the backend.
|
|
273
272
|
*/
|
|
274
273
|
sampleRate?: number;
|
|
275
274
|
|
|
@@ -358,12 +357,6 @@ export declare interface TracerOptions {
|
|
|
358
357
|
* @default false
|
|
359
358
|
*/
|
|
360
359
|
enableGetRumData?: boolean
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Whether to set the error flag when an error occurs in an internal span.
|
|
364
|
-
* @default false
|
|
365
|
-
*/
|
|
366
|
-
internalErrors?: boolean
|
|
367
360
|
};
|
|
368
361
|
|
|
369
362
|
/**
|
|
@@ -476,7 +469,6 @@ interface Plugins {
|
|
|
476
469
|
"amqp10": plugins.amqp10;
|
|
477
470
|
"amqplib": plugins.amqplib;
|
|
478
471
|
"aws-sdk": plugins.aws_sdk;
|
|
479
|
-
"bluebird": plugins.bluebird;
|
|
480
472
|
"bunyan": plugins.bunyan;
|
|
481
473
|
"cassandra-driver": plugins.cassandra_driver;
|
|
482
474
|
"connect": plugins.connect;
|
|
@@ -504,6 +496,7 @@ interface Plugins {
|
|
|
504
496
|
"memcached": plugins.memcached;
|
|
505
497
|
"microgateway-core": plugins.microgateway_core;
|
|
506
498
|
"mocha": plugins.mocha;
|
|
499
|
+
"moleculer": plugins.moleculer;
|
|
507
500
|
"mongodb-core": plugins.mongodb_core;
|
|
508
501
|
"mongoose": plugins.mongoose;
|
|
509
502
|
"mysql": plugins.mysql;
|
|
@@ -514,16 +507,12 @@ interface Plugins {
|
|
|
514
507
|
"paperplane": plugins.paperplane;
|
|
515
508
|
"pg": plugins.pg;
|
|
516
509
|
"pino": plugins.pino;
|
|
517
|
-
"promise-js": plugins.promise_js;
|
|
518
|
-
"promise": plugins.promise;
|
|
519
|
-
"q": plugins.q;
|
|
520
510
|
"redis": plugins.redis;
|
|
521
511
|
"restify": plugins.restify;
|
|
522
512
|
"rhea": plugins.rhea;
|
|
523
513
|
"router": plugins.router;
|
|
524
514
|
"sharedb": plugins.sharedb;
|
|
525
515
|
"tedious": plugins.tedious;
|
|
526
|
-
"when": plugins.when;
|
|
527
516
|
"winston": plugins.winston;
|
|
528
517
|
}
|
|
529
518
|
|
|
@@ -707,6 +696,16 @@ declare namespace plugins {
|
|
|
707
696
|
metadata?: string[] | ((variables: { [key: string]: any }) => { [key: string]: any });
|
|
708
697
|
}
|
|
709
698
|
|
|
699
|
+
/** @hidden */
|
|
700
|
+
interface Moleculer extends Instrumentation {
|
|
701
|
+
/**
|
|
702
|
+
* Whether to include context meta as tags.
|
|
703
|
+
*
|
|
704
|
+
* @default false
|
|
705
|
+
*/
|
|
706
|
+
meta?: boolean;
|
|
707
|
+
}
|
|
708
|
+
|
|
710
709
|
/**
|
|
711
710
|
* This plugin automatically instruments the
|
|
712
711
|
* [amqp10](https://github.com/noodlefrenzy/node-amqp10) module.
|
|
@@ -750,12 +749,6 @@ declare namespace plugins {
|
|
|
750
749
|
[key: string]: boolean | Object | undefined;
|
|
751
750
|
}
|
|
752
751
|
|
|
753
|
-
/**
|
|
754
|
-
* This plugin patches the [bluebird](https://github.com/petkaantonov/bluebird)
|
|
755
|
-
* module to bind the promise callback the the caller context.
|
|
756
|
-
*/
|
|
757
|
-
interface bluebird extends Integration {}
|
|
758
|
-
|
|
759
752
|
/**
|
|
760
753
|
* This plugin patches the [bunyan](https://github.com/trentm/node-bunyan)
|
|
761
754
|
* to automatically inject trace identifiers in log records when the
|
|
@@ -786,7 +779,7 @@ declare namespace plugins {
|
|
|
786
779
|
* This plugin automatically instruments the
|
|
787
780
|
* [cucumber](https://www.npmjs.com/package/@cucumber/cucumber) module.
|
|
788
781
|
*/
|
|
789
|
-
interface cucumber extends
|
|
782
|
+
interface cucumber extends Integration {}
|
|
790
783
|
|
|
791
784
|
/**
|
|
792
785
|
* This plugin automatically instruments the
|
|
@@ -1107,6 +1100,24 @@ declare namespace plugins {
|
|
|
1107
1100
|
*/
|
|
1108
1101
|
interface mocha extends Integration {}
|
|
1109
1102
|
|
|
1103
|
+
/**
|
|
1104
|
+
* This plugin automatically instruments the
|
|
1105
|
+
* [moleculer](https://moleculer.services/) module.
|
|
1106
|
+
*/
|
|
1107
|
+
interface moleculer extends Moleculer {
|
|
1108
|
+
/**
|
|
1109
|
+
* Configuration for Moleculer clients. Set to false to disable client
|
|
1110
|
+
* instrumentation.
|
|
1111
|
+
*/
|
|
1112
|
+
client?: boolean | Moleculer;
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* Configuration for Moleculer servers. Set to false to disable server
|
|
1116
|
+
* instrumentation.
|
|
1117
|
+
*/
|
|
1118
|
+
server?: boolean | Moleculer;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1110
1121
|
/**
|
|
1111
1122
|
* This plugin automatically instruments the
|
|
1112
1123
|
* [mongodb-core](https://github.com/mongodb-js/mongodb-core) module.
|
|
@@ -1189,24 +1200,6 @@ declare namespace plugins {
|
|
|
1189
1200
|
*/
|
|
1190
1201
|
interface pino extends Integration {}
|
|
1191
1202
|
|
|
1192
|
-
/**
|
|
1193
|
-
* This plugin patches the [promise-js](https://github.com/kevincennis/promise)
|
|
1194
|
-
* module to bind the promise callback the the caller context.
|
|
1195
|
-
*/
|
|
1196
|
-
interface promise_js extends Integration {}
|
|
1197
|
-
|
|
1198
|
-
/**
|
|
1199
|
-
* This plugin patches the [promise](https://github.com/then/promise)
|
|
1200
|
-
* module to bind the promise callback the the caller context.
|
|
1201
|
-
*/
|
|
1202
|
-
interface promise extends Integration {}
|
|
1203
|
-
|
|
1204
|
-
/**
|
|
1205
|
-
* This plugin patches the [q](https://github.com/kriskowal/q)
|
|
1206
|
-
* module to bind the promise callback the the caller context.
|
|
1207
|
-
*/
|
|
1208
|
-
interface q extends Integration {}
|
|
1209
|
-
|
|
1210
1203
|
/**
|
|
1211
1204
|
* This plugin automatically instruments the
|
|
1212
1205
|
* [redis](https://github.com/NodeRedis/node_redis) module.
|
|
@@ -1289,12 +1282,6 @@ declare namespace plugins {
|
|
|
1289
1282
|
*/
|
|
1290
1283
|
interface tedious extends Instrumentation {}
|
|
1291
1284
|
|
|
1292
|
-
/**
|
|
1293
|
-
* This plugin patches the [when](https://github.com/cujojs/when)
|
|
1294
|
-
* module to bind the promise callback the the caller context.
|
|
1295
|
-
*/
|
|
1296
|
-
interface when extends Integration {}
|
|
1297
|
-
|
|
1298
1285
|
/**
|
|
1299
1286
|
* This plugin patches the [winston](https://github.com/winstonjs/winston)
|
|
1300
1287
|
* to automatically inject trace identifiers in log records when the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dd-trace",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Datadog APM tracing client for JavaScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"bench": "node benchmark",
|
|
11
11
|
"bench:profiler": "node benchmark/profiler",
|
|
12
12
|
"bench:e2e": "SERVICES=mongo yarn services && cd benchmark/e2e && node benchmark-run.js --duration=30",
|
|
13
|
+
"bench:e2e:ci-visibility": "node benchmark/e2e-ci/benchmark-run.js",
|
|
13
14
|
"type:doc": "cd docs && yarn && yarn build",
|
|
14
15
|
"type:test": "cd docs && yarn && yarn test",
|
|
15
16
|
"lint": "node scripts/check_licenses.js && eslint . && yarn audit --groups dependencies",
|
|
@@ -18,6 +19,8 @@
|
|
|
18
19
|
"test": "SERVICES=* yarn services && mocha --exit --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
|
|
19
20
|
"test:trace:core": "mocha --exit --expose-gc --file packages/dd-trace/test/setup/core.js \"packages/dd-trace/test/**/*.spec.js\"",
|
|
20
21
|
"test:trace:core:ci": "nyc --include \"packages/dd-trace/src/**/*.js\" -- npm run test:trace:core -- --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json",
|
|
22
|
+
"test:instrumentations": "mocha --file 'packages/dd-trace/test/setup/core.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
|
|
23
|
+
"test:instrumentations:ci": "nyc --include 'packages/datadog-instrumentations/src/**/*.js' -- npm run test:instrumentations -- --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json",
|
|
21
24
|
"test:core": "mocha --file packages/datadog-core/test/setup.js 'packages/datadog-core/test/**/*.spec.js'",
|
|
22
25
|
"test:core:ci": "nyc --include 'packages/datadog-core/src/**/*.js' -- npm run test:core -- --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json",
|
|
23
26
|
"test:plugins": "mocha --exit --file \"packages/dd-trace/test/setup/core.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\"",
|
|
@@ -58,7 +61,7 @@
|
|
|
58
61
|
"node": ">=12"
|
|
59
62
|
},
|
|
60
63
|
"dependencies": {
|
|
61
|
-
"@datadog/native-appsec": "^0.
|
|
64
|
+
"@datadog/native-appsec": "^0.8.1",
|
|
62
65
|
"@datadog/native-metrics": "^1.1.0",
|
|
63
66
|
"@datadog/pprof": "^0.3.0",
|
|
64
67
|
"@datadog/sketches-js": "^1.0.4",
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { addHook } = require('./helpers/instrument')
|
|
4
|
+
const { wrapThen } = require('./helpers/promise')
|
|
5
|
+
const shimmer = require('../../datadog-shimmer')
|
|
6
|
+
|
|
7
|
+
function createGetNewLibraryCopyWrap (originalLib) {
|
|
8
|
+
return function wrapGetNewLibraryCopy (getNewLibraryCopy) {
|
|
9
|
+
return function getNewLibraryCopyWithTrace () {
|
|
10
|
+
const libraryCopy = getNewLibraryCopy.apply(this, arguments)
|
|
11
|
+
shimmer.wrap(libraryCopy.prototype, '_then', wrapThen)
|
|
12
|
+
shimmer.wrap(libraryCopy, 'getNewLibraryCopy', createGetNewLibraryCopyWrap(originalLib))
|
|
13
|
+
return libraryCopy
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
addHook({ name: 'bluebird', versions: ['>=2.0.2'] }, Promise => {
|
|
19
|
+
shimmer.wrap(Promise.prototype, '_then', wrapThen)
|
|
20
|
+
return Promise
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
addHook({ name: 'bluebird', versions: ['^2.11.0', '^3.4.1'] }, Promise => {
|
|
24
|
+
shimmer.wrap(Promise, 'getNewLibraryCopy', createGetNewLibraryCopyWrap(Promise))
|
|
25
|
+
return Promise
|
|
26
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { channel, addHook,
|
|
3
|
+
const { channel, addHook, AsyncResource } = require('./helpers/instrument')
|
|
4
4
|
const shimmer = require('../../datadog-shimmer')
|
|
5
5
|
|
|
6
6
|
const rrtypes = {
|
|
@@ -53,7 +53,7 @@ function wrap (prefix, fn, expectedArgs, rrtype) {
|
|
|
53
53
|
const errorCh = channel(prefix + ':error')
|
|
54
54
|
|
|
55
55
|
const wrapped = function () {
|
|
56
|
-
const cb = bind(arguments[arguments.length - 1])
|
|
56
|
+
const cb = AsyncResource.bind(arguments[arguments.length - 1])
|
|
57
57
|
if (
|
|
58
58
|
!startCh.hasSubscribers ||
|
|
59
59
|
arguments.length < expectedArgs ||
|
|
@@ -90,32 +90,31 @@ function getBasedir (id) {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
if (semver.satisfies(process.versions.node, '>=16.0.0')) {
|
|
93
|
-
exports.
|
|
94
|
-
exports.bindAsyncResource = AsyncResource.prototype.bind
|
|
93
|
+
exports.AsyncResource = AsyncResource
|
|
95
94
|
} else {
|
|
96
|
-
exports.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
configurable: true,
|
|
102
|
-
enumerable: false,
|
|
103
|
-
value: fn.length,
|
|
104
|
-
writable: false
|
|
105
|
-
},
|
|
106
|
-
'asyncResource': {
|
|
107
|
-
configurable: true,
|
|
108
|
-
enumerable: true,
|
|
109
|
-
value: this,
|
|
110
|
-
writable: true
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
return ret
|
|
114
|
-
}
|
|
95
|
+
exports.AsyncResource = class extends AsyncResource {
|
|
96
|
+
static bind (fn, type, thisArg) {
|
|
97
|
+
type = type || fn.name
|
|
98
|
+
return (new exports.AsyncResource(type || 'bound-anonymous-fn')).bind(fn, thisArg)
|
|
99
|
+
}
|
|
115
100
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
101
|
+
bind (fn, thisArg = this) {
|
|
102
|
+
const ret = this.runInAsyncScope.bind(this, fn, thisArg)
|
|
103
|
+
Object.defineProperties(ret, {
|
|
104
|
+
'length': {
|
|
105
|
+
configurable: true,
|
|
106
|
+
enumerable: false,
|
|
107
|
+
value: fn.length,
|
|
108
|
+
writable: false
|
|
109
|
+
},
|
|
110
|
+
'asyncResource': {
|
|
111
|
+
configurable: true,
|
|
112
|
+
enumerable: true,
|
|
113
|
+
value: this,
|
|
114
|
+
writable: true
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
return ret
|
|
118
|
+
}
|
|
120
119
|
}
|
|
121
120
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { AsyncResource } = require('async_hooks')
|
|
4
|
+
|
|
5
|
+
exports.wrapThen = function wrapThen (origThen) {
|
|
6
|
+
return function then (onFulfilled, onRejected, onProgress) {
|
|
7
|
+
const ar = new AsyncResource('bound-anonymous-fn')
|
|
8
|
+
|
|
9
|
+
arguments[0] = wrapCallback(ar, onFulfilled)
|
|
10
|
+
arguments[1] = wrapCallback(ar, onRejected)
|
|
11
|
+
|
|
12
|
+
// not standard but sometimes supported
|
|
13
|
+
if (onProgress) {
|
|
14
|
+
arguments[2] = wrapCallback(ar, onProgress)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return origThen.apply(this, arguments)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function wrapCallback (ar, callback) {
|
|
22
|
+
if (typeof callback !== 'function') return callback
|
|
23
|
+
|
|
24
|
+
return function () {
|
|
25
|
+
return ar.runInAsyncScope(() => {
|
|
26
|
+
return callback.apply(this, arguments)
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { AsyncResource } = require('async_hooks')
|
|
4
3
|
const {
|
|
5
4
|
channel,
|
|
6
5
|
addHook,
|
|
7
|
-
|
|
8
|
-
bindAsyncResource
|
|
6
|
+
AsyncResource
|
|
9
7
|
} = require('./helpers/instrument')
|
|
10
8
|
const shimmer = require('../../datadog-shimmer')
|
|
11
9
|
|
|
@@ -27,9 +25,9 @@ addHook({ name: 'memcached', versions: ['>=2.2'] }, Memcached => {
|
|
|
27
25
|
|
|
28
26
|
const wrappedQueryCompiler = function () {
|
|
29
27
|
const query = queryCompiler.apply(this, arguments)
|
|
30
|
-
const callback =
|
|
28
|
+
const callback = asyncResource.bind(query.callback)
|
|
31
29
|
|
|
32
|
-
query.callback = bind(function (err) {
|
|
30
|
+
query.callback = AsyncResource.bind(function (err) {
|
|
33
31
|
if (err) {
|
|
34
32
|
errorCh.publish(err)
|
|
35
33
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
channel,
|
|
5
|
+
addHook,
|
|
6
|
+
AsyncResource
|
|
7
|
+
} = require('./helpers/instrument')
|
|
8
|
+
const shimmer = require('../../datadog-shimmer')
|
|
9
|
+
|
|
10
|
+
addHook({ name: 'mysql', file: 'lib/Connection.js', versions: ['>=2'] }, Connection => {
|
|
11
|
+
const startCh = channel('apm:mysql:query:start')
|
|
12
|
+
const asyncEndCh = channel('apm:mysql:query:async-end')
|
|
13
|
+
const endCh = channel('apm:mysql:query:end')
|
|
14
|
+
const errorCh = channel('apm:mysql:query:error')
|
|
15
|
+
|
|
16
|
+
shimmer.wrap(Connection.prototype, 'query', query => function () {
|
|
17
|
+
const asyncResource = new AsyncResource('bound-anonymous-fn')
|
|
18
|
+
if (!startCh.hasSubscribers) {
|
|
19
|
+
return query.apply(this, arguments)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const sql = arguments[0].sql ? arguments[0].sql : arguments[0]
|
|
23
|
+
const startArgs = [sql, this.config]
|
|
24
|
+
|
|
25
|
+
startCh.publish(startArgs)
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const res = query.apply(this, arguments)
|
|
29
|
+
|
|
30
|
+
if (res._callback) {
|
|
31
|
+
const cb = asyncResource.bind(res._callback)
|
|
32
|
+
res._callback = AsyncResource.bind(function (error, result) {
|
|
33
|
+
if (error) {
|
|
34
|
+
errorCh.publish(error)
|
|
35
|
+
}
|
|
36
|
+
asyncEndCh.publish(result)
|
|
37
|
+
|
|
38
|
+
return cb.apply(this, arguments)
|
|
39
|
+
})
|
|
40
|
+
} else {
|
|
41
|
+
const cb = AsyncResource.bind(function () {
|
|
42
|
+
asyncEndCh.publish(undefined)
|
|
43
|
+
})
|
|
44
|
+
res.on('end', cb)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return res
|
|
48
|
+
} catch (err) {
|
|
49
|
+
err.stack // trigger getting the stack at the original throwing point
|
|
50
|
+
errorCh.publish(err)
|
|
51
|
+
|
|
52
|
+
throw err
|
|
53
|
+
} finally {
|
|
54
|
+
endCh.publish(undefined)
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
return Connection
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
addHook({ name: 'mysql', file: 'lib/Pool.js', versions: ['>=2'] }, Pool => {
|
|
62
|
+
shimmer.wrap(Pool.prototype, 'getConnection', getConnection => function (cb) {
|
|
63
|
+
arguments[0] = AsyncResource.bind(cb)
|
|
64
|
+
return getConnection.apply(this, arguments)
|
|
65
|
+
})
|
|
66
|
+
return Pool
|
|
67
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { addHook } = require('./helpers/instrument')
|
|
4
|
+
const { wrapThen } = require('./helpers/promise')
|
|
5
|
+
const shimmer = require('../../datadog-shimmer')
|
|
6
|
+
|
|
7
|
+
addHook({
|
|
8
|
+
name: 'promise-js',
|
|
9
|
+
versions: ['>=0.0.3']
|
|
10
|
+
}, Promise => {
|
|
11
|
+
if (Promise !== global.Promise) {
|
|
12
|
+
shimmer.wrap(Promise.prototype, 'then', wrapThen)
|
|
13
|
+
}
|
|
14
|
+
return Promise
|
|
15
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { addHook } = require('./helpers/instrument')
|
|
4
|
+
const { wrapThen } = require('./helpers/promise')
|
|
5
|
+
const shimmer = require('../../datadog-shimmer')
|
|
6
|
+
|
|
7
|
+
addHook({
|
|
8
|
+
name: 'promise',
|
|
9
|
+
file: 'lib/core.js',
|
|
10
|
+
versions: ['>=7']
|
|
11
|
+
}, Promise => {
|
|
12
|
+
shimmer.wrap(Promise.prototype, 'then', wrapThen)
|
|
13
|
+
return Promise
|
|
14
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { addHook } = require('./helpers/instrument')
|
|
4
|
+
const { wrapThen } = require('./helpers/promise')
|
|
5
|
+
const shimmer = require('../../datadog-shimmer')
|
|
6
|
+
|
|
7
|
+
addHook({
|
|
8
|
+
name: 'q',
|
|
9
|
+
versions: ['1']
|
|
10
|
+
}, Q => {
|
|
11
|
+
shimmer.wrap(Q.makePromise.prototype, 'then', wrapThen)
|
|
12
|
+
return Q
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
addHook({
|
|
16
|
+
name: 'q',
|
|
17
|
+
versions: ['>=2']
|
|
18
|
+
}, Q => {
|
|
19
|
+
shimmer.wrap(Q.Promise.prototype, 'then', wrapThen)
|
|
20
|
+
return Q
|
|
21
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { addHook } = require('./helpers/instrument')
|
|
4
|
+
const { wrapThen } = require('./helpers/promise')
|
|
5
|
+
const shimmer = require('../../datadog-shimmer')
|
|
6
|
+
|
|
7
|
+
addHook({
|
|
8
|
+
name: 'when',
|
|
9
|
+
file: 'lib/Promise.js',
|
|
10
|
+
versions: ['>=3']
|
|
11
|
+
}, Promise => {
|
|
12
|
+
shimmer.wrap(Promise.prototype, 'then', wrapThen)
|
|
13
|
+
return Promise
|
|
14
|
+
})
|
|
@@ -103,8 +103,8 @@ module.exports = [
|
|
|
103
103
|
name: '@cucumber/cucumber',
|
|
104
104
|
versions: ['7.0.0 - 7.2.1'],
|
|
105
105
|
file: 'lib/runtime/pickle_runner.js',
|
|
106
|
-
patch (PickleRunner, tracer) {
|
|
107
|
-
const testEnvironmentMetadata = getTestEnvironmentMetadata('cucumber')
|
|
106
|
+
patch (PickleRunner, tracer, config) {
|
|
107
|
+
const testEnvironmentMetadata = getTestEnvironmentMetadata('cucumber', config)
|
|
108
108
|
const sourceRoot = process.cwd()
|
|
109
109
|
const pl = PickleRunner.default
|
|
110
110
|
this.wrap(
|
|
@@ -127,8 +127,8 @@ module.exports = [
|
|
|
127
127
|
name: '@cucumber/cucumber',
|
|
128
128
|
versions: ['>=7.3.0'],
|
|
129
129
|
file: 'lib/runtime/test_case_runner.js',
|
|
130
|
-
patch (TestCaseRunner, tracer) {
|
|
131
|
-
const testEnvironmentMetadata = getTestEnvironmentMetadata('cucumber')
|
|
130
|
+
patch (TestCaseRunner, tracer, config) {
|
|
131
|
+
const testEnvironmentMetadata = getTestEnvironmentMetadata('cucumber', config)
|
|
132
132
|
const sourceRoot = process.cwd()
|
|
133
133
|
const pl = TestCaseRunner.default
|
|
134
134
|
this.wrap(
|
|
@@ -4,6 +4,7 @@ const {
|
|
|
4
4
|
TEST_SUITE,
|
|
5
5
|
TEST_STATUS,
|
|
6
6
|
TEST_FRAMEWORK_VERSION,
|
|
7
|
+
TEST_IS_RUM_ACTIVE,
|
|
7
8
|
getTestEnvironmentMetadata,
|
|
8
9
|
CI_APP_ORIGIN,
|
|
9
10
|
getTestParentSpan
|
|
@@ -66,19 +67,28 @@ module.exports = (on, config) => {
|
|
|
66
67
|
}
|
|
67
68
|
})
|
|
68
69
|
}
|
|
69
|
-
return null
|
|
70
|
+
return activeSpan ? activeSpan._spanContext._traceId.toString(10) : null
|
|
70
71
|
},
|
|
71
72
|
'dd:afterEach': (test) => {
|
|
72
|
-
const { state, error } = test
|
|
73
|
+
const { state, error, isRUMActive } = test
|
|
73
74
|
if (activeSpan) {
|
|
74
75
|
activeSpan.setTag(TEST_STATUS, CYPRESS_STATUS_TO_TEST_STATUS[state])
|
|
75
76
|
if (error) {
|
|
76
77
|
activeSpan.setTag('error', error)
|
|
77
78
|
}
|
|
79
|
+
if (isRUMActive) {
|
|
80
|
+
activeSpan.setTag(TEST_IS_RUM_ACTIVE, 'true')
|
|
81
|
+
}
|
|
78
82
|
activeSpan.finish()
|
|
79
83
|
}
|
|
80
84
|
activeSpan = null
|
|
81
85
|
return null
|
|
86
|
+
},
|
|
87
|
+
'dd:addTags': (tags) => {
|
|
88
|
+
if (activeSpan) {
|
|
89
|
+
activeSpan.addTags(tags)
|
|
90
|
+
}
|
|
91
|
+
return null
|
|
82
92
|
}
|
|
83
93
|
})
|
|
84
94
|
}
|