Skip to content

Commit 444ad14

Browse files
authored
Disable APM tracing (standalone billing) (#5198)
* move standalone products, tracesource, prioritySampler, etc * fixes and tests * publish 'datadog:tracer:configure' * rename config prop as apmTracingEnabled * appsec standalone module * fix integration tests * clean up * simplify rateLimiter configuration * support 32 bit tracesource masks * clean up * remove b-3x headers and clear traceparent * delete traceparent header and tests * product getProductRateLimiter tests * increase coverage * test.ts * SpanStatsProcessor should disable stats only if apmTracingEnabled is false * calculate stats.enabled in config.js * show deprecated appsec.standalone.enabled * fix merge * fix again :S * Change property comment * keep appsec.standalone.enabled * lint * lint * lint
1 parent 522aa56 commit 444ad14

37 files changed

+665
-494
lines changed

docs/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ let promise: Promise<void>;
3939

4040
ddTrace.init();
4141
tracer.init({
42+
apmTracingEnabled: false,
4243
logInjection: true,
4344
startupLogs: false,
4445
env: 'test',

index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,12 @@ declare namespace tracer {
345345
* List of options available to the tracer.
346346
*/
347347
export interface TracerOptions {
348+
/**
349+
* Used to disable APM Tracing when using standalone products
350+
* @default true
351+
*/
352+
apmTracingEnabled?: boolean
353+
348354
/**
349355
* Whether to enable trace ID injection in log records to be able to correlate
350356
* traces with logs.
@@ -528,6 +534,9 @@ declare namespace tracer {
528534
appsec?: {
529535
/**
530536
* Configuration of Standalone ASM mode
537+
* Deprecated in favor of `apmTracingEnabled`.
538+
*
539+
* @deprecated
531540
*/
532541
standalone?: {
533542
/**

integration-tests/standalone-asm.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('Standalone ASM', () => {
4747
function assertKeep (payload) {
4848
const { meta, metrics } = payload
4949

50-
assert.propertyVal(meta, '_dd.p.appsec', '1')
50+
assert.propertyVal(meta, '_dd.p.ts', '02')
5151

5252
assert.propertyVal(metrics, '_sampling_priority_v1', USER_KEEP)
5353
assert.propertyVal(metrics, '_dd.apm.enabled', 0)
@@ -57,7 +57,7 @@ describe('Standalone ASM', () => {
5757
const { metrics } = payload
5858
assert.propertyVal(metrics, '_sampling_priority_v1', AUTO_REJECT)
5959
assert.propertyVal(metrics, '_dd.apm.enabled', 0)
60-
assert.notProperty(metrics, '_dd.p.appsec')
60+
assert.notProperty(metrics, '_dd.p.ts')
6161
}
6262

6363
async function doWarmupRequests (procOrUrl, number = 3) {
@@ -99,7 +99,7 @@ describe('Standalone ASM', () => {
9999

100100
const { meta, metrics } = fifthReq[0]
101101
assert.notProperty(meta, 'manual.keep')
102-
assert.notProperty(meta, '_dd.p.appsec')
102+
assert.notProperty(meta, '_dd.p.ts')
103103

104104
assert.propertyVal(metrics, '_sampling_priority_v1', AUTO_KEEP)
105105
assert.propertyVal(metrics, '_dd.apm.enabled', 0)
@@ -207,7 +207,7 @@ describe('Standalone ASM', () => {
207207
})
208208

209209
// proc/propagation-with-event triggers an appsec event and calls downstream proc2/down with no event
210-
it('should keep if parent trace is (prio:2, _dd.p.appsec:1) but there is no event in the local trace',
210+
it('should keep if parent trace is (prio:2, _dd.p.ts:02) but there is no event in the local trace',
211211
async () => {
212212
await doWarmupRequests(proc)
213213
await doWarmupRequests(proc2)
@@ -284,7 +284,7 @@ describe('Standalone ASM', () => {
284284
const { meta, metrics } = payload[0][0]
285285
assert.property(meta, '_dd.iast.json') // WEAK_HASH and XCONTENTTYPE_HEADER_MISSING reported
286286

287-
assert.notProperty(meta, '_dd.p.appsec')
287+
assert.notProperty(meta, '_dd.p.ts')
288288
assert.notProperty(metrics, '_dd.apm.enabled')
289289
})
290290
})
@@ -304,7 +304,7 @@ describe('Standalone ASM', () => {
304304
const { meta, metrics } = payload[0][0]
305305
assert.property(meta, '_dd.appsec.json') // crs-942-100 triggered
306306

307-
assert.notProperty(meta, '_dd.p.appsec')
307+
assert.notProperty(meta, '_dd.p.ts')
308308
assert.notProperty(metrics, '_dd.apm.enabled')
309309
})
310310
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"test:appsec:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" -- npm run test:appsec:plugins",
2525
"test:debugger": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/dd-trace/test/debugger/**/*.spec.js'",
2626
"test:debugger:ci": "nyc --no-clean --include 'packages/dd-trace/src/debugger/**/*.js' -- npm run test:debugger",
27-
"test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,datastreams,encode,exporters,opentelemetry,opentracing,plugins,service-naming,telemetry}/**/*.spec.js\"",
27+
"test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,datastreams,encode,exporters,opentelemetry,opentracing,plugins,service-naming,standalone,telemetry}/**/*.spec.js\"",
2828
"test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/**/*.js\"",
2929
"test:instrumentations": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
3030
"test:instrumentations:ci": "nyc --no-clean --include 'packages/datadog-instrumentations/src/**/*.js' -- npm run test:instrumentations",

packages/dd-trace/src/appsec/iast/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const securityControls = require('./security-controls')
2222
const requestStart = dc.channel('dd-trace:incomingHttpRequestStart')
2323
const requestClose = dc.channel('dd-trace:incomingHttpRequestEnd')
2424
const iastResponseEnd = dc.channel('datadog:iast:response-end')
25-
2625
let isEnabled = false
2726

2827
function enable (config, _tracer) {

packages/dd-trace/src/appsec/iast/vulnerability-reporter.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
const LRU = require('lru-cache')
44
const vulnerabilitiesFormatter = require('./vulnerabilities-formatter')
55
const { IAST_ENABLED_TAG_KEY, IAST_JSON_TAG_KEY } = require('./tags')
6-
const standalone = require('../standalone')
7-
const { SAMPLING_MECHANISM_APPSEC } = require('../../constants')
86
const { keepTrace } = require('../../priority_sampler')
97
const { reportStackTrace, getCallsiteFrames, canReportStackTrace, STACK_TRACE_NAMESPACES } = require('../stack_trace')
108
const { getOriginalPathAndLineFromSourceMap } = require('./taint-tracking/rewriter')
9+
const { ASM } = require('../../standalone/product')
1110

1211
const VULNERABILITIES_KEY = 'vulnerabilities'
1312
const VULNERABILITY_HASHES_MAX_SIZE = 1000
@@ -51,8 +50,7 @@ function addVulnerability (iastContext, vulnerability, callSiteFrames) {
5150

5251
if (!span) return
5352

54-
keepTrace(span, SAMPLING_MECHANISM_APPSEC)
55-
standalone.sample(span)
53+
keepTrace(span, ASM)
5654

5755
if (stackTraceEnabled && canReportStackTrace(span, maxStackTraces, STACK_TRACE_NAMESPACES.IAST)) {
5856
const originalCallSiteList = callSiteFrames.map(callsite => replaceCallSiteFromSourceMap(callsite))

packages/dd-trace/src/appsec/reporter.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ const {
1313
getRequestMetrics
1414
} = require('./telemetry')
1515
const zlib = require('zlib')
16-
const standalone = require('./standalone')
17-
const { SAMPLING_MECHANISM_APPSEC } = require('../constants')
1816
const { keepTrace } = require('../priority_sampler')
17+
const { ASM } = require('../standalone/product')
1918

2019
// default limiter, configurable with setRateLimit()
2120
let limiter = new Limiter(100)
@@ -129,9 +128,7 @@ function reportAttack (attackData) {
129128
}
130129

131130
if (limiter.isAllowed()) {
132-
keepTrace(rootSpan, SAMPLING_MECHANISM_APPSEC)
133-
134-
standalone.sample(rootSpan)
131+
keepTrace(rootSpan, ASM)
135132
}
136133

137134
// TODO: maybe add this to format.js later (to take decision as late as possible)
@@ -186,9 +183,7 @@ function finishRequest (req, res) {
186183
if (metricsQueue.size) {
187184
rootSpan.addTags(Object.fromEntries(metricsQueue))
188185

189-
keepTrace(rootSpan, SAMPLING_MECHANISM_APPSEC)
190-
191-
standalone.sample(rootSpan)
186+
keepTrace(rootSpan, ASM)
192187

193188
metricsQueue.clear()
194189
}

packages/dd-trace/src/appsec/sdk/track_event.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
const log = require('../../log')
44
const { getRootSpan } = require('./utils')
55
const { setUserTags } = require('./set_user')
6-
const standalone = require('../standalone')
76
const waf = require('../waf')
8-
const { SAMPLING_MECHANISM_APPSEC } = require('../../constants')
97
const { keepTrace } = require('../../priority_sampler')
108
const addresses = require('../addresses')
9+
const { ASM } = require('../../standalone/product')
1110

1211
function trackUserLoginSuccessEvent (tracer, user, metadata) {
1312
// TODO: better user check here and in _setUser() ?
@@ -79,8 +78,7 @@ function trackEvent (eventName, fields, sdkMethodName, rootSpan) {
7978

8079
rootSpan.addTags(tags)
8180

82-
keepTrace(rootSpan, SAMPLING_MECHANISM_APPSEC)
83-
standalone.sample(rootSpan)
81+
keepTrace(rootSpan, ASM)
8482
}
8583

8684
function runWaf (eventName, user) {

packages/dd-trace/src/appsec/standalone.js

Lines changed: 0 additions & 130 deletions
This file was deleted.

packages/dd-trace/src/appsec/user_tracking.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ const log = require('../log')
55
const telemetry = require('./telemetry')
66
const addresses = require('./addresses')
77
const { keepTrace } = require('../priority_sampler')
8-
const { SAMPLING_MECHANISM_APPSEC } = require('../constants')
9-
const standalone = require('./standalone')
108
const waf = require('./waf')
9+
const { ASM } = require('../standalone/product')
1110

1211
// the RFC doesn't include '_id', but it's common in MongoDB
1312
const USER_ID_FIELDS = ['id', '_id', 'email', 'username', 'login', 'user']
@@ -151,8 +150,7 @@ function trackLogin (framework, login, user, success, rootSpan) {
151150
persistent[addresses.LOGIN_FAILURE] = null
152151
}
153152

154-
keepTrace(rootSpan, SAMPLING_MECHANISM_APPSEC)
155-
standalone.sample(rootSpan)
153+
keepTrace(rootSpan, ASM)
156154

157155
rootSpan.addTags(newTags)
158156

0 commit comments

Comments
 (0)