Skip to content

AWS Lambda detection never matches because the environment variable name has a trailing space #386

Open

Description

@ejsmith

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

  • // 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;
    }
    (the check is on line 500)
  • 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];
    }
    (GetEnvironmentalVariable does 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

  1. Set the environment variable AWS_LAMBDA_FUNCTION_NAME=test and do not set Exceptionless__ProcessQueueOnCompletedRequest.
  2. Create a client and call client.Configuration.ReadFromEnvironmentalVariables() (or client.Startup()).
  3. client.Configuration.ProcessQueueOnCompletedRequest is false. Repeat with FUNCTIONS_WORKER_RUNTIME=dotnet and it is true.

Suggested fix

Remove the trailing space: GetEnvironmentalVariable("AWS_LAMBDA_FUNCTION_NAME"), and add a test that covers both serverless variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions