From 245e56388fe355e6481be383163f0cea318362f4 Mon Sep 17 00:00:00 2001 From: Islam Shehata Date: Wed, 27 Sep 2023 20:14:58 +0300 Subject: [PATCH] introduce PANIC_ON_API_ERR --- README.md | 5 +++++ main.go | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4bef082..1e279d6 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,9 @@ For more detail on how to disable the CloudWatch logging, see the [Axiom documen - `AXIOM_DATASET`: The dataset name to send logs to. Learn more about creating a dataset [here](https://www.axiom.co/docs/reference/settings#dataset) - `AXIOM_TOKEN`: The Axiom API token (needs ingest permission into the dataset above). Learn more about creating tokens [here](https://www.axiom.co/docs/restapi/token#creating-an-access-token) +**note** the extensions will not work without correct credentials, but it will not crash your function. If you want it to crash for testing purposes +check the [Troubleshooting](#troubleshooting) section below. + 2. Add the extension as a layer with the AWS CLI: @@ -136,6 +139,8 @@ module "lambda_function" { Double check that the API token has permission to ingest data into the dataset. If that is not the issue, please check the function logs on the AWS console, the extension will log any errors with setup or ingest. +For testing purposes you can also set the `PANIC_ON_API_ERR` environment variable to `true` to tell the extension to crash if couldn't connect to Axiom. + ## License © Axiom, Inc., 2023 diff --git a/main.go b/main.go index d51f3df..ab6b68b 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ import ( var ( runtimeAPI = os.Getenv("AWS_LAMBDA_RUNTIME_API") + crashOnAPIErr = os.Getenv("PANIC_ON_API_ERR") extensionName = filepath.Base(os.Args[0]) isFirstInvocation = true runtimeDone = make(chan struct{}) @@ -65,7 +66,11 @@ func Run() error { if err != nil { // We don't want to exit with error, so that the extensions doesn't crash and crash the main function with it. // so we continue even if Axiom client is nil - logger.Error("error creating axiom client", zap.Error(err)) + logger.Error("error creating axiom client, no logs will send to Axiom.", zap.Error(err)) + // if users want to crash on error, they can set the PANIC_ON_API_ERROR env variable + if crashOnAPIErr == "true" { + return err + } } httpServer := server.New(logsPort, axiom, runtimeDone)