Skip to content

Commit 5b773b6

Browse files
authored
Enable ETW in integrated_auto only (#3560)
1 parent 6fac4d7 commit 5b773b6

File tree

8 files changed

+29
-22
lines changed

8 files changed

+29
-22
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CHANGELOG
22

3-
## Version 3.5 GA (02/26/2024)
3+
## Version 3.5 GA (02/28/2024)
44

55
### Enhancements:
66

@@ -13,6 +13,7 @@
1313

1414
### Bug fixes:
1515

16+
* Fix ETW log for non-auto attach ([#3560](https://github.com/microsoft/ApplicationInsights-Java/pull/3560))
1617
* Fix duplicate exceptions ([#3555](https://github.com/microsoft/ApplicationInsights-Java/pull/3555))
1718

1819
## Version 3.4.19 GA (12/20/2023)

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,8 @@ private static String getDefaultPath() {
629629
}
630630
return DEFAULT_NAME; // this will be relative to the directory where agent jar is located
631631
}
632-
if (DiagnosticsHelper.isAppSvcRpIntegration()
633-
|| DiagnosticsHelper.isFunctionsRpIntegration()) {
632+
if (DiagnosticsHelper.isAppSvcRpIntegratedAuto()
633+
|| DiagnosticsHelper.isFunctionsRpIntegratedAuto()) {
634634
return StatusFile.getLogDir() + File.separator + DEFAULT_NAME;
635635
}
636636
// azure spring cloud

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,9 @@ static Configuration getConfigurationFromEnvVar(String json) {
978978

979979
Configuration configuration = getConfiguration(json, JsonOrigin.ENV_VAR);
980980

981-
// restrict connection string in APPLICATIONINSIGHTS_CONFIGURATION_CONTENT for App Service only
982-
if (configuration.connectionString != null && DiagnosticsHelper.isAppSvcRpIntegration()) {
981+
// restrict connection string in APPLICATIONINSIGHTS_CONFIGURATION_CONTENT for App Service
982+
// INTEGRATED_AUTO only
983+
if (configuration.connectionString != null && DiagnosticsHelper.isAppSvcRpIntegratedAuto()) {
983984
throw new ConfigurationException(
984985
"\"connectionString\" attribute is not supported inside of "
985986
+ APPLICATIONINSIGHTS_CONFIGURATION_CONTENT

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/diagnostics/DiagnosticsHelper.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public class DiagnosticsHelper {
1313
private DiagnosticsHelper() {}
1414

1515
// visible for testing
16-
private static volatile boolean appSvcRpIntegration;
17-
private static volatile boolean functionsRpIntegration;
16+
private static volatile boolean appSvcRpIntegratedAuto;
17+
private static volatile boolean functionsRpIntegratedAuto;
1818

1919
private static final boolean isWindows;
2020

@@ -37,12 +37,16 @@ public static void initRpIntegration(Path agentPath) {
3737
// TODO (heya) refactor PropertyHelper and ResourceProvider to simplify logic for rp
3838
if ("java".equals(System.getenv("FUNCTIONS_WORKER_RUNTIME"))) {
3939
PropertyHelper.setRpIntegrationChar('f');
40-
functionsRpIntegration = true;
4140
setRpAttachType(agentPath, "functions.codeless");
41+
if (RpAttachType.INTEGRATED_AUTO.equals(RpAttachType.getRpAttachType())) {
42+
functionsRpIntegratedAuto = true;
43+
}
4244
} else if (!Strings.isNullOrEmpty(System.getenv("WEBSITE_SITE_NAME"))) {
4345
PropertyHelper.setRpIntegrationChar('a');
44-
appSvcRpIntegration = true;
4546
setRpAttachType(agentPath, "appsvc.codeless");
47+
if (RpAttachType.INTEGRATED_AUTO.equals(RpAttachType.getRpAttachType())) {
48+
appSvcRpIntegratedAuto = true;
49+
}
4650
} else if (!Strings.isNullOrEmpty(System.getenv("AKS_ARM_NAMESPACE_ID"))) {
4751
// AKS_ARM_NAMESPACE_ID is an env var available in AKS only and it's also used as the AKS
4852
// attach rate numerator
@@ -57,12 +61,12 @@ public static void initRpIntegration(Path agentPath) {
5761
}
5862
}
5963

60-
public static boolean isAppSvcRpIntegration() {
61-
return appSvcRpIntegration;
64+
public static boolean isAppSvcRpIntegratedAuto() {
65+
return appSvcRpIntegratedAuto;
6266
}
6367

64-
public static boolean isFunctionsRpIntegration() {
65-
return functionsRpIntegration;
68+
public static boolean isFunctionsRpIntegratedAuto() {
69+
return functionsRpIntegratedAuto;
6670
}
6771

6872
public static ApplicationMetadataFactory getMetadataFactory() {
@@ -82,7 +86,7 @@ private static void setRpAttachType(Path agentPath, String markerFile) {
8286
}
8387

8488
// only used by tests
85-
public static void setAppSvcRpIntegration(boolean appSvcRpIntegration) {
86-
DiagnosticsHelper.appSvcRpIntegration = appSvcRpIntegration;
89+
public static void setAppSvcRpIntegratedAuto(boolean appSvcRpIntegratedAuto) {
90+
DiagnosticsHelper.appSvcRpIntegratedAuto = appSvcRpIntegratedAuto;
8791
}
8892
}

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/diagnostics/status/StatusFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public void run() {
230230
justification =
231231
"The constructed file path cannot be controlled by an end user of the instrumented application)")
232232
private static boolean writable() {
233-
if (!DiagnosticsHelper.isAppSvcRpIntegration()) {
233+
if (!DiagnosticsHelper.isAppSvcRpIntegratedAuto()) {
234234
return false;
235235
}
236236
return new File(logDir).canWrite();

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/LoggingConfigurator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ public class LoggingConfigurator {
5757
void configure() {
5858
loggerContext.getLogger(ROOT_LOGGER_NAME).detachAndStopAllAppenders();
5959

60-
if (DiagnosticsHelper.isAppSvcRpIntegration()) {
60+
// only enable ETW when it's INTEGRATED_AUTO
61+
if (DiagnosticsHelper.isAppSvcRpIntegratedAuto()) {
6162
configureAppSvc();
62-
} else if (DiagnosticsHelper.isFunctionsRpIntegration()) {
63+
} else if (DiagnosticsHelper.isFunctionsRpIntegratedAuto()) {
6364
configureFunctions();
6465
} else if (destination == null || destination.equalsIgnoreCase("file+console")) {
6566
configureFileAndConsole();
@@ -203,7 +204,7 @@ private Appender<ILoggingEvent> configureConsoleAppender() {
203204
appender.setName("CONSOLE");
204205

205206
// format Functions diagnostic log as comma separated
206-
if (DiagnosticsHelper.isFunctionsRpIntegration()) {
207+
if (DiagnosticsHelper.isFunctionsRpIntegratedAuto()) {
207208
appender.setLayout(
208209
new ApplicationInsightsCsvLayout(PropertyHelper.getQualifiedSdkVersionString()));
209210
} else {

agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void shouldParseFromEnvVar() throws IOException {
105105

106106
@Test
107107
void shouldThrowFromEnvVarIfEmbeddedConnectionStringAndAppSvcRpIntegration() {
108-
DiagnosticsHelper.setAppSvcRpIntegration(true);
108+
DiagnosticsHelper.setAppSvcRpIntegratedAuto(true);
109109
try {
110110
String contentJson =
111111
"{\"connectionString\":\"InstrumentationKey=55555555-5555-5555-5555-555555555555\","
@@ -115,7 +115,7 @@ void shouldThrowFromEnvVarIfEmbeddedConnectionStringAndAppSvcRpIntegration() {
115115
assertThatThrownBy(() -> ConfigurationBuilder.create(Paths.get("."), null))
116116
.isInstanceOf(ConfigurationBuilder.ConfigurationException.class);
117117
} finally {
118-
DiagnosticsHelper.setAppSvcRpIntegration(false);
118+
DiagnosticsHelper.setAppSvcRpIntegratedAuto(false);
119119
}
120120
}
121121

agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/diagnostics/DiagnosticsTestHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class DiagnosticsTestHelper {
77
private DiagnosticsTestHelper() {}
88

99
public static void setIsAppSvcAttachForLoggingPurposes(boolean appSvcAttachForLoggingPurposes) {
10-
DiagnosticsHelper.setAppSvcRpIntegration(appSvcAttachForLoggingPurposes);
10+
DiagnosticsHelper.setAppSvcRpIntegratedAuto(appSvcAttachForLoggingPurposes);
1111
}
1212

1313
public static void reset() {

0 commit comments

Comments
 (0)