dd-trace 4.0.0-pre-4e7da80 → 4.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "4.0.0-pre-4e7da80",
3
+ "version": "4.0.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -63,7 +63,7 @@
63
63
  },
64
64
  "homepage": "https://github.com/DataDog/dd-trace-js#readme",
65
65
  "engines": {
66
- "node": ">=14"
66
+ "node": ">=16"
67
67
  },
68
68
  "dependencies": {
69
69
  "@datadog/native-appsec": "^3.1.0",
@@ -95,7 +95,7 @@
95
95
  "semver": "^7.3.8"
96
96
  },
97
97
  "devDependencies": {
98
- "@types/node": ">=14",
98
+ "@types/node": ">=16",
99
99
  "autocannon": "^4.5.2",
100
100
  "axios": "^0.21.2",
101
101
  "benchmark": "^2.1.4",
@@ -4,6 +4,8 @@ const types = require('./types')
4
4
  const { addHook, channel, AsyncResource } = require('../helpers/instrument')
5
5
  const shimmer = require('../../../datadog-shimmer')
6
6
 
7
+ const nodeMajor = parseInt(process.versions.node.split('.')[0])
8
+
7
9
  const patched = new WeakSet()
8
10
  const instances = new WeakMap()
9
11
 
@@ -232,13 +234,15 @@ function patch (grpc) {
232
234
  return grpc
233
235
  }
234
236
 
235
- addHook({ name: 'grpc', versions: ['>=1.24.3'] }, patch)
237
+ if (nodeMajor <= 14) {
238
+ addHook({ name: 'grpc', versions: ['>=1.24.3'] }, patch)
236
239
 
237
- addHook({ name: 'grpc', versions: ['>=1.24.3'], file: 'src/client.js' }, client => {
238
- shimmer.wrap(client, 'makeClientConstructor', createWrapMakeClientConstructor())
240
+ addHook({ name: 'grpc', versions: ['>=1.24.3'], file: 'src/client.js' }, client => {
241
+ shimmer.wrap(client, 'makeClientConstructor', createWrapMakeClientConstructor())
239
242
 
240
- return client
241
- })
243
+ return client
244
+ })
245
+ }
242
246
 
243
247
  addHook({ name: '@grpc/grpc-js', versions: ['>=1.0.3'] }, patch)
244
248
 
@@ -4,6 +4,8 @@ const types = require('./types')
4
4
  const { channel, addHook, AsyncResource } = require('../helpers/instrument')
5
5
  const shimmer = require('../../../datadog-shimmer')
6
6
 
7
+ const nodeMajor = parseInt(process.versions.node.split('.')[0])
8
+
7
9
  const startChannel = channel('apm:grpc:server:request:start')
8
10
  const errorChannel = channel('apm:grpc:server:request:error')
9
11
  const updateChannel = channel('apm:grpc:server:request:update')
@@ -139,11 +141,13 @@ function isEmitter (obj) {
139
141
  return typeof obj.emit === 'function' && typeof obj.once === 'function'
140
142
  }
141
143
 
142
- addHook({ name: 'grpc', versions: ['>=1.24.3'], file: 'src/server.js' }, server => {
143
- shimmer.wrap(server.Server.prototype, 'register', wrapRegister)
144
+ if (nodeMajor <= 14) {
145
+ addHook({ name: 'grpc', versions: ['>=1.24.3'], file: 'src/server.js' }, server => {
146
+ shimmer.wrap(server.Server.prototype, 'register', wrapRegister)
144
147
 
145
- return server
146
- })
148
+ return server
149
+ })
150
+ }
147
151
 
148
152
  addHook({ name: '@grpc/grpc-js', versions: ['>=1.0.3'], file: 'build/src/server.js' }, server => {
149
153
  shimmer.wrap(server.Server.prototype, 'register', wrapRegister)
@@ -9,8 +9,15 @@ const {
9
9
  getCoveredFilenamesFromCoverage,
10
10
  JEST_WORKER_TRACE_PAYLOAD_CODE,
11
11
  JEST_WORKER_COVERAGE_PAYLOAD_CODE,
12
- getTestLineStart
12
+ getTestLineStart,
13
+ getTestSuitePath,
14
+ getTestParametersString
13
15
  } = require('../../dd-trace/src/plugins/util/test')
16
+ const {
17
+ getFormattedJestTestParameters,
18
+ getJestTestName,
19
+ getJestSuitesToRun
20
+ } = require('../../datadog-plugin-jest/src/util')
14
21
 
15
22
  const testSessionStartCh = channel('ci:jest:session:start')
16
23
  const testSessionFinishCh = channel('ci:jest:session:finish')
@@ -37,13 +44,6 @@ let skippableSuites = []
37
44
  let isCodeCoverageEnabled = false
38
45
  let isSuitesSkippingEnabled = false
39
46
 
40
- const {
41
- getTestSuitePath,
42
- getTestParametersString
43
- } = require('../../dd-trace/src/plugins/util/test')
44
-
45
- const { getFormattedJestTestParameters, getJestTestName } = require('../../datadog-plugin-jest/src/util')
46
-
47
47
  const sessionAsyncResource = new AsyncResource('bound-anonymous-fn')
48
48
 
49
49
  const specStatusToTestStatus = {
@@ -429,10 +429,7 @@ addHook({
429
429
  const testPaths = await getTestPaths.apply(this, arguments)
430
430
  const { tests } = testPaths
431
431
 
432
- const filteredTests = tests.filter(({ path: testPath }) => {
433
- const relativePath = testPath.replace(`${rootDir}/`, '')
434
- return !skippableSuites.includes(relativePath)
435
- })
432
+ const filteredTests = getJestSuitesToRun(skippableSuites, tests, rootDir)
436
433
 
437
434
  skippableSuites = []
438
435
 
@@ -1,3 +1,5 @@
1
+ const { getTestSuitePath } = require('../../dd-trace/src/plugins/util/test')
2
+
1
3
  /**
2
4
  * There are two ways to call `test.each` in `jest`:
3
5
  * 1. With an array of arrays: https://jestjs.io/docs/api#1-testeachtablename-fn-timeout
@@ -45,4 +47,11 @@ function getJestTestName (test) {
45
47
  return titles.join(' ')
46
48
  }
47
49
 
48
- module.exports = { getFormattedJestTestParameters, getJestTestName }
50
+ function getJestSuitesToRun (skippableSuites, originalTests, rootDir) {
51
+ return originalTests.filter(({ path: testPath }) => {
52
+ const relativePath = getTestSuitePath(testPath, rootDir)
53
+ return !skippableSuites.includes(relativePath)
54
+ })
55
+ }
56
+
57
+ module.exports = { getFormattedJestTestParameters, getJestTestName, getJestSuitesToRun }
@@ -51,7 +51,7 @@ function onIncomingHttpRequestStart (data) {
51
51
  }
52
52
  if (rootSpan.addTags) {
53
53
  rootSpan.addTags({
54
- [IAST_ENABLED_TAG_KEY]: isRequestAcquired ? '1' : '0'
54
+ [IAST_ENABLED_TAG_KEY]: isRequestAcquired ? 1 : 0
55
55
  })
56
56
  }
57
57
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  const iastLog = require('../../../iast-log')
4
4
 
5
- const COMMAND_PATTERN = '^(?:\\s*(?:sudo|doas)\\s+)?\\b\\S+\\b(.*)'
5
+ const COMMAND_PATTERN = '^(?:\\s*(?:sudo|doas)\\s+)?\\b\\S+\\b\\s(.*)'
6
6
 
7
7
  class CommandSensitiveAnalyzer {
8
8
  constructor () {
@@ -2,14 +2,15 @@
2
2
 
3
3
  const fs = require('fs')
4
4
  const os = require('os')
5
+ const uuid = require('crypto-randomuuid')
5
6
  const URL = require('url').URL
6
7
  const log = require('./log')
7
8
  const pkg = require('./pkg')
8
9
  const coalesce = require('koalas')
9
10
  const tagger = require('./tagger')
10
11
  const { isTrue, isFalse } = require('./util')
11
- const uuid = require('crypto-randomuuid')
12
12
  const { GIT_REPOSITORY_URL, GIT_COMMIT_SHA } = require('./plugins/util/tags')
13
+ const { getGitMetadataFromGitProperties } = require('./git_properties')
13
14
 
14
15
  const fromEntries = Object.fromEntries || (entries =>
15
16
  entries.reduce((obj, [k, v]) => Object.assign(obj, { [k]: v }), {}))
@@ -539,6 +540,18 @@ ken|consumer_?(?:id|key|secret)|sign(?:ed|ature)?|auth(?:entication|orization)?)
539
540
  process.env.DD_GIT_COMMIT_SHA,
540
541
  this.tags[GIT_COMMIT_SHA]
541
542
  )
543
+ if (!this.repositoryUrl || !this.commitSHA) {
544
+ const DD_GIT_PROPERTIES_FILE = coalesce(
545
+ process.env.DD_GIT_PROPERTIES_FILE,
546
+ `${process.cwd()}/git.properties`
547
+ )
548
+ const gitPropertiesString = maybeFile(DD_GIT_PROPERTIES_FILE)
549
+ if (gitPropertiesString) {
550
+ const { commitSHA, repositoryUrl } = getGitMetadataFromGitProperties(gitPropertiesString)
551
+ this.commitSHA = this.commitSHA || commitSHA
552
+ this.repositoryUrl = this.repositoryUrl || repositoryUrl
553
+ }
554
+ }
542
555
  }
543
556
 
544
557
  this.stats = {
@@ -0,0 +1,32 @@
1
+ const commitSHARegex = /git\.commit\.sha=([a-f\d]{40})/
2
+ const repositoryUrlRegex = /git\.repository_url=([\w\d:@/.-]+)/
3
+
4
+ function getGitMetadataFromGitProperties (gitPropertiesString) {
5
+ if (!gitPropertiesString) {
6
+ return {}
7
+ }
8
+ const commitSHAMatch = gitPropertiesString.match(commitSHARegex)
9
+ const repositoryUrlMatch = gitPropertiesString.match(repositoryUrlRegex)
10
+
11
+ const repositoryUrl = repositoryUrlMatch ? repositoryUrlMatch[1] : undefined
12
+ let parsedUrl = repositoryUrl
13
+
14
+ if (repositoryUrl) {
15
+ try {
16
+ // repository URLs can contain username and password, so we want to filter those out
17
+ parsedUrl = new URL(repositoryUrl)
18
+ if (parsedUrl.password) {
19
+ parsedUrl = `${parsedUrl.origin}${parsedUrl.pathname}`
20
+ }
21
+ } catch (e) {
22
+ // if protocol isn't https, no password will be used
23
+ }
24
+ }
25
+
26
+ return {
27
+ commitSHA: commitSHAMatch ? commitSHAMatch[1] : undefined,
28
+ repositoryUrl: parsedUrl
29
+ }
30
+ }
31
+
32
+ module.exports = { getGitMetadataFromGitProperties }