Bugsnag::Middleware
Inherits HTTP::Handler < Reference < Object
Report errors that occur in your HTTP apps to Bugsnag automatically.
http = HTTP::Server.new([
Bugsnag::Middleware.new
.with_user { |context| Bugsnag::User.from_user(find_user_from(context)) }
.with_app { Bugsnag::App.new(id: "my-app") }
.with_metadata { |context| Bugsnag::Metadata{"session" => context.session.data} },
my_app,
])
Constructors
Instance methods
Give the Bugsnag middleware information about the running app, including the name, version, release stage (production, development, beta, etc), and even how long it's been running.
started_at = Time.monotonic
Bugsnag::Middleware.new
.with_app { |context| Bugsnag::App.new(
id: "my-app-web",
version: ENV["GIT_REF"]?,
release_stage: ENV["DEPLOYMENT_ENVIRONMENT"]? || "development",
duration: Time.monotonic - started_at,
) }
For more details, see Bugsnag::App.
Tell the Bugsnag middleware what other information may be useful based on
the HTTP::Server::Context for the current request. For example, maybe
you want to include session data. The keys for a Metadata object must be
strings and the values must be JSON-serializable objects, such as
JSON::Any (or any type it can wrap) or an object that includes
JSON::Serializable.
Bugsnag::Middleware.new
.with_metadata { |context| Bugsnag::Metadata{
"session" => context.session.data,
"environment" => filter(hash_from(ENV)),
} }
Tell the Bugsnag middleware how to infer the user from the
HTTP::Server::Context for the current request.
Bugsnag::Middleware.new
.with_user { |context| Bugsnag::User.from_user(context.current_user) }