Skip to content

Commit 0b3f9ce

Browse files
authored
Fix an NullPointerException in Linux Consumption Plan (#1732)
* Don't send statsbeat when cikey is empty or null * Use a diff Strings * Remove negation!
1 parent 4ea3e7a commit 0b3f9ce

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

core/src/main/java/com/microsoft/applicationinsights/internal/statsbeat/BaseStatsbeat.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121

2222
package com.microsoft.applicationinsights.internal.statsbeat;
2323

24-
import com.google.common.annotations.VisibleForTesting;
24+
import com.google.common.base.Strings;
2525
import com.microsoft.applicationinsights.TelemetryClient;
2626
import com.microsoft.applicationinsights.TelemetryConfiguration;
2727
import com.microsoft.applicationinsights.internal.util.ThreadPoolUtils;
2828
import com.microsoft.applicationinsights.telemetry.MetricTelemetry;
29+
2930
import org.slf4j.Logger;
3031
import org.slf4j.LoggerFactory;
3132

@@ -64,6 +65,11 @@ private class StatsbeatSender implements Runnable {
6465
@Override
6566
public void run() {
6667
try {
68+
// For Linux Consumption Plan, connection string is lazily set.
69+
// There is no need to send statsbeat when cikey is empty.
70+
if (Strings.isNullOrEmpty(CustomDimensions.get().getCustomerIkey())) {
71+
return;
72+
}
6773
send();
6874
}
6975
catch (Exception e) {

core/src/main/java/com/microsoft/applicationinsights/internal/statsbeat/CustomDimensions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public OperatingSystem getOperatingSystem() {
8787
return operatingSystem;
8888
}
8989

90+
public String getCustomerIkey() { return customerIkey; }
91+
9092
public void setResourceProvider(ResourceProvider resourceProvider) {
9193
this.resourceProvider = resourceProvider;
9294
}

0 commit comments

Comments
 (0)