Module raven
raven.lua: a Lua Raven client used to send errors to Sentry
According to client development guide
The following items are expected of production-ready clients:
- DSN configuration √
- Graceful failures (e.g.
Sentry server unreachable) √
- Scrubbing w/ processors
- Tag support √
To test a DSN configuration:
$ lua raven.lua test [DSN]
Info:
- Copyright: (c) 2013-2014, CloudFlare, Inc.
- Author: JGC
,Jiale Zhi
Functions
new (self, dsn, conf) | Create a new Sentry client. |
captureException (self, exception, conf) | Send an exception to Sentry. |
captureMessage (self, message, conf) | Send a message to Sentry. |
call (self, f, ...) | Call function f with parameters ... |
Functions
- new (self, dsn, conf)
-
Create a new Sentry client. Three parameters:
Parameters:
- self raven client
- dsn
The DSN of the Sentry instance with this format:
{PROTOCOL}://{PUBLIC_KEY}:{SECRET_KEY}@{HOST}/{PATH}{PROJECT_ID}
http://pub:secret@127.0.0.1:8080/sentry/proj-id
- conf
client configuration. Conf should be a hash table. Possible keys are:
- tags extra tags to include on all reported errors
- logger
- verify_ssl boolean of whether to perform SSL certificate verification
- cafile path to CA certificate bundle file. Required only when using luasec, ngx version uses the lua_ssl_trusted_certificate directive for this.
{ tags = { foo = "bar", abc = "def" }, logger = "myLogger", verify_ssl = false }
Returns:
-
a new raven instance
Usage:
local raven = require "raven" local rvn = raven:new(dsn, { tags = { foo = "bar", abc = "def" }, logger = "myLogger" })
- captureException (self, exception, conf)
-
Send an exception to Sentry.
see reference.
Parameters:
- self raven client
- exception
a hash table describing an exception. For example:
{{ ["type"] = "SyntaxError", ["value"] = "Wattttt!", ["module"] = "__builtins__", stacktrace = { frames = { { filename = "/real/file/name", func = "myfunc", lineno" = 3 }, { filename = "/real/file/name", func = "myfunc1", lineno" = 10 }, } } }}
- conf capture configuration. Conf should be a hash table. Possible keys are: "tags", "trace_level". "tags" will be send to Sentry together with "tags" in client configuration. "trace_level" is used for geting stack backtracing. You shouldn't pass this argument unless you know what you are doing.
Returns:
-
On success, return event id. If not success, return nil and
an error string.
Usage:
local raven = require "raven" local rvn = raven:new(dsn, { tags = { foo = "bar", abc = "def" }, logger = "myLogger" }) local id, err = rvn:captureException(exception, { tags = { foo = "bar", abc = "def" }})
- captureMessage (self, message, conf)
-
Send a message to Sentry.
Parameters:
- self raven client
- message arbitrary message (most likely an error string)
- conf capture configuration. Conf should be a hash table. Possiable keys are: "tags", "trace_level". "tags" will be send to Sentry together with "tags" in client configuration. "trace_level" is used for geting stack backtracing. You shouldn't pass this argument unless you know what you are doing.
Returns:
-
On success, return event id. If not success, return nil and
error string.
Usage:
local raven = require "raven" local rvn = raven:new(dsn, { tags = { foo = "bar", abc = "def" }, logger = "myLogger" }) local id, err = rvn:captureMessage("Sample message", { tags = { foo = "bar", abc = "def" }})
- call (self, f, ...)
-
Call function f with parameters ... wrapped in a xpcall and
send any exception to Sentry. Returns a boolean indicating whether
the function execution worked and an error if not
Parameters:
- self raven client
- f function to be called
- ... function "f" 's arguments
Returns:
-
the same with xpcall
Usage:
function func(a, b, c) return a * b + c end return rvn:call(func, a, b, c)