From 1585293f5d4a649a69553390f9b76191e5e691be Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 8 Aug 2023 12:51:32 -0700 Subject: [PATCH 1/2] Fix azure functions consumption initialization --- .../FunctionEnvironmentReloadInstrumentation.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/agent/instrumentation/azure-functions/src/main/java/io/opentelemetry/javaagent/instrumentation/azurefunctions/FunctionEnvironmentReloadInstrumentation.java b/agent/instrumentation/azure-functions/src/main/java/io/opentelemetry/javaagent/instrumentation/azurefunctions/FunctionEnvironmentReloadInstrumentation.java index 57a3cf9bd03..fb35ab1b156 100644 --- a/agent/instrumentation/azure-functions/src/main/java/io/opentelemetry/javaagent/instrumentation/azurefunctions/FunctionEnvironmentReloadInstrumentation.java +++ b/agent/instrumentation/azure-functions/src/main/java/io/opentelemetry/javaagent/instrumentation/azurefunctions/FunctionEnvironmentReloadInstrumentation.java @@ -32,6 +32,12 @@ public void transform(TypeTransformer transformer) { public static class ExecuteAdvice { @Advice.OnMethodExit(suppress = Throwable.class) public static void methodExit() { + + if (System.getenv("AzureWebJobsStorage") == null) { + // specialization hasn't occurred yet, and this is just a fake warmup request + return; + } + AzureFunctions.configureOnce(); } } From 4e8ca80a7652cd6a1d2505866a01784a48d90ebc Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 11 Aug 2023 10:15:14 -0700 Subject: [PATCH 2/2] Fix Functions self-diagnostics logging on Windows --- .../internal/diagnostics/DiagnosticsHelper.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/diagnostics/DiagnosticsHelper.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/diagnostics/DiagnosticsHelper.java index ef6962317fe..972bfd7ff8e 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/diagnostics/DiagnosticsHelper.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/diagnostics/DiagnosticsHelper.java @@ -33,17 +33,20 @@ private DiagnosticsHelper() {} } public static void initRpIntegration(Path agentPath) { - if (!Strings.isNullOrEmpty(System.getenv("WEBSITE_SITE_NAME"))) { + // important to check FUNCTIONS_WORKER_RUNTIME before WEBSITE_SITE_NAME + // TODO (heya) how should we report functions windows users who are using app services + // windows attach by manually setting the env vars (which was the old documented way) + if ("java".equals(System.getenv("FUNCTIONS_WORKER_RUNTIME"))) { + rpIntegrationChar = 'f'; + functionsRpIntegration = true; + setRpAttachType(agentPath, "functions.codeless"); + } else if (!Strings.isNullOrEmpty(System.getenv("WEBSITE_SITE_NAME"))) { rpIntegrationChar = 'a'; appSvcRpIntegration = true; setRpAttachType(agentPath, "appsvc.codeless"); } else if (!Strings.isNullOrEmpty(System.getenv("KUBERNETES_SERVICE_HOST"))) { rpIntegrationChar = 'k'; setRpAttachType(agentPath, "aks.codeless"); - } else if ("java".equals(System.getenv("FUNCTIONS_WORKER_RUNTIME"))) { - rpIntegrationChar = 'f'; - functionsRpIntegration = true; - setRpAttachType(agentPath, "functions.codeless"); } else if (!Strings.isNullOrEmpty( System.getenv("APPLICATIONINSIGHTS_SPRINGCLOUD_SERVICE_ID"))) { rpIntegrationChar = 's';