Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/WebJobs.Script/Diagnostics/DiagnosticEventConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ internal static class DiagnosticEventConstants

public const string WorkerRuntimeDoesNotMatchWithFunctionMetadataErrorCode = "AZFD0013";
public const string WorkerRuntimeDoesNotMatchWithFunctionMetadataHelpLink = "https://aka.ms/functions-invalid-worker-runtime";

public const string DeprecatedProxiesErrorCode = "AZFD0014";
public const string DeprecatedProxiesHelpLink = "https://aka.ms/functions-deprecated-proxies";
}
}
7 changes: 7 additions & 0 deletions src/WebJobs.Script/Host/ProxyFunctionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.Azure.AppService.Proxy.Client;
using Microsoft.Azure.WebJobs.Logging;
using Microsoft.Azure.WebJobs.Script.Description;
using Microsoft.Azure.WebJobs.Script.Diagnostics;
using Microsoft.Azure.WebJobs.Script.Eventing;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -127,6 +128,12 @@ internal static Collection<ProxyFunctionMetadata> ReadProxyMetadata(string scrip
logger.LogInformation("Loading proxies metadata");
var metadataCollection = LoadProxyMetadata(proxiesJson, functionErrors, logger);
logger.LogInformation($"{metadataCollection.Count} proxies loaded");

if (metadataCollection.Count > 0)
{
logger.LogDiagnosticEventWarning(DiagnosticEventConstants.DeprecatedProxiesErrorCode, "Azure Functions Proxies are deprecated and community support will end on September 30, 2025. Please migrate to Azure API Management or Azure Container Apps. See https://aka.ms/functions-deprecated-proxies for more information.", DiagnosticEventConstants.DeprecatedProxiesHelpLink, null);
Copy link
Preview

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This warning message is very long (over 200 characters) and should be broken into multiple lines for better readability. Consider using string interpolation or multiline string formatting to improve maintainability.

Suggested change
logger.LogDiagnosticEventWarning(DiagnosticEventConstants.DeprecatedProxiesErrorCode, "Azure Functions Proxies are deprecated and community support will end on September 30, 2025. Please migrate to Azure API Management or Azure Container Apps. See https://aka.ms/functions-deprecated-proxies for more information.", DiagnosticEventConstants.DeprecatedProxiesHelpLink, null);
logger.LogDiagnosticEventWarning(
DiagnosticEventConstants.DeprecatedProxiesErrorCode,
@"Azure Functions Proxies are deprecated and community support will end on September 30, 2025.
Please migrate to Azure API Management or Azure Container Apps.
See https://aka.ms/functions-deprecated-proxies for more information.",
DiagnosticEventConstants.DeprecatedProxiesHelpLink,
null);

Copilot uses AI. Check for mistakes.

}

return metadataCollection;
}

Expand Down
44 changes: 44 additions & 0 deletions test/WebJobs.Script.Tests/ProxyFunctionProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Script.Description;
using Microsoft.Azure.WebJobs.Script.Eventing;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using WebJobs.Script.Tests;
Expand Down Expand Up @@ -60,5 +61,48 @@ public async Task ProxyMetadata_WhenProxyFileChanges_IsRefreshed()
Assert.Equal(20, proxyMetadata3.Length);
}
}

[Fact]
public async Task ProxyFunctionProvider_WhenProxiesEnabled_EmitsDiagnosticWarning()
{
using (var tempDirectory = new TempDirectory())
{
var testProxiesPath = Path.Combine(Environment.CurrentDirectory, @"TestScripts\Proxies");
var options = new OptionsWrapper<ScriptJobHostOptions>(new ScriptJobHostOptions
{
RootScriptPath = tempDirectory.Path
});

var environment = new TestEnvironment(new Dictionary<string, string>
{
{ EnvironmentSettingNames.AzureWebJobsFeatureFlags, ScriptConstants.FeatureFlagEnableProxies },
});
var eventManager = new ScriptEventManager();
var loggerFactory = new LoggerFactory();
var testLogger = new TestLogger("Startup");
loggerFactory.AddProvider(new TestLoggerProvider(testLogger));

var provider = new ProxyFunctionProvider(options, environment, eventManager, loggerFactory);

// Copy proxies definition to trigger the warning
FileUtility.CopyDirectory(testProxiesPath, tempDirectory.Path);

// Get metadata to trigger loading of proxies and the diagnostic warning
ImmutableArray<FunctionMetadata> proxyMetadata = await provider.GetFunctionMetadataAsync();

// Verify proxies were loaded
Assert.NotEmpty(proxyMetadata);

var warningLog = testLogger.GetLogMessages().FirstOrDefault(m =>
m.Level == LogLevel.Warning &&
m.State is IDictionary<string, object> state &&
state.ContainsKey(ScriptConstants.ErrorCodeKey) &&
state[ScriptConstants.ErrorCodeKey].ToString() == DiagnosticEventConstants.DeprecatedProxiesErrorCode);
Comment on lines +96 to +100
Copy link
Preview

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The LINQ query for finding the warning log is complex and hard to read. Consider extracting this into a helper method or breaking it into multiple steps with intermediate variables for better readability.

Suggested change
var warningLog = testLogger.GetLogMessages().FirstOrDefault(m =>
m.Level == LogLevel.Warning &&
m.State is IDictionary<string, object> state &&
state.ContainsKey(ScriptConstants.ErrorCodeKey) &&
state[ScriptConstants.ErrorCodeKey].ToString() == DiagnosticEventConstants.DeprecatedProxiesErrorCode);
var logMessages = testLogger.GetLogMessages();
var warningLogs = logMessages.Where(m => m.Level == LogLevel.Warning);
var logsWithState = warningLogs.Where(m => m.State is IDictionary<string, object>);
var logsWithErrorCode = logsWithState.Where(m =>
((IDictionary<string, object>)m.State).ContainsKey(ScriptConstants.ErrorCodeKey) &&
((IDictionary<string, object>)m.State)[ScriptConstants.ErrorCodeKey].ToString() == DiagnosticEventConstants.DeprecatedProxiesErrorCode);
var warningLog = logsWithErrorCode.FirstOrDefault();

Copilot uses AI. Check for mistakes.


Assert.NotNull(warningLog);
Assert.Contains("Azure Functions Proxies are deprecated", warningLog.FormattedMessage);
Assert.Contains("September 30, 2025", warningLog.FormattedMessage);
}
}
}
}