Repository navigation
Description
In Exceptionless 6.2.0 (core Exceptionless package), ReadFromEnvironmentalVariables() is meant to turn on ProcessQueueOnCompletedRequest automatically when running in AWS Lambda, but it looks up "AWS_LAMBDA_FUNCTION_NAME " (with a trailing space). No such variable exists, so the Lambda check never fires.
Where
- (the check is on line 500)
Exceptionless.Net/src/Exceptionless/Extensions/ExceptionlessConfigurationExtensions.cs
Lines 496 to 506 in 5792f00
// if we are running in a serverless environment default this config to true if (String.IsNullOrEmpty(processQueueOnCompletedRequestValue)) { // check for AWS lambda environment if (!String.IsNullOrEmpty(GetEnvironmentalVariable("AWS_LAMBDA_FUNCTION_NAME "))) processQueueOnCompletedRequestValue = Boolean.TrueString; // check for azure functions environment if (!String.IsNullOrEmpty(GetEnvironmentalVariable("FUNCTIONS_WORKER_RUNTIME"))) processQueueOnCompletedRequestValue = Boolean.TrueString; } - (
Exceptionless.Net/src/Exceptionless/Extensions/ExceptionlessConfigurationExtensions.cs
Lines 518 to 535 in 5792f00
private static string GetEnvironmentalVariable(string name) { if (String.IsNullOrEmpty(name)) return null; if (_environmentVariables == null) { try { _environmentVariables = Environment.GetEnvironmentVariables().Cast<DictionaryEntry>().ToDictionary(e => e.Key.ToString(), e => e.Value.ToString()); } catch (Exception) { _environmentVariables = new Dictionary<string, string>(); return null; } } if (!_environmentVariables.ContainsKey(name)) return null; return _environmentVariables[name]; } GetEnvironmentalVariabledoes an exact, untrimmed key lookup)
What happens
On AWS Lambda, AWS_LAMBDA_FUNCTION_NAME is set, but the lookup is for AWS_LAMBDA_FUNCTION_NAME , so it returns null. ProcessQueueOnCompletedRequest stays false unless the app sets it explicitly, and the ASP.NET Core middleware does not flush the queue at the end of each request. Lambda freezes the process after the response is sent, so queued events can sit unsent until a later invocation, or be lost when the environment is recycled (see #215 for the original report of this behavior). The Azure Functions check on the next line (FUNCTIONS_WORKER_RUNTIME) works because it has no trailing space.
Expected
When AWS_LAMBDA_FUNCTION_NAME is set and Exceptionless:ProcessQueueOnCompletedRequest is not configured, ProcessQueueOnCompletedRequest is set to true, the same as on Azure Functions.
Steps to reproduce
- Set the environment variable
AWS_LAMBDA_FUNCTION_NAME=testand do not setExceptionless__ProcessQueueOnCompletedRequest. - Create a client and call
client.Configuration.ReadFromEnvironmentalVariables()(orclient.Startup()). client.Configuration.ProcessQueueOnCompletedRequestisfalse. Repeat withFUNCTIONS_WORKER_RUNTIME=dotnetand it istrue.
Suggested fix
Remove the trailing space: GetEnvironmentalVariable("AWS_LAMBDA_FUNCTION_NAME"), and add a test that covers both serverless variables.
Activity