Simple module for OpenResty to send errors to Rollbar.
lua-resty-rollbar
is a Lua Rollbar client that makes it easy to report errors to Rollbar with
stack traces. Errors are sent to Rollbar asynchronously in a light thread.
Install using LuaRocks:
luarocks install lua-resty-rollbar 0.1.0
local rollbar = require 'resty.rollbar'
-- Set your Rollbar token
-- This token must have 'post_server_item' scope
rollbar.set_token('MY_TOKEN')
-- Set the set_environment. Defaults to 'development'
rollbar.set_environment('production')
function main()
local res, err = do_something()
if not res {
-- Error reporting
-- This function will automatically read request information (URI, method,...) if available before reporting the error to Rollbar
rollbar.report(rollbar.ERR, err)
-- If the error reporting occurs from outside a request context (eg. inside a timer), you can supply a third parameter to prevent
-- an useless function call that will try to read non existing request information
rollbar.report(rollbar.ERR, err, {})
return
}
end
The tests are written using the busted unit testing framework. To ease the testing of this package, we provide a self contained Docker Compose file to execute the unit tests.
Run the Docker Compose container in a terminal:
docker compose up
In a different terminal, execute the tests with:
docker compose exec test busted specs
luarocks upload --api-key=<API key> ./lua-resty-rollbar-0.1.0-1.rockspec
The API key is from LuaRocks settings.