aws-lambda-haskell-runtime icon indicating copy to clipboard operation
aws-lambda-haskell-runtime copied to clipboard

log the error to stderr when an error is thrown

Open stevemao opened this issue 3 years ago • 0 comments

Lambda doesn't log the error automatically when it's reported. This makes it very hard to debug when integrating with other service such as API gateway. Although users of this library can print logs anywhere they want, they cannot print the error that is thrown from the library. All uncaught errors should be printed to stderr. This aligns the behaviour of other runtime engines such as Nodejs.

The logger is passed as an option so that users can choose to overwrite the format of the logs.

Before

2022-03-14T23:52:09.027+11:00 | START RequestId: 6eedee44-a17a-45c4-92f1-92b0ccc01dca Version: $LATEST
-- | --
  | 2022-03-14T23:52:09.065+11:00 | END RequestId: 6eedee44-a17a-45c4-92f1-92b0ccc01dca
  | 2022-03-14T23:52:09.065+11:00 | REPORT RequestId: 6eedee44-a17a-45c4-92f1-92b0ccc01dca Duration: 34.33 ms Billed Duration: 77 ms Memory Size: 128 MB Max Memory Used: 22 MB Init Duration: 41.72 ms

After

2022-03-15T23:08:58.239+11:00 | START RequestId: 5fe9c264-9527-4e8f-bcfd-6c1e89e7382e Version: $LATEST
-- | --
  | 2022-03-15T23:08:59.564+11:00 | 5fe9c264-9527-4e8f-bcfd-6c1e89e7382e ERROR Invocation Error {"isBase64Encoded":false,"statusCode":400,"body":"Parsing {errorMessage = \"Error in $: key \\\"resource\\\" not found\", actualValue = \"{\\\"version\\\":\\\"2.0\\\",\\\"routeKey\\\":\\\"POST /start\\\",\\\"rawPath\\\":\\\"/start\\\",\\\"rawQueryString\\\":\\\"\\\",\\\"headers\\\":{\\\"accept\\\":\\\"*/*\\\",\\\"accept-encoding\\\":\\\"gzip, deflate, br\\\",\\\"cache-control\\\":\\\"no-cache\\\",\\\"content-length\\\":\\\"14\\\",\\\"content-type\\\":\\\"application/json\\\",\\\"host\\\":\\\"9u1pm42rf6.execute-api.ap-southeast-2.amazonaws.com\\\",\\\"postman-token\\\":\\\"3ad02f7a-20e4-499d-b748-148a17f6bc19\\\",\\\"user-agent\\\":\\\"PostmanRuntime/7.29.0\\\",\\\"x-amzn-trace-id\\\":\\\"Root=1-623081d8-5ca0569150e6d8120445a39c\\\",\\\"x-forwarded-for\\\":\\\"14.200.247.110\\\",\\\"x-forwarded-port\\\":\\\"443\\\",\\\"x-forwarded-proto\\\":\\\"https\\\"},\\\"requestContext\\\":{\\\"accountId\\\":\\\"905299074195\\\",\\\"apiId\\\":\\\"9u1pm42rf6\\\",\\\"domainName\\\":\\\"9u142rf6.execute-api.ap-southeast-2.amazonaws.com\\\",\\\"domainPrefix\\\":\\\"9u6\\\",\\\"http\\\":{\\\"m
  | 2022-03-15T23:09:00.804+11:00 | ...
  | 2022-03-15T23:09:00.824+11:00 | END RequestId: 5fe9c264-9527-4e8f-bcfd-6c1e89e7382e
  | 2022-03-15T23:09:00.824+11:00 | REPORT RequestId: 5fe9c264-9527-4e8f-bcfd-6c1e89e7382e Duration: 2583.89 ms Billed Duration: 3706 ms Memory Size: 128 MB Max Memory Used: 46 MB Init Duration: 1121.73 ms

stevemao avatar Mar 15 '22 12:03 stevemao