Swiftpack.co - Package - nodes-vapor/bugsnag

Bugsnag 🐛

Swift Version Vapor Version Circle CI codebeat badge codecov Readme Score GitHub license

Reporting errors to Bugsnag.

📦 Installation

Integrating Bugsnag in your project

Update your Package.swift file.

.package(url: "https://github.com/nodes-vapor/bugsnag.git", .upToNextMinor(from: "3.0.0"))

Update Sources/App/configure.swift

public func configure(
    _ config: inout Config,
    _ env: inout Environment,
    _ services: inout Services
) throws {
    // Register provider
    let bugsnagProvider = BugsnagProvider(config: BugsnagConfig(
        apiKey: "<YOUR BUGSNAG API KEY>",
        releaseStage: environment.name,
        shouldReport: environment.name != "local"
        debug: false
    try services.register(bugsnagProvider)


    // Register middleware

    var middlewaresConfig = MiddlewareConfig()
    middlewaresConfig.use(BugsnagMiddleware.self) // Catch errors and report to bugsnag



Bugsnag offers three different types of reports: info, warning and error. To make a report just instantiate a ErrorReporter and use the respective functions.

let reporter = try req.make(ErrorReporter.self) // or `BugsnagReporter.self`

reporter.report(Abort(.upgradeRequired), severity: .info, on: req)
reporter.report(Abort(.notFound), severity: .warning, on: req)
reporter.report(Abort(.internalServerError), severity: .error, on: req) // you can omit the `severity` parameter since `.error` is the default

It's also possible to attach metadata to the report.

    metadata: ["key": "value"],
    on: req


Conforming your Authenticatable model to BugsnagReportableUser allows you to easily pair the data to a report. The protocol requires your model to have an id field that is CustomStringConvertible.

extension YourUser: BugsnagReportableUser {}

try reporter.error(userType: YourUser.self, Abort(.notFound), on: req)


Breadcrumbs enable you to attach custom events to your reports. Leave a breadcrumb using the convenience function on Request.

    name: "Something happened!",
    type: .manual,
    metadata: ["foo": "bar"]

The breadcrumb types are provided by Bugsnag:

enum BreadcrumbType {
    case navigation
    case request
    case process
    case log
    case user
    case state
    case error
    case manual

🏆 Credits

This package is developed and maintained by the Vapor team at Nodes. The package owner for this project is Siemen.

📄 License

This package is open-sourced software licensed under the MIT license.


Stars: 30
Help us keep the lights on



3.0.0-rc.3 - Jun 1, 2019


  • Now reports breadcrumbs metadata to Bugsnag in the correct way

3.0.0-rc.2 - May 16, 2019


  • Included more meta information in case the underlying error is an NSError (domain, user info, error code)


  • Debug description of the request was removed because it could contain security and privacy sensitive data

3.0.0-rc.1 - Mar 6, 2019


  • force explicit handling of return type for BugsnagReporter.report(...)
  • make report extensions on ErrorReporter protocol public
  • use req.client instead of HTTPClient.connect for improved stability

3.0.0-beta.3 - Feb 14, 2019


  • Support for filtering out keys from the request (e.g. to remove sensitive information such as passwords)


  • Reporting now takes in a Container instead of a Request. This allows for reporting in cases where you don't have a request.

3.0.0-beta.2 - Feb 8, 2019


  • the 'Future's you get when reporting to Bugsnag now no longer be ignored unless you explicitly use _ = reporter.report(...)


  • BugsnagMiddleware is registered by the provider.