Skip to content

Commit 3491e54

Browse files
authored
1 parent 98f101f commit 3491e54

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/statsbeat/StatsbeatModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public StatsbeatModule() {
4747
}
4848

4949
public void start(TelemetryClient telemetryClient, Configuration config) {
50+
if (telemetryClient.getStatsbeatConnectionString() == null) {
51+
logger.debug("Don't start StatsbeatModule when statsbeat connection string is null.");
52+
return;
53+
}
54+
5055
if (started.getAndSet(true)) {
5156
throw new IllegalStateException("initialize already called");
5257
}

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/telemetry/TelemetryClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ public void updateConnectionStrings(
411411
this.statsbeatConnectionString =
412412
StatsbeatConnectionString.create(
413413
this.connectionString, statsbeatInstrumentationKey, statsbeatEndpoint);
414+
if (this.statsbeatConnectionString == null) {
415+
statsbeatModule.shutdown();
416+
}
414417
}
415418
}
416419

@@ -515,6 +518,9 @@ public Builder setConnectionStrings(
515518
this.statsbeatConnectionString =
516519
StatsbeatConnectionString.create(
517520
this.connectionString, statsbeatInstrumentationKey, statsbeatEndpoint);
521+
if (this.statsbeatConnectionString == null) {
522+
statsbeatModule.shutdown();
523+
}
518524
}
519525
return this;
520526
}

agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/configuration/StatsbeatConnectionString.java

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public final class StatsbeatConnectionString {
2626

2727
private static final Pattern pattern = Pattern.compile("^https?://(?:www\\.)?([^/.-]+)");
2828

29-
private static final Set<String> EU_REGION_GEO_SET = new HashSet<>(10);
29+
private static final Set<String> EU_REGION_GEO_SET = new HashSet<>(12);
30+
private static final Set<String> NON_EU_REGION_GEO_SET = new HashSet<>(33);
3031

3132
static {
3233
EU_REGION_GEO_SET.add("westeurope");
@@ -39,23 +40,64 @@ public final class StatsbeatConnectionString {
3940
EU_REGION_GEO_SET.add("swedencentral");
4041
EU_REGION_GEO_SET.add("switzerlandnorth");
4142
EU_REGION_GEO_SET.add("switzerlandwest");
43+
EU_REGION_GEO_SET.add("uksouth");
44+
EU_REGION_GEO_SET.add("ukwest");
45+
46+
NON_EU_REGION_GEO_SET.add("eastasia");
47+
NON_EU_REGION_GEO_SET.add("southeastasia");
48+
NON_EU_REGION_GEO_SET.add("chinaeast2");
49+
NON_EU_REGION_GEO_SET.add("chinaeast3");
50+
NON_EU_REGION_GEO_SET.add("chinanorth3");
51+
NON_EU_REGION_GEO_SET.add("centralindia");
52+
NON_EU_REGION_GEO_SET.add("southindia");
53+
NON_EU_REGION_GEO_SET.add("jioindiacentral");
54+
NON_EU_REGION_GEO_SET.add("jioindiawest");
55+
NON_EU_REGION_GEO_SET.add("japaneast");
56+
NON_EU_REGION_GEO_SET.add("japanwest");
57+
NON_EU_REGION_GEO_SET.add("koreacentral");
58+
NON_EU_REGION_GEO_SET.add("koreasouth");
59+
NON_EU_REGION_GEO_SET.add("australiacentral");
60+
NON_EU_REGION_GEO_SET.add("australiacentral2");
61+
NON_EU_REGION_GEO_SET.add("australiaeast");
62+
NON_EU_REGION_GEO_SET.add("australiasoutheast");
63+
NON_EU_REGION_GEO_SET.add("canadacentral");
64+
NON_EU_REGION_GEO_SET.add("canadaeast");
65+
NON_EU_REGION_GEO_SET.add("qatarcentral");
66+
NON_EU_REGION_GEO_SET.add("uaecentral");
67+
NON_EU_REGION_GEO_SET.add("uaenorth");
68+
NON_EU_REGION_GEO_SET.add("southafricanorth");
69+
NON_EU_REGION_GEO_SET.add("brazilsouth");
70+
NON_EU_REGION_GEO_SET.add("brazilsoutheast");
71+
NON_EU_REGION_GEO_SET.add("centralus");
72+
NON_EU_REGION_GEO_SET.add("eastus");
73+
NON_EU_REGION_GEO_SET.add("eastus2");
74+
NON_EU_REGION_GEO_SET.add("northcentralus");
75+
NON_EU_REGION_GEO_SET.add("southcentralus");
76+
NON_EU_REGION_GEO_SET.add("westus");
77+
NON_EU_REGION_GEO_SET.add("westus2");
78+
NON_EU_REGION_GEO_SET.add("westus3");
4279
}
4380

4481
private final String ingestionEndpoint;
4582
private final String instrumentationKey;
4683

84+
@Nullable
4785
public static StatsbeatConnectionString create(
4886
ConnectionString connectionString,
4987
@Nullable String instrumentationKey,
5088
@Nullable String ingestionEndpoint) {
5189

52-
// if customer is in EU region and their statsbeat config is not in EU region, customer is
53-
// responsible for breaking the EU data boundary violation.
54-
// Statsbeat config setting has the highest precedence.
5590
if (instrumentationKey == null || instrumentationKey.isEmpty()) {
5691
InstrumentationKeyEndpointPair pair =
5792
StatsbeatConnectionString.getInstrumentationKeyAndEndpointPair(
5893
connectionString.getIngestionEndpoint());
94+
95+
// Statsbeat will not get collected when customer's stamp specific region is not found in our
96+
// known non-EU and EU lists
97+
if (pair == null) {
98+
return null;
99+
}
100+
59101
instrumentationKey = pair.instrumentationKey;
60102
ingestionEndpoint = pair.endpoint;
61103
}
@@ -87,16 +129,19 @@ public String getInstrumentationKey() {
87129
}
88130

89131
// visible for testing
132+
@Nullable
90133
static InstrumentationKeyEndpointPair getInstrumentationKeyAndEndpointPair(
91134
String customerEndpoint) {
92135
String geo = getGeoWithoutStampSpecific(customerEndpoint);
93136
if (geo != null && EU_REGION_GEO_SET.contains(geo.toLowerCase(Locale.ROOT))) {
94137
return new InstrumentationKeyEndpointPair(
95138
EU_REGION_STATSBEAT_IKEY, EU_REGION_STATSBEAT_ENDPOINT);
139+
} else if (geo != null && NON_EU_REGION_GEO_SET.contains(geo.toLowerCase(Locale.ROOT))) {
140+
return new InstrumentationKeyEndpointPair(
141+
NON_EU_REGION_STATSBEAT_IKEY, NON_EU_REGION_STATSBEAT_ENDPOINT);
96142
}
97143

98-
return new InstrumentationKeyEndpointPair(
99-
NON_EU_REGION_STATSBEAT_IKEY, NON_EU_REGION_STATSBEAT_ENDPOINT);
144+
return null;
100145
}
101146

102147
// visible for testing

0 commit comments

Comments
 (0)