-
Notifications
You must be signed in to change notification settings - Fork 12
/
RollbarDemoApp.swift
91 lines (72 loc) · 3.45 KB
/
RollbarDemoApp.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import SwiftUI
import RollbarNotifier
@main
struct RollbarDemoApp: App {
@AppStorage("rollbar_endpoint") var endpoint = "https://api.rollbar.com/api/1/item/"
@AppStorage("rollbar_post_client_item_access_token") var accessToken = ""
init() {
// Dynamically read these settings from your config settings on application startup.
let accessToken = self.accessToken // Rollbar post_client_item access token
let environment = "staging"
let codeVersion = "main" // Ideally codeVersion is commit SHA https://docs.rollbar.com/docs/versions
// Initialize a configuration object and add configuration settings as needed.
let config = RollbarConfig.mutableConfig(
withAccessToken: accessToken,
environment: environment)
// The config endpoint already defaults to `api.rollbar.com` so setting it is unnecessary.
// This is an implementation detail of this application and should very rarely be needed.
config.destination.endpoint = endpoint
config.loggingOptions.codeVersion = codeVersion
// Optionally defined whether rate limited occurrences should be dropped or
// kept in a queue. Defaults to drop.
config.loggingOptions.rateLimitBehavior = .drop // or .queue
// Optionally anonymize the IP address
//config.loggingOptions.captureIp = RollbarCaptureIpType.anonymize
// Suppress internal Rollbar logging. Defaults to true.
config.developerOptions.suppressSdkInfoLogging = false
config.telemetry.enabled = true
config.telemetry.captureLog = true
config.telemetry.maximumTelemetryData = 10
config.modifyRollbarData = Rollbar.transform(payload:)
// Optionally don't send certain occurrences based on some aspect of
// the payload contents
//config.checkIgnoreRollbarData = Rollbar.shouldIgnore(payload:)
// List of fields to scrub
// Make sure to test this if you are overriding the default scrub list
//config.dataScrubber.scrubFields = ["accessToken", "cpu", "key_y"]
// optionally add data about the user to improve error response
config.person.id = "12345"
// additional custom data to add to every occurrence sent
config.customData = ["customer_type": "enterprise"]
// Initialize a Rollbar shared instance with a crash collector
Rollbar.initWithConfiguration(config)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
extension Rollbar {
/// `return true` means DO NOT send the data to Rollbar (i.e. ignore)
/// `return false` means DO send the data to Rollbar
static func shouldIgnore(payload: RollbarData) -> Bool {
return false
}
/// Transform the occurrence payload just before the data is sent.
///
/// This allows data to be added/removed from the payload basd on some
/// aspect of the payload data.
///
/// This method is often used to do advanced data scrubbing or to add
/// additional data to the payload that is only available at the time
/// the error occurs.
static func transform(payload: RollbarData) -> RollbarData {
// Context is an indexed fast search field in the Rollbar Web UI
//
// The items timeline view can be filtered by context
// https://docs.rollbar.com/docs/search-items#context
payload.context = "owner#ui_team"
return payload
}
}