Skip to content

Commit 0111818

Browse files
authored
fix standalone v2 for sca (#8400)
Fix the Sampler to enable ASMStandaloneSampler also when SCA is enabled
1 parent 646553c commit 0111818

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

dd-trace-core/src/main/java/datadog/trace/common/sampling/Sampler.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ final class Builder {
3636
public static Sampler forConfig(final Config config, final TraceConfig traceConfig) {
3737
Sampler sampler;
3838
if (config != null) {
39-
if (!config.isApmTracingEnabled()
40-
&& (config.getAppSecActivation() == ProductActivation.FULLY_ENABLED
41-
|| config.getIastActivation() == ProductActivation.FULLY_ENABLED)) {
39+
if (!config.isApmTracingEnabled() && isAsmEnabled(config)) {
4240
log.debug("APM is disabled. Only 1 trace per minute will be sent.");
4341
return new AsmStandaloneSampler(Clock.systemUTC());
4442
}
@@ -103,6 +101,12 @@ public static Sampler forConfig(final Config config, final TraceConfig traceConf
103101
return sampler;
104102
}
105103

104+
private static boolean isAsmEnabled(Config config) {
105+
return config.getAppSecActivation() == ProductActivation.FULLY_ENABLED
106+
|| config.getIastActivation() == ProductActivation.FULLY_ENABLED
107+
|| config.isAppSecScaEnabled();
108+
}
109+
106110
public static Sampler forConfig(final Properties config) {
107111
return forConfig(Config.get(config), null);
108112
}

dd-trace-core/src/test/groovy/datadog/trace/common/sampling/SamplerTest.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ class SamplerTest extends DDSpecification{
3131
sampler instanceof AsmStandaloneSampler
3232
}
3333

34+
void "test that AsmStandaloneSampler is selected when apm tracing disabled and sca enabled is enabled"() {
35+
setup:
36+
System.setProperty("dd.apm.tracing.enabled", "false")
37+
System.setProperty("dd.appsec.sca.enabled", "true")
38+
Config config = new Config()
39+
40+
when:
41+
Sampler sampler = Sampler.Builder.forConfig(config, null)
42+
43+
then:
44+
sampler instanceof AsmStandaloneSampler
45+
}
46+
3447
void "test that AsmStandaloneSampler is not selected when apm tracing and asm not enabled"() {
3548
setup:
3649
System.setProperty("dd.apm.tracing.enabled", "false")

internal-api/src/main/java/datadog/trace/api/Config.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3981,8 +3981,8 @@ public String getAgentlessLogSubmissionProduct() {
39813981
return agentlessLogSubmissionProduct;
39823982
}
39833983

3984-
public Boolean getAppSecScaEnabled() {
3985-
return appSecScaEnabled;
3984+
public boolean isAppSecScaEnabled() {
3985+
return appSecScaEnabled != null && appSecScaEnabled;
39863986
}
39873987

39883988
public boolean isAppSecRaspEnabled() {

0 commit comments

Comments
 (0)