dd-trace 4.0.0-pre-3965634 → 4.0.0-pre-60b4fde

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 (138) hide show
  1. package/LICENSE-3rdparty.csv +1 -2
  2. package/index.d.ts +6 -2
  3. package/package.json +18 -17
  4. package/packages/datadog-instrumentations/src/cucumber.js +80 -3
  5. package/packages/datadog-instrumentations/src/mariadb.js +130 -11
  6. package/packages/datadog-instrumentations/src/mocha.js +12 -3
  7. package/packages/datadog-instrumentations/src/mongodb-core.js +8 -2
  8. package/packages/datadog-instrumentations/src/next.js +32 -4
  9. package/packages/datadog-instrumentations/src/playwright.js +2 -2
  10. package/packages/datadog-plugin-amqp10/src/consumer.js +1 -1
  11. package/packages/datadog-plugin-amqp10/src/index.js +1 -1
  12. package/packages/datadog-plugin-amqp10/src/producer.js +1 -1
  13. package/packages/datadog-plugin-amqplib/src/client.js +1 -1
  14. package/packages/datadog-plugin-amqplib/src/consumer.js +1 -1
  15. package/packages/datadog-plugin-amqplib/src/index.js +1 -1
  16. package/packages/datadog-plugin-amqplib/src/producer.js +1 -1
  17. package/packages/datadog-plugin-aws-sdk/src/base.js +7 -2
  18. package/packages/datadog-plugin-aws-sdk/src/index.js +1 -1
  19. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +2 -0
  20. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +2 -0
  21. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +2 -0
  22. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +2 -0
  23. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +2 -0
  24. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +2 -0
  25. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +2 -0
  26. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +2 -0
  27. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +2 -0
  28. package/packages/datadog-plugin-bunyan/src/index.js +1 -1
  29. package/packages/datadog-plugin-cassandra-driver/src/index.js +1 -1
  30. package/packages/datadog-plugin-connect/src/index.js +1 -1
  31. package/packages/datadog-plugin-couchbase/src/index.js +1 -1
  32. package/packages/datadog-plugin-cucumber/src/index.js +31 -5
  33. package/packages/datadog-plugin-cypress/src/index.js +1 -1
  34. package/packages/datadog-plugin-cypress/src/plugin.js +0 -2
  35. package/packages/datadog-plugin-dns/src/index.js +1 -1
  36. package/packages/datadog-plugin-dns/src/lookup.js +1 -1
  37. package/packages/datadog-plugin-dns/src/lookup_service.js +1 -1
  38. package/packages/datadog-plugin-dns/src/resolve.js +1 -1
  39. package/packages/datadog-plugin-dns/src/reverse.js +1 -1
  40. package/packages/datadog-plugin-elasticsearch/src/index.js +1 -1
  41. package/packages/datadog-plugin-express/src/index.js +1 -1
  42. package/packages/datadog-plugin-fastify/src/index.js +1 -1
  43. package/packages/datadog-plugin-find-my-way/src/index.js +1 -1
  44. package/packages/datadog-plugin-fs/src/index.js +1 -1
  45. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +1 -1
  46. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +1 -1
  47. package/packages/datadog-plugin-google-cloud-pubsub/src/index.js +1 -1
  48. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +1 -1
  49. package/packages/datadog-plugin-graphql/src/execute.js +1 -1
  50. package/packages/datadog-plugin-graphql/src/index.js +1 -1
  51. package/packages/datadog-plugin-graphql/src/parse.js +1 -1
  52. package/packages/datadog-plugin-graphql/src/resolve.js +1 -1
  53. package/packages/datadog-plugin-graphql/src/validate.js +1 -1
  54. package/packages/datadog-plugin-grpc/src/client.js +1 -1
  55. package/packages/datadog-plugin-grpc/src/index.js +1 -1
  56. package/packages/datadog-plugin-grpc/src/server.js +1 -1
  57. package/packages/datadog-plugin-hapi/src/index.js +1 -1
  58. package/packages/datadog-plugin-http/src/client.js +2 -2
  59. package/packages/datadog-plugin-http/src/index.js +1 -1
  60. package/packages/datadog-plugin-http/src/server.js +2 -2
  61. package/packages/datadog-plugin-http2/src/client.js +2 -2
  62. package/packages/datadog-plugin-http2/src/index.js +1 -1
  63. package/packages/datadog-plugin-http2/src/server.js +2 -2
  64. package/packages/datadog-plugin-ioredis/src/index.js +1 -1
  65. package/packages/datadog-plugin-jest/src/index.js +2 -7
  66. package/packages/datadog-plugin-kafkajs/src/consumer.js +1 -1
  67. package/packages/datadog-plugin-kafkajs/src/index.js +1 -1
  68. package/packages/datadog-plugin-kafkajs/src/producer.js +1 -1
  69. package/packages/datadog-plugin-koa/src/index.js +1 -1
  70. package/packages/datadog-plugin-mariadb/src/index.js +18 -1
  71. package/packages/datadog-plugin-memcached/src/index.js +1 -1
  72. package/packages/datadog-plugin-microgateway-core/src/index.js +1 -1
  73. package/packages/datadog-plugin-mocha/src/index.js +4 -4
  74. package/packages/datadog-plugin-moleculer/src/client.js +1 -1
  75. package/packages/datadog-plugin-moleculer/src/index.js +1 -1
  76. package/packages/datadog-plugin-moleculer/src/server.js +1 -1
  77. package/packages/datadog-plugin-mongodb-core/src/index.js +1 -1
  78. package/packages/datadog-plugin-mysql/src/index.js +1 -1
  79. package/packages/datadog-plugin-mysql2/src/index.js +1 -1
  80. package/packages/datadog-plugin-net/src/index.js +9 -75
  81. package/packages/datadog-plugin-net/src/ipc.js +1 -1
  82. package/packages/datadog-plugin-net/src/tcp.js +1 -1
  83. package/packages/datadog-plugin-next/src/index.js +3 -3
  84. package/packages/datadog-plugin-opensearch/src/index.js +1 -1
  85. package/packages/datadog-plugin-oracledb/src/index.js +1 -1
  86. package/packages/datadog-plugin-paperplane/src/index.js +1 -1
  87. package/packages/datadog-plugin-paperplane/src/logger.js +1 -1
  88. package/packages/datadog-plugin-paperplane/src/server.js +1 -1
  89. package/packages/datadog-plugin-pg/src/index.js +1 -1
  90. package/packages/datadog-plugin-pino/src/index.js +1 -1
  91. package/packages/datadog-plugin-playwright/src/index.js +3 -3
  92. package/packages/datadog-plugin-redis/src/index.js +1 -1
  93. package/packages/datadog-plugin-restify/src/index.js +1 -1
  94. package/packages/datadog-plugin-rhea/src/consumer.js +1 -1
  95. package/packages/datadog-plugin-rhea/src/index.js +1 -1
  96. package/packages/datadog-plugin-rhea/src/producer.js +1 -1
  97. package/packages/datadog-plugin-router/src/index.js +8 -8
  98. package/packages/datadog-plugin-sharedb/src/index.js +1 -1
  99. package/packages/datadog-plugin-tedious/src/index.js +1 -1
  100. package/packages/datadog-plugin-web/src/index.js +1 -1
  101. package/packages/datadog-plugin-winston/src/index.js +1 -1
  102. package/packages/dd-trace/src/appsec/gateway/engine/runner.js +2 -1
  103. package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +2 -0
  104. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +2 -2
  105. package/packages/dd-trace/src/appsec/iast/iast-log.js +111 -0
  106. package/packages/dd-trace/src/appsec/iast/index.js +7 -4
  107. package/packages/dd-trace/src/appsec/iast/path-line.js +3 -6
  108. package/packages/dd-trace/src/appsec/iast/taint-tracking/index.js +2 -0
  109. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations.js +2 -0
  110. package/packages/dd-trace/src/appsec/iast/taint-tracking/origin-types.js +2 -0
  111. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +2 -0
  112. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +5 -3
  113. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +5 -3
  114. package/packages/dd-trace/src/appsec/iast/telemetry/log_collector.js +96 -0
  115. package/packages/dd-trace/src/appsec/iast/telemetry/logs.js +87 -0
  116. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +27 -2
  117. package/packages/dd-trace/src/config.js +21 -2
  118. package/packages/dd-trace/src/exporters/common/agents.js +42 -0
  119. package/packages/dd-trace/src/exporters/common/request.js +1 -4
  120. package/packages/dd-trace/src/lambda/handler.js +14 -6
  121. package/packages/dd-trace/src/opentracing/span.js +5 -0
  122. package/packages/dd-trace/src/plugin_manager.js +7 -7
  123. package/packages/dd-trace/src/plugins/ci_plugin.js +13 -15
  124. package/packages/dd-trace/src/plugins/log_plugin.js +1 -1
  125. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  126. package/packages/dd-trace/src/plugins/util/ci.js +12 -0
  127. package/packages/dd-trace/src/plugins/util/test.js +12 -5
  128. package/packages/dd-trace/src/profiling/config.js +68 -2
  129. package/packages/dd-trace/src/profiling/constants.js +16 -0
  130. package/packages/dd-trace/src/profiling/exporter_cli.js +62 -0
  131. package/packages/dd-trace/src/profiling/exporters/agent.js +2 -1
  132. package/packages/dd-trace/src/profiling/profiler.js +21 -8
  133. package/packages/dd-trace/src/profiling/profilers/space.js +21 -1
  134. package/packages/dd-trace/src/span_sampler.js +3 -2
  135. package/packages/dd-trace/src/telemetry/index.js +16 -2
  136. package/packages/dd-trace/src/util.js +10 -1
  137. package/scripts/junit_report.js +0 -25
  138. package/scripts/tdd.js +0 -34
@@ -51,8 +51,6 @@ dev,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
51
51
  dev,jszip,MIT,Copyright 2015-2016 Stuart Knightley and contributors
52
52
  dev,mkdirp,MIT,Copyright 2010 James Halliday
53
53
  dev,mocha,MIT,Copyright 2011-2018 JS Foundation and contributors https://js.foundation
54
- dev,mocha-junit-reporter,MIT,Copyright (c) 2015 Michael Allen
55
- dev,mocha-multi-reporters,MIT,Copyright 2019 Yousaf Nabi and 2015 Stanley Ng
56
54
  dev,multer,MIT,Copyright 2014 Hage Yaapa
57
55
  dev,msgpack-lite,MIT,Copyright 2015 Yusuke Kawasaki
58
56
  dev,nock,MIT,Copyright 2017 Pedro Teixeira and other contributors
@@ -62,6 +60,7 @@ dev,proxyquire,MIT,Copyright 2013 Thorsten Lorenz
62
60
  dev,rimraf,ISC,Copyright Isaac Z. Schlueter and Contributors
63
61
  dev,sinon,BSD-3-Clause,Copyright 2010-2017 Christian Johansen
64
62
  dev,sinon-chai,WTFPL and BSD-2-Clause,Copyright 2004 Sam Hocevar 2012–2017 Domenic Denicola
63
+ dev,tap,ISC,Copyright 2011-2022 Isaac Z. Schlueter and Contributors
65
64
  dev,tape,MIT,Copyright James Halliday
66
65
  dev,wait-on,MIT,Copyright 2015 Jeff Barczewski
67
66
  file,aws-lambda-nodejs-runtime-interface-client,Apache 2.0,Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
package/index.d.ts CHANGED
@@ -98,7 +98,7 @@ export declare interface Tracer extends opentracing.Tracer {
98
98
  * * The function doesn't accept a callback and doesn't return a promise, in
99
99
  * which case the span will finish at the end of the function execution.
100
100
  */
101
- wrap<T = (...args: any[]) => any> (name: string, fn: T, requiresParent?: boolean): T;
101
+ wrap<T = (...args: any[]) => any> (name: string, fn: T): T;
102
102
  wrap<T = (...args: any[]) => any> (name: string, options: TraceOptions & SpanOptions, fn: T): T;
103
103
  wrap<T = (...args: any[]) => any> (name: string, options: (...args: any[]) => TraceOptions & SpanOptions, fn: T): T;
104
104
 
@@ -438,7 +438,11 @@ export declare interface TracerOptions {
438
438
  * Controls how many code vulnerabilities can be detected in the same request
439
439
  * @default 2
440
440
  */
441
- maxContextOperations?: number
441
+ maxContextOperations?: number,
442
+ /**
443
+ * Whether to enable vulnerability deduplication
444
+ */
445
+ deduplicationEnabled?: boolean
442
446
  }
443
447
  };
444
448
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "4.0.0-pre-3965634",
3
+ "version": "4.0.0-pre-60b4fde",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -14,27 +14,29 @@
14
14
  "type:test": "cd docs && yarn && yarn test",
15
15
  "lint": "node scripts/check_licenses.js && eslint . && yarn audit --groups dependencies",
16
16
  "services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
17
- "tdd": "node scripts/tdd.js",
18
17
  "test": "SERVICES=* yarn services && mocha --colors --exit --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
19
- "test:trace:core": "mocha --colors --exit --expose-gc --file packages/dd-trace/test/setup/core.js --exclude \"packages/dd-trace/test/lambda/**/*.spec.js\" --exclude \"packages/dd-trace/test/profiling/**/*.spec.js\" --exclude \"packages/dd-trace/test/appsec/iast/**/*.plugin.spec.js\" \"packages/dd-trace/test/**/*.spec.js\"",
20
- "test:trace:core:ci": "nyc --no-clean --include \"packages/dd-trace/src/**/*.js\" --exclude \"packages/dd-trace/src/lambda/**/*.spec.js\" --exclude \"packages/dd-trace/src/profiling/**/*.js\" --exclude \"packages/dd-trace/test/appsec/iast/**/*.plugin.spec.js\" -- npm run test:trace:core -- --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter.json",
21
- "test:instrumentations": "mocha --colors --file 'packages/dd-trace/test/setup/core.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
18
+ "test:appsec": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" --exclude \"packages/dd-trace/test/appsec/iast/**/*.plugin.spec.js\" \"packages/dd-trace/test/appsec/**/*.spec.js\"",
19
+ "test:appsec:ci": "nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" --exclude \"packages/dd-trace/test/appsec/iast/**/*.plugin.spec.js\" -- npm run test:appsec",
20
+ "test:appsec:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/appsec/iast/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
21
+ "test:appsec:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/test/appsec/iast/**/*.@($(echo $PLUGINS)).plugin.spec.js\" -- npm run test:appsec:plugins",
22
+ "test:trace:core": "tap packages/dd-trace/test/*.spec.js packages/dd-trace/test/{ci-visibility,encode,exporters,opentracing,plugins,telemetry}/**/*.spec.js",
23
+ "test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=packages/dd-trace/src/**/*.js",
24
+ "test:instrumentations": "mocha --colors -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
22
25
  "test:instrumentations:ci": "nyc --no-clean --include 'packages/datadog-instrumentations/src/**/*.js' -- npm run test:instrumentations",
23
- "test:core": "mocha --colors --file packages/datadog-core/test/setup.js 'packages/datadog-core/test/**/*.spec.js'",
24
- "test:core:ci": "nyc --no-clean --include 'packages/datadog-core/src/**/*.js' -- npm run test:core",
25
- "test:lambda": "mocha --colors --exit --file \"packages/dd-trace/test/setup/core.js\" \"packages/dd-trace/test/lambda/**/*.spec.js\"",
26
+ "test:core": "tap packages/datadog-core/test/**/*.spec.js",
27
+ "test:core:ci": "npm run test:core -- --coverage --nyc-arg=--include=packages/datadog-core/src/**/*.js",
28
+ "test:lambda": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/lambda/**/*.spec.js\"",
26
29
  "test:lambda:ci": "nyc --no-clean --include \"packages/dd-trace/src/lambda/**/*.js\" -- npm run test:lambda",
27
- "test:plugins": "mocha --colors --exit --file \"packages/dd-trace/test/setup/core.js\" \"packages/datadog-instrumentations/test/@($(echo $PLUGINS)).spec.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\" \"packages/dd-trace/test/appsec/iast/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
28
- "test:plugins:ci": "yarn services && nyc --no-clean --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS)).js\" --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS))/**/*.js\" --include \"packages/datadog-plugin-@($(echo $PLUGINS))/src/**/*.js\" --include \"packages/dd-trace/test/appsec/iast/**/*.@($(echo $PLUGINS)).plugin.spec.js\" -- npm run test:plugins",
30
+ "test:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-instrumentations/test/@($(echo $PLUGINS)).spec.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\"",
31
+ "test:plugins:ci": "yarn services && nyc --no-clean --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS)).js\" --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS))/**/*.js\" --include \"packages/datadog-plugin-@($(echo $PLUGINS))/src/**/*.js\" -- npm run test:plugins",
29
32
  "test:plugins:upstream": "node ./packages/dd-trace/test/plugins/suite.js",
30
- "test:profiler": "mocha --colors --exit --file \"packages/dd-trace/test/setup/core.js\" \"packages/dd-trace/test/profiling/**/*.spec.js\"",
31
- "test:profiler:ci": "nyc --no-clean --include \"packages/dd-trace/src/profiling/**/*.js\" -- npm run test:profiler",
33
+ "test:profiler": "tap packages/dd-trace/test/profiling/**/*.spec.js",
34
+ "test:profiler:ci": "npm run test:profiler -- --coverage --nyc-arg=--include=packages/dd-trace/src/profiling/**/*.js",
32
35
  "test:integration": "mocha --colors --timeout 30000 \"integration-tests/**/*.spec.js\"",
33
36
  "test:shimmer": "mocha --colors 'packages/datadog-shimmer/test/**/*.spec.js'",
34
37
  "test:shimmer:ci": "nyc --no-clean --include 'packages/datadog-shimmer/src/**/*.js' -- npm run test:shimmer",
35
38
  "leak:core": "node ./scripts/install_plugin_modules && (cd packages/memwatch && yarn) && NODE_PATH=./packages/memwatch/node_modules node --no-warnings ./node_modules/.bin/tape 'packages/dd-trace/test/leak/**/*.js'",
36
- "leak:plugins": "yarn services && (cd packages/memwatch && yarn) && NODE_PATH=./packages/memwatch/node_modules node --no-warnings ./node_modules/.bin/tape \"packages/datadog-plugin-@($(echo $PLUGINS))/test/leak.js\"",
37
- "junit:upload": "node ./scripts/junit_report.js"
39
+ "leak:plugins": "yarn services && (cd packages/memwatch && yarn) && NODE_PATH=./packages/memwatch/node_modules node --no-warnings ./node_modules/.bin/tape \"packages/datadog-plugin-@($(echo $PLUGINS))/test/leak.js\""
38
40
  },
39
41
  "repository": {
40
42
  "type": "git",
@@ -64,7 +66,7 @@
64
66
  "@datadog/native-iast-rewriter": "2.0.1",
65
67
  "@datadog/native-iast-taint-tracking": "1.1.1",
66
68
  "@datadog/native-metrics": "^1.5.0",
67
- "@datadog/pprof": "^2.0.0",
69
+ "@datadog/pprof": "^2.1.0",
68
70
  "@datadog/sketches-js": "^2.1.0",
69
71
  "crypto-randomuuid": "^1.0.0",
70
72
  "diagnostics_channel": "^1.1.0",
@@ -114,8 +116,6 @@
114
116
  "jszip": "^3.5.0",
115
117
  "mkdirp": "^0.5.1",
116
118
  "mocha": "8",
117
- "mocha-junit-reporter": "^2.1.0",
118
- "mocha-multi-reporters": "^1.5.1",
119
119
  "msgpack-lite": "^0.1.26",
120
120
  "multer": "^1.4.5-lts.1",
121
121
  "nock": "^11.3.3",
@@ -125,6 +125,7 @@
125
125
  "rimraf": "^3.0.0",
126
126
  "sinon": "^11.1.2",
127
127
  "sinon-chai": "^3.7.0",
128
+ "tap": "^16.3.4",
128
129
  "tape": "^4.9.1",
129
130
  "wait-on": "^5.0.0"
130
131
  }
@@ -1,4 +1,5 @@
1
1
  'use strict'
2
+ const { createCoverageMap } = require('istanbul-lib-coverage')
2
3
 
3
4
  const { addHook, channel, AsyncResource } = require('./helpers/instrument')
4
5
  const shimmer = require('../../datadog-shimmer')
@@ -12,10 +13,24 @@ const errorCh = channel('ci:cucumber:error')
12
13
 
13
14
  const testSuiteStartCh = channel('ci:cucumber:test-suite:start')
14
15
  const testSuiteFinishCh = channel('ci:cucumber:test-suite:finish')
16
+ const testSuiteCodeCoverageCh = channel('ci:cucumber:test-suite:code-coverage')
15
17
 
18
+ const itrConfigurationCh = channel('ci:cucumber:itr-configuration')
19
+ const skippableSuitesCh = channel('ci:cucumber:test-suite:skippable')
16
20
  const sessionStartCh = channel('ci:cucumber:session:start')
17
21
  const sessionFinishCh = channel('ci:cucumber:session:finish')
18
22
 
23
+ const {
24
+ getCoveredFilenamesFromCoverage,
25
+ resetCoverage,
26
+ mergeCoverage,
27
+ fromCoverageMapToCoverage,
28
+ getTestSuitePath
29
+ } = require('../../dd-trace/src/plugins/util/test')
30
+
31
+ // We'll preserve the original coverage here
32
+ const originalCoverageMap = createCoverageMap()
33
+
19
34
  // TODO: remove in a later major version
20
35
  const patched = new WeakSet()
21
36
 
@@ -88,12 +103,25 @@ function wrapRun (pl, isLatestVersion) {
88
103
  } else {
89
104
  pickleResultByFile[testSuiteFullPath].push(status)
90
105
  }
106
+ testFinishCh.publish({ status, skipReason, errorMessage })
91
107
  // last test in suite
92
108
  if (pickleResultByFile[testSuiteFullPath].length === pickleByFile[testSuiteFullPath].length) {
93
109
  const testSuiteStatus = getSuiteStatusFromTestStatuses(pickleResultByFile[testSuiteFullPath])
110
+ if (global.__coverage__) {
111
+ const coverageFiles = getCoveredFilenamesFromCoverage(global.__coverage__)
112
+
113
+ testSuiteCodeCoverageCh.publish({
114
+ coverageFiles,
115
+ suiteFile: testSuiteFullPath
116
+ })
117
+ // We need to reset coverage to get a code coverage per suite
118
+ // Before that, we preserve the original coverage
119
+ mergeCoverage(global.__coverage__, originalCoverageMap)
120
+ resetCoverage(global.__coverage__)
121
+ }
122
+
94
123
  testSuiteFinishCh.publish(testSuiteStatus)
95
124
  }
96
- testFinishCh.publish({ status, skipReason, errorMessage })
97
125
  })
98
126
  return promise
99
127
  } catch (err) {
@@ -164,6 +192,13 @@ addHook({
164
192
  file: 'lib/runtime/test_case_runner.js'
165
193
  }, testCaseHook)
166
194
 
195
+ function getPicklesToRun (runtime, suitesToSkip) {
196
+ return runtime.pickleIds.filter((pickleId) => {
197
+ const test = runtime.eventDataCollector.getPickle(pickleId)
198
+ return !suitesToSkip.includes(getTestSuitePath(test.uri, process.cwd()))
199
+ }, {})
200
+ }
201
+
167
202
  function getPickleByFile (runtime) {
168
203
  return runtime.pickleIds.reduce((acc, pickleId) => {
169
204
  const test = runtime.eventDataCollector.getPickle(pickleId)
@@ -182,19 +217,61 @@ addHook({
182
217
  file: 'lib/runtime/index.js'
183
218
  }, (runtimePackage, cucumberVersion) => {
184
219
  shimmer.wrap(runtimePackage.default.prototype, 'start', start => async function () {
220
+ const asyncResource = new AsyncResource('bound-anonymous-fn')
221
+ let onDone
222
+
223
+ const configPromise = new Promise(resolve => {
224
+ onDone = resolve
225
+ })
226
+
227
+ asyncResource.runInAsyncScope(() => {
228
+ itrConfigurationCh.publish({ onDone })
229
+ })
230
+
231
+ await configPromise
232
+
233
+ const skippableSuitesPromise = new Promise(resolve => {
234
+ onDone = resolve
235
+ })
236
+
237
+ asyncResource.runInAsyncScope(() => {
238
+ skippableSuitesCh.publish({ onDone })
239
+ })
240
+
241
+ const { err, skippableSuites } = await skippableSuitesPromise
242
+
243
+ if (!err) {
244
+ this.pickleIds = getPicklesToRun(this, skippableSuites)
245
+ }
246
+
185
247
  pickleByFile = getPickleByFile(this)
186
248
 
187
249
  const processArgv = process.argv.slice(2).join(' ')
188
250
  const command = process.env.npm_lifecycle_script || `cucumber-js ${processArgv}`
189
251
 
190
- const asyncResource = new AsyncResource('bound-anonymous-fn')
191
252
  asyncResource.runInAsyncScope(() => {
192
253
  sessionStartCh.publish({ command, frameworkVersion: cucumberVersion })
193
254
  })
194
255
  const success = await start.apply(this, arguments)
195
256
 
257
+ let testCodeCoverageLinesTotal
258
+
259
+ if (global.__coverage__) {
260
+ try {
261
+ testCodeCoverageLinesTotal = originalCoverageMap.getCoverageSummary().lines.pct
262
+ } catch (e) {
263
+ // ignore errors
264
+ }
265
+ // restore the original coverage
266
+ global.__coverage__ = fromCoverageMapToCoverage(originalCoverageMap)
267
+ }
268
+
196
269
  asyncResource.runInAsyncScope(() => {
197
- sessionFinishCh.publish(success ? 'pass' : 'fail')
270
+ sessionFinishCh.publish({
271
+ status: success ? 'pass' : 'fail',
272
+ isSuitesSkipped: skippableSuites ? !!skippableSuites.length : false,
273
+ testCodeCoverageLinesTotal
274
+ })
198
275
  })
199
276
  return success
200
277
  })
@@ -7,17 +7,17 @@ const shimmer = require('../../datadog-shimmer')
7
7
  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
+ const skipCh = channel('apm:mariadb:pool:skip')
11
+ const unskipCh = channel('apm:mariadb:pool:unskip')
10
12
 
11
- function wrapCommandStart (start) {
13
+ function wrapCommandStart (start, callbackResource) {
12
14
  return function () {
13
15
  if (!startCh.hasSubscribers) return start.apply(this, arguments)
14
16
 
15
- const callbackResource = new AsyncResource('bound-anonymous-fn')
16
-
17
17
  const resolve = callbackResource.bind(this.resolve)
18
18
  const reject = callbackResource.bind(this.reject)
19
19
 
20
- const asyncResource = new AsyncResource('bound-anonymous-fn')
20
+ const asyncResource = callbackResource.runInAsyncScope(() => new AsyncResource('bound-anonymous-fn'))
21
21
 
22
22
  shimmer.wrap(this, 'resolve', function wrapResolve () {
23
23
  return function () {
@@ -47,17 +47,136 @@ function wrapCommandStart (start) {
47
47
  }
48
48
  }
49
49
 
50
+ function wrapCommand (Command) {
51
+ return class extends Command {
52
+ constructor (...args) {
53
+ super(...args)
54
+
55
+ const callbackResource = new AsyncResource('bound-anonymous-fn')
56
+
57
+ if (this.start) {
58
+ this.start = wrapCommandStart(this.start, callbackResource)
59
+ }
60
+ }
61
+ }
62
+ }
63
+
64
+ function createWrapQuery (options) {
65
+ return function wrapQuery (query) {
66
+ return function (sql) {
67
+ if (!startCh.hasSubscribers) return query.apply(this, arguments)
68
+
69
+ const asyncResource = new AsyncResource('bound-anonymous-fn')
70
+
71
+ return asyncResource.runInAsyncScope(() => {
72
+ startCh.publish({ sql, conf: options })
73
+
74
+ return query.apply(this, arguments)
75
+ .then(result => {
76
+ finishCh.publish()
77
+ return result
78
+ }, error => {
79
+ errorCh.publish(error)
80
+ finishCh.publish()
81
+ throw error
82
+ })
83
+ }, 'bound-anonymous-fn')
84
+ }
85
+ }
86
+ }
87
+
88
+ function createWrapQueryCallback (options) {
89
+ return function wrapQuery (query) {
90
+ return function (sql) {
91
+ if (!startCh.hasSubscribers) return query.apply(this, arguments)
92
+
93
+ const cb = arguments[arguments.length - 1]
94
+ const asyncResource = new AsyncResource('bound-anonymous-fn')
95
+ const callbackResource = new AsyncResource('bound-anonymous-fn')
96
+
97
+ if (typeof cb !== 'function') {
98
+ arguments.length = arguments.length + 1
99
+ }
100
+
101
+ arguments[arguments.length - 1] = asyncResource.bind(function (err) {
102
+ if (err) {
103
+ errorCh.publish(err)
104
+ }
105
+
106
+ finishCh.publish()
107
+
108
+ if (typeof cb === 'function') {
109
+ return callbackResource.runInAsyncScope(() => cb.apply(this, arguments))
110
+ }
111
+ })
112
+
113
+ return asyncResource.runInAsyncScope(() => {
114
+ startCh.publish({ sql, conf: options })
115
+
116
+ return query.apply(this, arguments)
117
+ }, 'bound-anonymous-fn')
118
+ }
119
+ }
120
+ }
121
+
122
+ function wrapConnection (Connection, promiseMethod) {
123
+ return function (options) {
124
+ Connection.apply(this, arguments)
125
+
126
+ shimmer.wrap(this, promiseMethod, createWrapQuery(options))
127
+ shimmer.wrap(this, '_queryCallback', createWrapQueryCallback(options))
128
+ }
129
+ }
130
+
131
+ function wrapPoolBase (PoolBase) {
132
+ return function (options, processTask, createConnectionPool, pingPromise) {
133
+ arguments[1] = wrapPoolMethod(processTask)
134
+ arguments[2] = wrapPoolMethod(createConnectionPool)
135
+
136
+ PoolBase.apply(this, arguments)
137
+
138
+ shimmer.wrap(this, 'query', createWrapQuery(options.connOptions))
139
+ }
140
+ }
141
+
142
+ // It's not possible to prevent connection pools from leaking across queries,
143
+ // so instead we just skip instrumentation completely to avoid memory leaks
144
+ // and/or orphan spans.
145
+ function wrapPoolMethod (createConnection) {
146
+ return function () {
147
+ skipCh.publish()
148
+ try {
149
+ return createConnection.apply(this, arguments)
150
+ } finally {
151
+ unskipCh.publish()
152
+ }
153
+ }
154
+ }
155
+
50
156
  const name = 'mariadb'
51
- const versions = ['>=2.0.3']
52
157
 
53
- addHook({ name, file: 'lib/cmd/query.js', versions }, (Query) => {
54
- shimmer.wrap(Query.prototype, 'start', wrapCommandStart)
158
+ addHook({ name, file: 'lib/cmd/query.js', versions: ['>=3'] }, (Query) => {
159
+ return wrapCommand(Query)
160
+ })
161
+
162
+ addHook({ name, file: 'lib/cmd/execute.js', versions: ['>=3'] }, (Execute) => {
163
+ return wrapCommand(Execute)
164
+ })
165
+
166
+ addHook({ name, file: 'lib/pool.js', versions: ['>=3'] }, (Pool) => {
167
+ shimmer.wrap(Pool.prototype, '_createConnection', wrapPoolMethod)
55
168
 
56
- return Query
169
+ return Pool
57
170
  })
58
171
 
59
- addHook({ name, file: 'lib/cmd/execute.js', versions }, (Query) => {
60
- shimmer.wrap(Query.prototype, 'start', wrapCommandStart)
172
+ addHook({ name, file: 'lib/connection.js', versions: ['>=2.5.2 <3'] }, (Connection) => {
173
+ return shimmer.wrap(Connection, wrapConnection(Connection, '_queryPromise'))
174
+ })
175
+
176
+ addHook({ name, file: 'lib/connection.js', versions: ['>=2.0.4 <=2.5.1'] }, (Connection) => {
177
+ return shimmer.wrap(Connection, wrapConnection(Connection, 'query'))
178
+ })
61
179
 
62
- return Query
180
+ addHook({ name, file: 'lib/pool-base.js', versions: ['>=2.0.4 <3'] }, (PoolBase) => {
181
+ return shimmer.wrap(PoolBase, wrapPoolBase(PoolBase))
63
182
  })
@@ -125,9 +125,18 @@ function mochaHook (Runner) {
125
125
 
126
126
  const isSuitesSkipped = !!suitesToSkip.length
127
127
 
128
- testSessionFinishCh.publish({ status, isSuitesSkipped })
129
- // restore the original coverage
130
- global.__coverage__ = fromCoverageMapToCoverage(originalCoverageMap)
128
+ let testCodeCoverageLinesTotal
129
+ if (global.__coverage__) {
130
+ try {
131
+ testCodeCoverageLinesTotal = originalCoverageMap.getCoverageSummary().lines.pct
132
+ } catch (e) {
133
+ // ignore errors
134
+ }
135
+ // restore the original coverage
136
+ global.__coverage__ = fromCoverageMapToCoverage(originalCoverageMap)
137
+ }
138
+
139
+ testSessionFinishCh.publish({ status, isSuitesSkipped, testCodeCoverageLinesTotal })
131
140
  }))
132
141
 
133
142
  this.once('start', testRunAsyncResource.bind(function () {
@@ -25,13 +25,19 @@ addHook({ name: 'mongodb-core', versions: ['2 - 3.1.9'] }, Server => {
25
25
  return Server
26
26
  })
27
27
 
28
- addHook({ name: 'mongodb', versions: ['>=4'], file: 'lib/cmap/connection.js' }, Connection => {
28
+ addHook({ name: 'mongodb', versions: ['>=4 <4.6.0'], file: 'lib/cmap/connection.js' }, Connection => {
29
29
  const proto = Connection.Connection.prototype
30
30
  shimmer.wrap(proto, 'command', command => wrapConnectionCommand(command, 'command'))
31
31
  shimmer.wrap(proto, 'query', query => wrapConnectionCommand(query, 'query'))
32
32
  return Connection
33
33
  })
34
34
 
35
+ addHook({ name: 'mongodb', versions: ['>=4.6.0'], file: 'lib/cmap/connection.js' }, Connection => {
36
+ const proto = Connection.Connection.prototype
37
+ shimmer.wrap(proto, 'command', command => wrapConnectionCommand(command, 'command'))
38
+ return Connection
39
+ })
40
+
35
41
  addHook({ name: 'mongodb', versions: ['>=3.3 <4'], file: 'lib/core/wireprotocol/index.js' }, wp => wrapWp(wp))
36
42
 
37
43
  addHook({ name: 'mongodb-core', versions: ['>=3.2'], file: 'lib/wireprotocol/index.js' }, wp => wrapWp(wp))
@@ -46,7 +52,7 @@ addHook({ name: 'mongodb-core', versions: ['~3.1.10'], file: 'lib/wireprotocol/2
46
52
  return WireProtocol
47
53
  })
48
54
 
49
- addHook({ name: 'mongodb', versions: ['>=3.5.4'], file: 'lib/utils.js' }, util => {
55
+ addHook({ name: 'mongodb', versions: ['>=3.5.4 <4.11.0'], file: 'lib/utils.js' }, util => {
50
56
  shimmer.wrap(util, 'maybePromise', maybePromise => function (parent, callback, fn) {
51
57
  const asyncResource = new AsyncResource('bound-anonymous-fn')
52
58
  const callbackIndex = arguments.length - 2
@@ -26,16 +26,33 @@ function wrapHandleApiRequest (handleApiRequest) {
26
26
  return promise.then(handled => {
27
27
  if (!handled) return handled
28
28
 
29
- const page = getPageFromPath(pathname, this.dynamicRoutes)
29
+ return this.hasPage(pathname).then(pageFound => {
30
+ const page = pageFound ? pathname : getPageFromPath(pathname, this.dynamicRoutes)
30
31
 
31
- pageLoadChannel.publish({ page })
32
+ pageLoadChannel.publish({ page })
32
33
 
33
- return handled
34
+ return handled
35
+ })
34
36
  })
35
37
  })
36
38
  }
37
39
  }
38
40
 
41
+ // next 13.2 handleApiRequest uses a different set of parameters
42
+ function wrapHandleApiRequestWithMatch (handleApiRequest) {
43
+ return function (req, res, query, match) {
44
+ return instrument(req, res, () => {
45
+ const page = (typeof match === 'object' && typeof match.definition === 'object')
46
+ ? match.definition.pathname
47
+ : undefined
48
+
49
+ pageLoadChannel.publish({ page })
50
+
51
+ return handleApiRequest.apply(this, arguments)
52
+ })
53
+ }
54
+ }
55
+
39
56
  function wrapRenderToResponse (renderToResponse) {
40
57
  return function (ctx) {
41
58
  return instrument(ctx.req, ctx.res, () => renderToResponse.apply(this, arguments))
@@ -127,7 +144,18 @@ function finish (req, res, result, err) {
127
144
  return result
128
145
  }
129
146
 
130
- // TODO: 13.2 support
147
+ addHook({ name: 'next', versions: ['>=13.2'], file: 'dist/server/next-server.js' }, nextServer => {
148
+ const Server = nextServer.default
149
+
150
+ shimmer.wrap(Server.prototype, 'handleRequest', wrapHandleRequest)
151
+ shimmer.wrap(Server.prototype, 'handleApiRequest', wrapHandleApiRequestWithMatch)
152
+ shimmer.wrap(Server.prototype, 'renderToResponse', wrapRenderToResponse)
153
+ shimmer.wrap(Server.prototype, 'renderErrorToResponse', wrapRenderErrorToResponse)
154
+ shimmer.wrap(Server.prototype, 'findPageComponents', wrapFindPageComponents)
155
+
156
+ return nextServer
157
+ })
158
+
131
159
  addHook({ name: 'next', versions: ['>=11.1 <13.2'], file: 'dist/server/next-server.js' }, nextServer => {
132
160
  const Server = nextServer.default
133
161
 
@@ -76,7 +76,7 @@ function getRootDir (playwrightRunner) {
76
76
  }
77
77
 
78
78
  function testBeginHandler (test) {
79
- const { title: testName, location: { file: testSuiteAbsolutePath }, _type } = test
79
+ const { _requireFile: testSuiteAbsolutePath, title: testName, _type } = test
80
80
 
81
81
  if (_type === 'beforeAll' || _type === 'afterAll') {
82
82
  return
@@ -101,7 +101,7 @@ function testBeginHandler (test) {
101
101
  }
102
102
 
103
103
  function testEndHandler (test, testStatus, error) {
104
- const { location: { file: testSuiteAbsolutePath }, results, _type } = test
104
+ const { _requireFile: testSuiteAbsolutePath, results, _type } = test
105
105
 
106
106
  if (_type === 'beforeAll' || _type === 'afterAll') {
107
107
  return
@@ -4,7 +4,7 @@ const ConsumerPlugin = require('../../dd-trace/src/plugins/consumer')
4
4
  const { getAddress, getShortName } = require('./util')
5
5
 
6
6
  class Amqp10ConsumerPlugin extends ConsumerPlugin {
7
- static get name () { return 'amqp10' }
7
+ static get id () { return 'amqp10' }
8
8
  static get system () { return 'amqp' }
9
9
 
10
10
  start ({ link }) {
@@ -5,7 +5,7 @@ const ConsumerPlugin = require('./consumer')
5
5
  const CompositePlugin = require('../../dd-trace/src/plugins/composite')
6
6
 
7
7
  class Amqp10Plugin extends CompositePlugin {
8
- static get name () { return 'amqp10' }
8
+ static get id () { return 'amqp10' }
9
9
  static get plugins () {
10
10
  return {
11
11
  producer: ProducerPlugin,
@@ -5,7 +5,7 @@ const { CLIENT_PORT_KEY } = require('../../dd-trace/src/constants')
5
5
  const { getAddress, getShortName } = require('./util')
6
6
 
7
7
  class Amqp10ProducerPlugin extends ProducerPlugin {
8
- static get name () { return 'amqp10' }
8
+ static get id () { return 'amqp10' }
9
9
  static get operation () { return 'send' }
10
10
  static get system () { return 'amqp' }
11
11
 
@@ -6,7 +6,7 @@ const ClientPlugin = require('../../dd-trace/src/plugins/client')
6
6
  const { getResourceName } = require('./util')
7
7
 
8
8
  class AmqplibClientPlugin extends ClientPlugin {
9
- static get name () { return 'amqplib' }
9
+ static get id () { return 'amqplib' }
10
10
  static get operation () { return 'command' }
11
11
 
12
12
  start ({ channel = {}, method, fields }) {
@@ -5,7 +5,7 @@ const ConsumerPlugin = require('../../dd-trace/src/plugins/consumer')
5
5
  const { getResourceName } = require('./util')
6
6
 
7
7
  class AmqplibConsumerPlugin extends ConsumerPlugin {
8
- static get name () { return 'amqplib' }
8
+ static get id () { return 'amqplib' }
9
9
  static get operation () { return 'command' }
10
10
 
11
11
  start ({ method, fields, message }) {
@@ -7,7 +7,7 @@ const CompositePlugin = require('../../dd-trace/src/plugins/composite')
7
7
 
8
8
  // TODO: Consider splitting channels for publish/receive in the instrumentation.
9
9
  class AmqplibPlugin extends CompositePlugin {
10
- static get name () { return 'amqplib' }
10
+ static get id () { return 'amqplib' }
11
11
  static get plugins () {
12
12
  return {
13
13
  producer: ProducerPlugin,
@@ -6,7 +6,7 @@ const ProducerPlugin = require('../../dd-trace/src/plugins/producer')
6
6
  const { getResourceName } = require('./util')
7
7
 
8
8
  class AmqplibProducerPlugin extends ProducerPlugin {
9
- static get name () { return 'amqplib' }
9
+ static get id () { return 'amqplib' }
10
10
  static get operation () { return 'command' }
11
11
 
12
12
  start ({ channel = {}, method, fields }) {
@@ -3,10 +3,13 @@
3
3
  const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
4
4
  const Plugin = require('../../dd-trace/src/plugins/plugin')
5
5
  const { storage } = require('../../datadog-core')
6
+ const { isTrue } = require('../../dd-trace/src/util')
6
7
 
7
8
  class BaseAwsSdkPlugin extends Plugin {
9
+ static get id () { return 'aws' }
10
+
8
11
  get serviceIdentifier () {
9
- const id = this.constructor.name.toLowerCase()
12
+ const id = this.constructor.id.toLowerCase()
10
13
  Object.defineProperty(this, 'serviceIdentifier', {
11
14
  configurable: true,
12
15
  writable: true,
@@ -74,7 +77,9 @@ class BaseAwsSdkPlugin extends Plugin {
74
77
  }
75
78
 
76
79
  isEnabled (request) {
77
- return true
80
+ const serviceId = this.serviceIdentifier.toUpperCase()
81
+ const envVarValue = process.env[`DD_TRACE_AWS_SDK_${serviceId}_ENABLED`]
82
+ return envVarValue ? isTrue(envVarValue) : true
78
83
  }
79
84
 
80
85
  addResponseTags (span, response) {