Skip to content

Commit 1e5059f

Browse files
authored
Documentation update (#25)
* Add comments in public definitions * Add table of contents to `README.md` * Rename `userAttributes` to `attributes` * Update example projects * Update Backtrace.podspec
1 parent 2f449f9 commit 1e5059f

File tree

15 files changed

+118
-69
lines changed

15 files changed

+118
-69
lines changed

Backtrace.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Pod::Spec.new do |s|
1010

1111
s.name = "Backtrace"
12-
s.version = "1.4.0"
12+
s.version = "1.4.1"
1313
s.summary = "Backtrace's integration with iOS and macOS"
1414
s.description = "Backtrace's integration with iOS and macOS for handling crashes"
1515
s.homepage = "https://backtrace.io/"

Example-iOS/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3232

3333
BacktraceClient.shared = try? BacktraceClient(configuration: backtraceConfiguration)
3434
BacktraceClient.shared?.delegate = self
35-
BacktraceClient.shared?.userAttributes = ["foo": "bar", "testing": true]
35+
BacktraceClient.shared?.attributes = ["foo": "bar", "testing": true]
3636

3737
do {
3838
try throwingFunc()

Example-macOS-ObjC/AppDelegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
2626
reportsPerMin: 3
2727
allowsAttachingDebugger: TRUE];
2828
BacktraceClient.shared = [[BacktraceClient alloc] initWithConfiguration: configuration error: nil];
29-
[BacktraceClient.shared setUserAttributes: @{@"foo": @"bar"}];
29+
[BacktraceClient.shared setAttributes: @{@"foo": @"bar"}];
3030
BacktraceClient.shared.delegate = self;
3131

3232
@try {

README.md

Lines changed: 62 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,32 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
7777

7878
}
7979

80-
//sending NSError
81-
NSError *error = [NSError errorWithDomain: @"backtrace.domain" code: 100 userInfo: @{}];
82-
[[BacktraceClient shared] sendWithCompletion:^(BacktraceResult * _Nonnull result) {
83-
NSLog(@"%@", result);
84-
}];
85-
8680
return YES;
8781
}
8882

8983
@end
9084
```
9185
86+
# Table of contents
87+
1. [Features Summary](#features-summary)
88+
2. [Installation](#installation)
89+
* [Cocoapods](#installation-cocoapods)
90+
3. [Documentation](#documentation)
91+
1. [Initialize client](#documentation-client-initialization)
92+
2. [Configure client](#documentation-client-configuration)
93+
* [Database settings](#documentation-database-settings)
94+
3. [Events handling](#documentation-events-handling)
95+
4. [Attributes](#documentation-attributes)
96+
5. [Attachments](#documentation-attachments)
97+
6. [Sending reports](#documentation-sending-report)
98+
1. [Error/NSError](#documentation-sending-error)
99+
2. [NSException](#documentation-sending-exception)
100+
3. [macOS note](#documentatio-sending-report-macOS)
101+
4. [FAQ](#faq)
102+
1. [Missing dSYM files](#faq-missing-dsym)
103+
* [Finding dSYMs while building project](#faq-finding-dsym-building)
104+
* [Finding dSYMs while archiving project](#faq-finding-dsym-archiving)
105+
92106
# Features Summary <a name="features-summary"></a>
93107
* Light-weight client library written in Swift with full Objective-C support that quickly submits exceptions/errors and crashes to your Backtrace dashboard includes:
94108
* system metadata,
@@ -102,7 +116,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
102116
103117
# Installation <a name="installation"></a>
104118
105-
## via CocoaPods
119+
## via CocoaPods <a name="installation-cocoapods"></a>
106120
107121
To use [CocoaPods](https://cocoapods.org) just add this to your Podfile:
108122
@@ -112,11 +126,10 @@ pod 'Backtrace'
112126
113127
**Note:** It is required to specify `use_frameworks!` in your Podfile.
114128
115-
# Documentation <a name="documentation"></a>
116-
117-
## Register with Backtrace credentials<a name="documentation-initialization"></a>
129+
# Documentation <a name="documentation"></a>
118130
119-
Register to Backtrace services using provided submission url (see: <a href="https://help.backtrace.io/troubleshooting/what-is-a-submission-url">What is a submission url?</a>) and token (see: <a href="https://help.backtrace.io/troubleshooting/what-is-a-submission-token">What is a submission token?</a>).
131+
## Initialize Backtrace client <a name="documentation-client-initialization"></a>
132+
Initializing Backtrace clinet requires registration to Backtrace services. You can register to Backtrace services using provided submission url (see: <a href="https://help.backtrace.io/troubleshooting/what-is-a-submission-url">What is a submission url?</a>) and token (see: <a href="https://help.backtrace.io/troubleshooting/what-is-a-submission-token">What is a submission token?</a>). These credentials you can supply using `BacktraceCredentials`.
120133
121134
- Swift
122135
```swift
@@ -127,8 +140,8 @@ BacktraceClient.shared = try? BacktraceClient(credentials: BacktraceCredentials)
127140
BacktraceClient.shared = [[BacktraceClient alloc] initWithCredentials: BacktraceCredentials error: error];
128141
```
129142
130-
## Backtrace client configuration
131-
For more advanced usage of BacktraceClient, you can supply BacktraceClientConfiguration as a parameter. See the following example:
143+
## Configure Backtrace client <a name="documentation-client-configuration"></a>
144+
For more advanced usage of `BacktraceClient`, you can supply `BacktraceClientConfiguration` as a parameter. See the following example:
132145
- Swift
133146
```swift
134147
let backtraceCredentials = BacktraceCredentials(endpoint: URL(string: "https://backtrace.io")!, token: "token")
@@ -156,7 +169,7 @@ BacktraceClient.shared = [[BacktraceClient alloc] initWithConfiguration: configu
156169
157170
**Note:** Backtrace library will *not* send any reports if the `allowsAttachingDebugger` flag is set to `false`.
158171
159-
### Database settings
172+
### Database settings <a name="documentation-database-settings"></a>
160173
BacktraceClient allows you to customize the initialization of BacktraceDatabase for local storage of error reports by supplying a BacktraceDatabaseSettings parameter, as follows:
161174
162175
- Swift
@@ -198,8 +211,8 @@ BacktraceClientConfiguration *configuration = [[BacktraceClientConfiguration all
198211
BacktraceClient.shared = [[BacktraceClient alloc] initWithConfiguration: configuration error: nil];
199212
```
200213
201-
### Events handling
202-
`BacktraceClient` allows you to subscribe for events produced before and after sending each report.
214+
## Events handling <a name="documentation-events-handling"></a>
215+
`BacktraceClient` allows you to subscribe for events produced before and after sending each report. You have to only attach object which confirm to `BacktraceClientDelegate` protocol.
203216
- Swift
204217
```swift
205218
// assign `self` or any other object as a `BacktraceClientDelegate`
@@ -225,20 +238,38 @@ BacktraceClient.shared.delegate = self;
225238
- (NSURLRequest *)willSendRequest:(NSURLRequest *)request;
226239
- (void)didReachLimit:(BacktraceResult *)result;
227240
```
241+
Attaching `BacktraceClientDelegate` allows you to e.g. modify report before send:
242+
- Swift
243+
```swift
244+
func willSend(_ report: BacktraceReport) -> (BacktraceReport) {
245+
report.attributes["added"] = "just before send"
246+
return report
247+
}
248+
```
249+
- Objctive-C
250+
```objective-c
251+
- (BacktraceReport *)willSend:(BacktraceReport *)report {
252+
NSMutableDictionary *dict = [report.attributes mutableCopy];
253+
[dict setObject: @"just before send" forKey: @"added"];
254+
report.attributes = dict;
255+
return report;
256+
}
257+
```
228258

229-
### User attributes
230-
You can add custom user attributes that should be send alongside crash and erros/exceptions:
259+
## Attributes <a name="documentation-attributes"></a>
260+
You can add custom attributes that should be send alongside crash and erros/exceptions:
231261
- Swift
232262
```swift
233-
BacktraceClient.shared?.userAttributes = ["foo": "bar", "testing": true]
263+
BacktraceClient.shared?.attributes = ["foo": "bar", "testing": true]
234264
```
235265

236266
- Objective-C
237267
```objective-c
238-
BacktraceClient.shared.userAttributes = @{@"foo": @"bar", @"testing": YES};
268+
BacktraceClient.shared.attributes = @{@"foo": @"bar", @"testing": YES};
239269
```
270+
Set attributes are attached to each report. You can specify unique set of attributes for specific report in `willSend(_:)` method of `BacktraceClientDelegate`. See [events handling](#documentation-events-handling) for more information.
240271
241-
### Attachments
272+
## Attachments <a name="documentation-attachments"></a>
242273
For each report you can attach files by supplying an array of file paths.
243274
- Swift
244275
```swift
@@ -254,11 +285,12 @@ NSArray *paths = @[[[NSBundle mainBundle] pathForResource: @"test" ofType: @"txt
254285
NSLog(@"%@", result);
255286
}];
256287
```
288+
Supplied files are attached for each report. You can specify unique set of files for specific report in `willSend(_:)` method of `BacktraceClientDelegate`. See [events handling](#documentation-events-handling) for more information.
257289
258290
## Sending an error report <a name="documentation-sending-report"></a>
259291
Registered `BacktraceClient` will be able to send an crash reports. Error report is automatically generated based.
260292
261-
### Sending `Error/NSError`
293+
### Sending `Error/NSError` <a name="documentation-sending-error"></a>
262294
- Swift
263295
```swift
264296
@objc func send(completion: ((BacktraceResult) -> Void))
@@ -268,7 +300,7 @@ Registered `BacktraceClient` will be able to send an crash reports. Error report
268300
- (void) sendWithCompletion: (void (^)(BacktraceResult * _Nonnull)) completion;
269301
```
270302

271-
### Sending `NSException`
303+
### Sending `NSException` <a name="documentation-sending-exception"></a>
272304
- Swift
273305
```swift
274306
@objc func send(exception: NSException, completion: ((BacktraceResult) -> Void))
@@ -278,36 +310,36 @@ Registered `BacktraceClient` will be able to send an crash reports. Error report
278310
- (void) sendWithException: NSException completion: (void (^)(BacktraceResult * _Nonnull)) completion;
279311
```
280312

281-
### macOS note
313+
### macOS note <a name="documentatio-sending-report-macOS"></a>
282314
If you want to catch additional exceptions on macOS which are not forwarded by macOS runtime, set `NSPrincipalClass` to `Backtrace.BacktraceCrashExceptionApplication` in your `Info.plist`.
283315

284316
Alternatively, you can set:
285-
- Swift
317+
- Swift
286318
```swift
287319
UserDefaults.standard.register(defaults: ["NSApplicationCrashOnExceptions": true])
288320
```
289-
-Objective-C
321+
- Objective-C
290322
```objective-c
291323
[[NSUserDefaults standardUserDefaults] registerDefaults:@{ @"NSApplicationCrashOnExceptions": @YES }];
292324
```
293325
but it crashes your app if you don't use `@try ... @catch`.
294326
295-
# FAQ
296-
## Missing dSYM files
327+
# FAQ <a name="faq"></a>
328+
## Missing dSYM files <a name="faq-missing-dsym"></a>
297329
Make sure your project is configured to generate the debug symbols:
298330
* Go to your project target's build settings: `YourTarget -> Build Settings`.
299331
* Search for `Debug Information Format`.
300332
* Select `DWARF with dSYM File`.
301333
![alt text](https://github.com/backtrace-labs/backtrace-cocoa/blob/master/docs/screenshots/xcode-debug-information-format.png)
302334
303-
### Finding dSYMs while building project
335+
### Finding dSYMs while building project <a name="faq-finding-dsym-building"></a>
304336
* Build the project.
305337
* Build products and dSYMs are placed into the `Products` directory.
306338
![alt text](https://github.com/backtrace-labs/backtrace-cocoa/blob/master/docs/screenshots/xcode-products.png)
307339
![alt text](https://github.com/backtrace-labs/backtrace-cocoa/blob/master/docs/screenshots/finder-dsyms-products.png)
308340
* Zip all the `dSYM` files and upload to Backtrace services (see: <a href="https://help.backtrace.io/product-guide/symbolification">Symbolification</a>)
309341
310-
### Finding dSYMs while archiving project
342+
### Finding dSYMs while archiving project <a name="faq-finding-dsym-archiving"></a>
311343
* Archive the project.
312344
* dSYMs are placed inside of an `.xcarchive` of your project.
313345
* Open Xcode -> Window -> Organizer

Sources/Features/Attributes/AttributesProvider.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33
final class AttributesProvider {
44

55
// attributes can be modified on runtime
6-
var userAttributes: Attributes = [:]
6+
var attributes: Attributes = [:]
77

88
private let bluetoothStatusListener = BluetoothStatusListener()
99
private var faultMessage: String?
@@ -14,8 +14,8 @@ extension AttributesProvider: SignalContext {
1414
self.faultMessage = faultMessage
1515
}
1616

17-
var attributes: Attributes {
18-
return userAttributes + defaultAttributes
17+
var allAttributes: Attributes {
18+
return attributes + defaultAttributes
1919
}
2020

2121
var defaultAttributes: Attributes {
@@ -28,6 +28,6 @@ extension AttributesProvider: SignalContext {
2828

2929
extension AttributesProvider: CustomStringConvertible {
3030
var description: String {
31-
return attributes.compactMap { "\($0.key): \($0.value)"}.joined(separator: "\n")
31+
return allAttributes.compactMap { "\($0.key): \($0.value)"}.joined(separator: "\n")
3232
}
3333
}

Sources/Features/Client/BacktraceReporter.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ extension BacktraceReporter: BacktraceClientCustomizing {
5252
}
5353
}
5454

55-
var userAttributes: Attributes {
55+
var attributes: Attributes {
5656
get {
57-
return attributesProvider.userAttributes
57+
return attributesProvider.attributes
5858
} set {
59-
attributesProvider.userAttributes = newValue
59+
attributesProvider.attributes = newValue
6060
}
6161
}
6262
}
@@ -79,7 +79,7 @@ extension BacktraceReporter {
7979
faultMessage: String? = nil) throws -> BacktraceResult {
8080
attributesProvider.set(faultMessage: faultMessage)
8181
let resource = try reporter.generateLiveReport(exception: exception,
82-
attributes: attributesProvider.attributes,
82+
attributes: attributesProvider.allAttributes,
8383
attachmentPaths: attachmentPaths)
8484
return try send(resource: resource)
8585
}

Sources/Features/Crash Reporting/CrashReporter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension CrashReporter: CrashReporting {
2121
}
2222
BacktraceLogger.debug("Saving custom attributes:\n\(attributesProvider.description)")
2323
attributesProvider.set(faultMessage: "siginfo_t.si_signo: \(signalInfo.si_signo)")
24-
try? AttributesStorage.store(attributesProvider.attributes, fileName: CrashReporter.crashName)
24+
try? AttributesStorage.store(attributesProvider.allAttributes, fileName: CrashReporter.crashName)
2525
}
2626
var callbacks = PLCrashReporterCallbacks(version: 0, context: rawMutablePointer, handleSignal: handler)
2727
reporter.setCrash(&callbacks)

Sources/Features/Repository/Model/BacktraceReport.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import Foundation
22
import Backtrace_PLCrashReporter
33

4+
/// Model represents single crash report which can be send to Backtrace services.
45
@objc final public class BacktraceReport: NSObject {
56

7+
/// Encoded informations about report like stack trace etc.
68
@objc public let reportData: Data
9+
710
let plCrashReport: PLCrashReport
811
let identifier: UUID
12+
13+
/// Array of files paths attached to the report.
914
@objc public var attachmentPaths: [String]
15+
16+
/// `Attributes` attached to the report.
1017
@objc public var attributes: Attributes
1118

1219
init(report: Data, attributes: Attributes, attachmentPaths: [String]) throws {

Sources/Public/BacktraceClient.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ extension BacktraceClient: BacktraceClientCustomizing {
6363
}
6464
}
6565

66-
/// Additional user attributes which are automatically added to each report.
67-
@objc public var userAttributes: Attributes {
66+
/// Additional attributes which are automatically added to each report.
67+
@objc public var attributes: Attributes {
6868
get {
69-
return reporter.userAttributes
69+
return reporter.attributes
7070
}
7171
set {
72-
reporter.userAttributes = newValue
72+
reporter.attributes = newValue
7373
}
7474
}
7575
}

Sources/Public/BacktraceClientConfiguration.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,36 @@ import Foundation
33
/// Backtrace client configuration settings.
44
@objc public class BacktraceClientConfiguration: NSObject {
55

6-
/// Client's credentials.
6+
/// Client's credentials. To learn more about credentials, see
7+
/// https://help.backtrace.io/troubleshooting/what-is-a-submission-url
8+
/// and https://help.backtrace.io/troubleshooting/what-is-a-submission-token .
79
@objc public let credentials: BacktraceCredentials
810

911
/// Database settings
1012
@objc public var dbSettings: BacktraceDatabaseSettings = BacktraceDatabaseSettings()
1113

12-
/// Number of records sent in 1 minute. Default: 3.
14+
/// Number of records sent in 1 minute. Default `3`.
1315
@objc public var reportsPerMin: Int = 3
1416

15-
/// Flag indicating if the Backtrace client should raport reports when the debugger is attached.
17+
/// Flag indicating if the Backtrace client should raport reports when the debugger is attached. Default `false`.
1618
@objc public var allowsAttachingDebugger: Bool = false
1719

1820
/// Produces Backtrace client configuration settings.
21+
///
1922
/// - Parameters:
2023
/// - credentials: Backtrace server API credentials.
2124
@objc public init(credentials: BacktraceCredentials) {
2225
self.credentials = credentials
2326
}
2427

2528
/// Produces Backtrace client configuration settings.
29+
///
2630
/// - Parameters:
2731
/// - credentials: Backtrace server API credentials.
28-
/// - dbSettings: Backtrace database settings
29-
/// - reportsPerMin: Maximum number of records sent to Backtrace services in 1 minute. Default: 3
32+
/// - dbSettings: Backtrace database settings.
33+
/// - reportsPerMin: Maximum number of records sent to Backtrace services in 1 minute. Default: `3`.
3034
/// - allowsAttachingDebugger: if set to `true` BacktraceClient will report reports even when the debugger
31-
/// is attached. Default: `false`
35+
/// is attached. Default: `false`.
3236
@objc public init(credentials: BacktraceCredentials,
3337
dbSettings: BacktraceDatabaseSettings = BacktraceDatabaseSettings(),
3438
reportsPerMin: Int = 3,

0 commit comments

Comments
 (0)