Skip to content

Commit 0b35be5

Browse files
authored
Merge branch 'master' into mhlidd/extracted_span_links
2 parents 7fe481c + 61c5a32 commit 0b35be5

67 files changed

Lines changed: 1806 additions & 666 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/appsec.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,17 @@ jobs:
264264
- uses: ./.github/actions/node/latest
265265
- run: yarn test:appsec:plugins:ci
266266
- uses: codecov/codecov-action@v3
267+
268+
template:
269+
runs-on: ubuntu-latest
270+
env:
271+
PLUGINS: handlebars|pug
272+
steps:
273+
- uses: actions/checkout@v4
274+
- uses: ./.github/actions/node/setup
275+
- uses: ./.github/actions/install
276+
- uses: ./.github/actions/node/oldest
277+
- run: yarn test:appsec:plugins:ci
278+
- uses: ./.github/actions/node/latest
279+
- run: yarn test:appsec:plugins:ci
280+
- uses: codecov/codecov-action@v3

.github/workflows/system-tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ jobs:
2626
name: system_tests_binaries
2727
path: ./binaries/**/*
2828

29-
get-essential-scenarios:
29+
get-scenarios:
3030
name: Get parameters
3131
uses: DataDog/system-tests/.github/workflows/compute-workflow-parameters.yml@main
3232
with:
3333
library: nodejs
34-
scenarios_groups: essentials
34+
scenarios_groups: essentials,appsec_rasp
3535

3636
system-tests:
3737
runs-on: ${{ contains(fromJSON('["CROSSED_TRACING_LIBRARIES", "INTEGRATIONS"]'), matrix.scenario) && 'ubuntu-latest-16-cores' || 'ubuntu-latest' }}
3838
needs:
39-
- get-essential-scenarios
39+
- get-scenarios
4040
strategy:
4141
matrix:
42-
weblog-variant: ${{fromJson(needs.get-essential-scenarios.outputs.endtoend_weblogs)}}
43-
scenario: ${{fromJson(needs.get-essential-scenarios.outputs.endtoend_scenarios)}}
42+
weblog-variant: ${{fromJson(needs.get-scenarios.outputs.endtoend_weblogs)}}
43+
scenario: ${{fromJson(needs.get-scenarios.outputs.endtoend_scenarios)}}
4444

4545
env:
4646
TEST_LIBRARY: nodejs

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ typings/
106106

107107
# End of https://www.gitignore.io/api/node,macos,visualstudiocode
108108

109-
.github/notes
110109
.next
111110
package-lock.json
112111
out

LICENSE-3rdparty.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Component,Origin,License,Copyright
2+
require,@datadog/libdatadog,Apache license 2.0,Copyright 2024 Datadog Inc.
23
require,@datadog/native-appsec,Apache license 2.0,Copyright 2018 Datadog Inc.
34
require,@datadog/native-metrics,Apache license 2.0,Copyright 2018 Datadog Inc.
45
require,@datadog/native-iast-rewriter,Apache license 2.0,Copyright 2018 Datadog Inc.
@@ -7,6 +8,7 @@ require,@datadog/pprof,Apache license 2.0,Copyright 2019 Google Inc.
78
require,@datadog/sketches-js,Apache license 2.0,Copyright 2020 Datadog Inc.
89
require,@opentelemetry/api,Apache license 2.0,Copyright OpenTelemetry Authors
910
require,@opentelemetry/core,Apache license 2.0,Copyright OpenTelemetry Authors
11+
require,@isaacs/ttlcache,ISC,Copyright (c) 2022-2023 - Isaac Z. Schlueter and Contributors
1012
require,crypto-randomuuid,MIT,Copyright 2021 Node.js Foundation and contributors
1113
require,dc-polyfill,MIT,Copyright 2023 Datadog Inc.
1214
require,ignore,MIT,Copyright 2013 Kael Zhang and contributors

docs/test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ tracer.init({
115115
},
116116
apiSecurity: {
117117
enabled: true,
118-
requestSampling: 1.0
119118
},
120119
rasp: {
121120
enabled: true

index.d.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -662,19 +662,13 @@ declare namespace tracer {
662662
mode?: 'safe' | 'extended' | 'disabled'
663663
},
664664
/**
665-
* Configuration for Api Security sampling
665+
* Configuration for Api Security
666666
*/
667667
apiSecurity?: {
668668
/** Whether to enable Api Security.
669-
* @default false
669+
* @default true
670670
*/
671671
enabled?: boolean,
672-
673-
/** Controls the request sampling rate (between 0 and 1) in which Api Security is triggered.
674-
* The value will be coerced back if it's outside of the 0-1 range.
675-
* @default 0.1
676-
*/
677-
requestSampling?: number
678672
},
679673
/**
680674
* Configuration for RASP

integration-tests/standalone-asm.spec.js

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,33 +81,42 @@ describe('Standalone ASM', () => {
8181
})
8282
})
8383

84-
it('should keep second req because RateLimiter allows 1 req/min and discard the next', async () => {
85-
// 1st req kept because waf init
86-
// 2nd req kept because it's the first one hitting RateLimiter
87-
// next in the first minute are dropped
88-
await doWarmupRequests(proc)
89-
90-
return curlAndAssertMessage(agent, proc, ({ headers, payload }) => {
84+
it('should keep fifth req because RateLimiter allows 1 req/min', async () => {
85+
const promise = curlAndAssertMessage(agent, proc, ({ headers, payload }) => {
9186
assert.propertyVal(headers, 'datadog-client-computed-stats', 'yes')
9287
assert.isArray(payload)
93-
assert.strictEqual(payload.length, 4)
94-
95-
const secondReq = payload[1]
96-
assert.isArray(secondReq)
97-
assert.strictEqual(secondReq.length, 5)
88+
if (payload.length === 4) {
89+
assertKeep(payload[0][0])
90+
assertDrop(payload[1][0])
91+
assertDrop(payload[2][0])
92+
assertDrop(payload[3][0])
93+
94+
// req after a minute
95+
} else {
96+
const fifthReq = payload[0]
97+
assert.isArray(fifthReq)
98+
assert.strictEqual(fifthReq.length, 5)
99+
100+
const { meta, metrics } = fifthReq[0]
101+
assert.notProperty(meta, 'manual.keep')
102+
assert.notProperty(meta, '_dd.p.appsec')
103+
104+
assert.propertyVal(metrics, '_sampling_priority_v1', AUTO_KEEP)
105+
assert.propertyVal(metrics, '_dd.apm.enabled', 0)
106+
}
107+
}, 70000, 2)
98108

99-
const { meta, metrics } = secondReq[0]
100-
assert.notProperty(meta, 'manual.keep')
101-
assert.notProperty(meta, '_dd.p.appsec')
109+
// 1st req kept because waf init
110+
// next in the first minute are dropped
111+
// 5nd req kept because RateLimiter allows 1 req/min
112+
await doWarmupRequests(proc)
102113

103-
assert.propertyVal(metrics, '_sampling_priority_v1', AUTO_KEEP)
104-
assert.propertyVal(metrics, '_dd.apm.enabled', 0)
114+
await new Promise(resolve => setTimeout(resolve, 60000))
105115

106-
assertDrop(payload[2][0])
116+
await curl(proc)
107117

108-
assertDrop(payload[3][0])
109-
})
110-
})
118+
return promise
119+
}).timeout(70000)
111120

112121
it('should keep attack requests', async () => {
113122
await doWarmupRequests(proc)

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"type:test": "cd docs && yarn && yarn test",
1616
"lint": "node scripts/check_licenses.js && eslint . && yarn audit",
1717
"lint-fix": "node scripts/check_licenses.js && eslint . --fix && yarn audit",
18+
"release:proposal": "node scripts/release/proposal",
1819
"services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
1920
"test": "SERVICES=* yarn services && mocha --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
2021
"test:appsec": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" \"packages/dd-trace/test/appsec/**/*.spec.js\"",
@@ -81,12 +82,14 @@
8182
"node": ">=18"
8283
},
8384
"dependencies": {
84-
"@datadog/native-appsec": "8.2.1",
85+
"@datadog/libdatadog": "^0.2.2",
86+
"@datadog/native-appsec": "8.3.0",
8587
"@datadog/native-iast-rewriter": "2.5.0",
8688
"@datadog/native-iast-taint-tracking": "3.2.0",
8789
"@datadog/native-metrics": "^3.0.1",
8890
"@datadog/pprof": "5.4.1",
8991
"@datadog/sketches-js": "^2.1.0",
92+
"@isaacs/ttlcache": "^1.4.1",
9093
"@opentelemetry/api": ">=1.0.0 <1.9.0",
9194
"@opentelemetry/core": "^1.14.0",
9295
"crypto-randomuuid": "^1.0.0",

packages/datadog-core/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
const { AsyncLocalStorage } = require('async_hooks')
4-
5-
const storage = new AsyncLocalStorage()
3+
const storage = require('./src/storage')
64

75
module.exports = { storage }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict'
2+
3+
const { AsyncLocalStorage } = require('async_hooks')
4+
5+
const storages = Object.create(null)
6+
const legacyStorage = new AsyncLocalStorage()
7+
8+
const storage = function (namespace) {
9+
if (!storages[namespace]) {
10+
storages[namespace] = new AsyncLocalStorage()
11+
}
12+
return storages[namespace]
13+
}
14+
15+
storage.disable = legacyStorage.disable.bind(legacyStorage)
16+
storage.enterWith = legacyStorage.enterWith.bind(legacyStorage)
17+
storage.exit = legacyStorage.exit.bind(legacyStorage)
18+
storage.getStore = legacyStorage.getStore.bind(legacyStorage)
19+
storage.run = legacyStorage.run.bind(legacyStorage)
20+
21+
module.exports = storage

0 commit comments

Comments
 (0)