Skip to content

Commit

Permalink
Merge pull request #20 from axiomhq/islam/axm-1660-tackle-hapn-reques…
Browse files Browse the repository at this point in the history
…ts-over-lambda-extension

introduce PANIC_ON_API_ERR
  • Loading branch information
dasfmi authored Sep 27, 2023
2 parents 496eee5 + 245e563 commit cdf1654
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cdf1654

Please sign in to comment.