Skip to content

Commit a9a244c

Browse files
authored
change == to .equals (#24)
* change == to .equals * Add tests for this env var
1 parent b6f5959 commit a9a244c

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ dependencies {
3535
testImplementation 'junit:junit:4.12'
3636
testImplementation 'org.apache.logging.log4j:log4j-api:2.13.3'
3737
testImplementation 'org.apache.logging.log4j:log4j-core:2.13.3'
38+
testImplementation 'com.github.stefanbirkner:system-rules:1.19.0'
3839
}
3940

4041
sourceCompatibility = 1.8

src/main/java/com/datadoghq/datadog_lambda_java/DDLambda.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ public DDLambda(Headerable req, Context cxt){
9090
MDC.put(MDC_TRACE_CONTEXT_FIELD, getTraceContextString());
9191
}
9292

93-
private boolean checkEnhanced(){
93+
protected boolean checkEnhanced(){
9494
String sysEnhanced = System.getenv(ENHANCED_ENV);
9595
if (sysEnhanced == null){
9696
return true;
9797
}
9898

99-
if (sysEnhanced.toLowerCase() == "false"){
99+
if (sysEnhanced.toLowerCase().equals("false")){
100100
return false;
101101
}
102102
return true;

src/main/java/com/datadoghq/datadog_lambda_java/Tracing.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public String toJSONString(){
191191
}
192192

193193
public boolean sendToXRay(){
194-
if (this.id == null || this.id == "") {
194+
if (this.id == null || this.id.equals("")) {
195195
return false;
196196
}
197197

@@ -353,7 +353,7 @@ class XRayTraceContext{
353353
public XRayTraceContext(){
354354
//Root=1-5e41a79d-e6a0db584029dba86a594b7e;Parent=8c34f5ad8f92d510;Sampled=1
355355
String traceId = System.getenv("_X_AMZN_TRACE_ID");
356-
if (traceId == null || traceId == ""){
356+
if (traceId == null || traceId.equals("")){
357357
DDLogger.getLoggerImpl().debug("Unable to find _X_AMZN_TRACE_ID");
358358
return;
359359
}

src/test/java/com/datadoghq/datadog_lambda_java/LambdaInstrumenterTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
import org.junit.Assert;
99
import org.junit.Before;
1010
import org.junit.Test;
11+
import org.junit.Rule;
12+
import org.junit.contrib.java.lang.system.EnvironmentVariables;
1113

1214

1315
public class LambdaInstrumenterTest {
16+
@Rule
17+
public final EnvironmentVariables environmentVariables = new EnvironmentVariables();
18+
1419
@Before
1520
public void setUp() throws Exception {
1621
ColdStart.resetColdStart();
@@ -109,6 +114,35 @@ public void setUp() throws Exception {
109114
Assert.assertTrue(pcm.tags.contains("cold_start:true"));
110115
}
111116

117+
@Test
118+
public void EnhancedMetricsDeactivatedWithEnvVar(){
119+
environmentVariables.set("DD_ENHANCED_METRICS", "false");
120+
Context mc1 = new EnhancedMetricTest.MockContext();
121+
DDLambda ddl = new DDLambda(mc1);
122+
boolean isEnhanced = ddl.checkEnhanced();
123+
Assert.assertFalse(isEnhanced);
124+
environmentVariables.clear("DD_ENHANCED_METRICS");
125+
}
126+
127+
@Test
128+
public void EnhancedMetricsActivatedByDefault(){
129+
System.out.println(System.getenv("DD_ENHANCED_METRICS"));
130+
Context mc1 = new EnhancedMetricTest.MockContext();
131+
DDLambda ddl = new DDLambda(mc1);
132+
boolean isEnhanced = ddl.checkEnhanced();
133+
Assert.assertTrue(isEnhanced);
134+
}
135+
136+
@Test
137+
public void EnhancedMetricsActivatedWithEnvVar(){
138+
environmentVariables.set("DD_ENHANCED_METRICS", "true");
139+
Context mc1 = new EnhancedMetricTest.MockContext();
140+
DDLambda ddl = new DDLambda(mc1);
141+
boolean isEnhanced = ddl.checkEnhanced();
142+
Assert.assertTrue(isEnhanced);
143+
environmentVariables.clear("DD_ENHANCED_METRICS");
144+
}
145+
112146
@After
113147
public void tearDown() throws Exception {
114148
ColdStart.resetColdStart();

0 commit comments

Comments
 (0)