You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 20, 2024. It is now read-only.
let bugsnagProvider =BugsnagProvider(config: BugsnagConfig(
25
+
publicfuncconfigure(_app: Application) throws {
26
+
// Configure Bugsnag.
27
+
app.bugsnag.configuration= .init(
33
28
apiKey: "<YOUR BUGSNAG API KEY>",
34
-
releaseStage: environment.name,
35
-
shouldReport: environment.name!="local"
36
-
debug:false
37
-
))
38
-
try services.register(bugsnagProvider)
29
+
releaseStage: app.environment.name,
30
+
shouldReport: app.environment.name!="local"
31
+
)
39
32
40
-
...
41
-
42
-
// Register middleware
43
-
44
-
var middlewaresConfig =MiddlewareConfig()
45
-
...
46
-
middlewaresConfig.use(BugsnagMiddleware.self) // Catch errors and report to bugsnag
47
-
...
48
-
services.register(middlewaresConfig)
49
-
50
-
...
33
+
// Add Bugsnag middleware.
34
+
app.middleware.use(BugsnagMiddleware())
51
35
}
52
36
```
53
37
54
38
### Reporting
55
-
Bugsnag offers three different types of reports: info, warning and error. To make a report just instantiate an `ErrorReporter` and use the respective functions.
56
39
57
-
##### Examples
58
-
```swift
59
-
let reporter =try req.make(ErrorReporter.self) // or `BugsnagReporter.self`
40
+
`BugsnagMiddleware` will automatically report errors thrown by your route handlers. You can report errors manually from `Application` or `Request`.
60
41
61
-
reporter.report(Abort(.upgradeRequired), severity: .info, on: req)
62
-
reporter.report(Abort(.notFound), severity: .warning, on: req)
63
-
reporter.report(Abort(.internalServerError), severity: .error, on: req) // you can omit the `severity` parameter since `.error` is the default
64
-
```
65
-
66
-
It's also possible to attach metadata to the report.
67
42
```swift
68
-
reporter.report(
69
-
Abort(.internalServerError),
70
-
metadata: ["key":"value"],
71
-
on: req
72
-
)
43
+
// Reporting from Application.
44
+
app.bugsnag.report(Abort(.internalServerError))
45
+
46
+
// Reporting from Request.
47
+
app.get("test") { req in
48
+
req.bugsnag.report(Abort(.upgradeRequired))
49
+
return HTTPStatus.ok
50
+
}
73
51
```
74
52
75
-
By conforming to the `ReportableError` protocol you can have full control over how (and if) the BugsnagMiddleware reports your errors. It has the following properties:
53
+
By conforming to the `BugsnagError` protocol you can have full control over how your errors are reported. It has the following properties:
76
54
77
55
| Name | Type | Function | Default |
78
56
|---|---|---|---|
79
57
|`shouldReport`|`Bool`| Opt out of error reporting by returning `false`|`true`|
|`userId`|`CustomStringConvertible?`| An optional user id associated with the error |`nil`|
82
59
|`metadata`|`[String: CustomDebugStringConvertible]`| Additional metadata to include in the report |`[:]`|
83
60
84
-
####Users
85
-
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`.
61
+
### Users
62
+
Conforming your `Authenticatable` model to `BugsnagUser` allows you to easily pair the data to a report.
86
63
87
64
```swift
88
-
extensionYourUser: BugsnagReportableUser {}
65
+
extensionTestUser: BugsnagUser {
66
+
var bugsnagID: CustomStringConvertible? {
67
+
self.id
68
+
}
69
+
}
70
+
```
71
+
72
+
Configure all user models you would like Bugsnag to report.
89
73
90
-
try reporter.error(userType: YourUser.self, Abort(.notFound), on: req)
74
+
```swift
75
+
// Add to configure.swift.
76
+
app.bugsnag.users.add(TestUser.self)
91
77
```
92
78
93
-
#### Breadcrumbs
79
+
Bugsnag will automatically check Vapor's authentication API for the configured user types and report the user's identifier if they are logged in.
80
+
81
+
### Breadcrumbs
94
82
Breadcrumbs enable you to attach custom events to your reports. Leave a breadcrumb using the convenience function on `Request`.
95
83
96
84
```swift
97
-
req.breadcrumb(
85
+
req.bugsnag.breadcrumb(
98
86
name: "Something happened!",
99
87
type: .manual,
100
88
metadata: ["foo":"bar"]
101
89
)
102
90
```
103
91
104
92
The breadcrumb types are provided by Bugsnag:
93
+
105
94
```swift
106
-
enumBreadcrumbType {
95
+
enumBugsnagBreadcrumbType {
96
+
caseerror
97
+
caselog
98
+
casemanual
107
99
casenavigation
108
-
caserequest
109
100
caseprocess
110
-
caselog
111
-
caseuser
101
+
caserequest
112
102
casestate
113
-
caseerror
114
-
casemanual
103
+
caseuser
115
104
}
116
105
```
117
106
118
-
#### Filter out fields from reports
107
+
### Key Filters
108
+
119
109
Usually you will receive information such as headers, query params or post body fields in the reports from Bugsnag. To ensure that you do not track sensitive information, you can configure Bugsnag with a list of fields that should be filtered out:
In this case Bugsnag Reports won't contain header fields, query params or post body json fields with the keys/names **password**, **email**, **authorization**,**lastname**.
118
+
In this case Bugsnag Reports will hide header fields, query params or post body json fields with the keys/names **email** and**password**.
129
119
130
-
⚠️ Note: in JSON bodies, this only works for the first level of fields and not for nested children.
120
+
⚠️ Note: If key filters are defined and Bugsnag does not know how to parse the request body, the entire body will be hidden.
0 commit comments