Skip to content

Commit

Permalink
add manual.keep if sampling request on incomingHttpEndTranslator
Browse files Browse the repository at this point in the history
  • Loading branch information
iunanua committed Apr 29, 2024
1 parent 6eab4dc commit 6ac9ce5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/dd-trace/src/appsec/api_security_sampler.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function sampleRequest (req, res) {
return shouldSample
}

// rfc mentions using a hash
function getKey (req = {}, res = {}) {
return `${req.method}-${req.url}-${res.statusCode}`
}
Expand Down
4 changes: 3 additions & 1 deletion packages/dd-trace/src/appsec/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ function incomingHttpEndTranslator ({ req, res }) {

if (apiSecuritySampler.sampleRequest(req, res)) {
persistent[addresses.WAF_CONTEXT_PROCESSOR] = EXTRACT_SCHEMA

const rootSpan = web.root(req)
rootSpan?.setTag(MANUAL_KEEP, 'true')
}

waf.run({ persistent }, req)
Expand Down Expand Up @@ -198,7 +201,6 @@ function onRequestCookieParser ({ req, res, abortController, cookies }) {
handleResults(results, req, res, rootSpan, abortController)
}

// can we assume res.statusCode is fixed here?
function onResponseBody ({ req, res, body }) {
if (!body || typeof body !== 'object') return

Expand Down
3 changes: 2 additions & 1 deletion packages/dd-trace/test/appsec/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ describe('AppSec Index', () => {
sinon.stub(waf, 'run')

const rootSpan = {
addTags: sinon.stub()
addTags: sinon.stub(),
setTag: sinon.stub()
}

web.root.returns(rootSpan)
Expand Down

0 comments on commit 6ac9ce5

Please sign in to comment.