Skip to content

Commit 965405b

Browse files
authored
Fix azure functions consumption initialization (#3244)
1 parent 5517341 commit 965405b

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,20 @@ private DiagnosticsHelper() {}
3333
}
3434

3535
public static void initRpIntegration(Path agentPath) {
36-
if (!Strings.isNullOrEmpty(System.getenv("WEBSITE_SITE_NAME"))) {
36+
// important to check FUNCTIONS_WORKER_RUNTIME before WEBSITE_SITE_NAME
37+
// TODO (heya) how should we report functions windows users who are using app services
38+
// windows attach by manually setting the env vars (which was the old documented way)
39+
if ("java".equals(System.getenv("FUNCTIONS_WORKER_RUNTIME"))) {
40+
rpIntegrationChar = 'f';
41+
functionsRpIntegration = true;
42+
setRpAttachType(agentPath, "functions.codeless");
43+
} else if (!Strings.isNullOrEmpty(System.getenv("WEBSITE_SITE_NAME"))) {
3744
rpIntegrationChar = 'a';
3845
appSvcRpIntegration = true;
3946
setRpAttachType(agentPath, "appsvc.codeless");
4047
} else if (!Strings.isNullOrEmpty(System.getenv("KUBERNETES_SERVICE_HOST"))) {
4148
rpIntegrationChar = 'k';
4249
setRpAttachType(agentPath, "aks.codeless");
43-
} else if ("java".equals(System.getenv("FUNCTIONS_WORKER_RUNTIME"))) {
44-
rpIntegrationChar = 'f';
45-
functionsRpIntegration = true;
46-
setRpAttachType(agentPath, "functions.codeless");
4750
} else if (!Strings.isNullOrEmpty(
4851
System.getenv("APPLICATIONINSIGHTS_SPRINGCLOUD_SERVICE_ID"))) {
4952
rpIntegrationChar = 's';

agent/instrumentation/azure-functions/src/main/java/io/opentelemetry/javaagent/instrumentation/azurefunctions/FunctionEnvironmentReloadInstrumentation.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public void transform(TypeTransformer transformer) {
3232
public static class ExecuteAdvice {
3333
@Advice.OnMethodExit(suppress = Throwable.class)
3434
public static void methodExit() {
35+
36+
if (System.getenv("AzureWebJobsStorage") == null) {
37+
// specialization hasn't occurred yet, and this is just a fake warmup request
38+
return;
39+
}
40+
3541
AzureFunctions.configureOnce();
3642
}
3743
}

0 commit comments

Comments
 (0)