Skip to content

Commit 934f7f6

Browse files
committed
chore: update Bugsee integration documentation and event caputring method
1 parent e7cb678 commit 934f7f6

File tree

4 files changed

+157
-88
lines changed

4 files changed

+157
-88
lines changed

doc/Bugsee.md

Lines changed: 138 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,103 @@
1-
# Bugsee
2-
3-
This project include [Bugsee](https://www.bugsee.com/) reporting and Logging, for both Android and iOS apps.
4-
Bugsee lets you monitor and get instant log of unhandled exceptions with traces, events, stacktrace and videos/screenshots of the reported exception. More features are provided by Bugsee like data obscuration and log filter.
5-
6-
For this implementation we've used [bugsee_flutter](https://pub.dev/packages/bugsee_flutter) package.
7-
8-
- By default only release apps will have Bugsee reporting enabled, to enable Bugsee in debug mode add your token in `launch.json` add remove the check on debug mode in `BugseeManager` class.
9-
- **Token**
10-
- Generate your token in order to test Bugsee logging and reporting
11-
- Head to [Bugsee dashboard](https://www.bugsee.com/)
12-
- Create a new account
13-
- Create a new Android/iOS (choose Flutter framework)
14-
- Copy-paste the generated token into `launch.json`
15-
16-
17-
## 1) Features
18-
19-
In this project we've implemented the following features of Bugsee:
20-
- [Manual invocation](https://docs.bugsee.com/sdk/flutter/manual/) helpfull for developers to test their Bugsee integration and setup with new tokens.
21-
- [Custom data](https://docs.bugsee.com/sdk/flutter/custom/) custom data could be attached to the logged exceptions (emails or other type of data)
22-
- [Email](https://docs.bugsee.com/sdk/flutter/custom/#:~:text=Adding%20custom%20data-,User%20email,-When%20you%20already) this will identify the user whom experienced the exception/bug this will update the exception dashboard item from anonymous to the user's mail this data will be reported with every logged exception unless the app is deleted or removed manually.
23-
- [Attributes](https://docs.bugsee.com/sdk/flutter/custom/#:~:text=User/Session%20attributes) attributes related to the user info, will be reported with every logged exception unless the app is deleted or removed manually.
24-
- [Traces](https://docs.bugsee.com/sdk/flutter/custom/#:~:text=them%0ABugsee.clearAllAttributes()%3B-,Custom%20traces,-Traces%20may%20be) helpfull when developer want to track the change of specific value before the logging of the exception.
25-
- [Events](https://docs.bugsee.com/sdk/flutter/custom/#:~:text=Custom%20events-,Events,-are%20identified%20by) highlight on which event the exception is logged, accept also json data attached to it.
26-
- [Exception Logging](https://docs.bugsee.com/sdk/flutter/logs/) the app automatically log every unhandled exception: Dart SDK exception are related to data or logic errors and Flutter SDK errors that are related to layout and rendering issues. The implementation also offer an API to manually log an exception with traces and events.
27-
- [Video Capturing](https://docs.bugsee.com/sdk/flutter/privacy/video/) video capturing is by default enabled in this project, but it can be turned off using the `videoEnabled` flag in the launchOptions object for Android and iOS.
28-
- [Log reporting](https://docs.bugsee.com/sdk/flutter/privacy/logs/) all logs are filtered by default using the `_filterBugseeLogs` method, this can be turned off from the app or by removing the call to `setLogFilter` Bugsee method.
29-
- [Obscure Data](https://docs.bugsee.com/sdk/flutter/privacy/video/#:~:text=Protecting%20flutter%20views): data obscuration is by default enabled in the project in order to protect user-related data from being leaked through captured videos.
30-
31-
**Default configurations:**
32-
Data obscuration, log collection, log filter and attaching log file features are initialized from the `.env.staging` file.
33-
```
34-
BUGSEE_IS_DATA_OBSCURE=true
35-
BUGSEE_DISABLE_LOG_COLLECTION=true
36-
BUGSEE_FILTER_LOG_COLLECTION=false
37-
BUGSEE_ATTACH_LOG_FILE=true
1+
# Bugsee Integration Documentation
2+
3+
This document provides a comprehensive guide to integrating and using **Bugsee** in your mobile application. Bugsee is a powerful tool for monitoring and debugging your app by capturing and reporting unhandled exceptions, providing insights into app crashes, user interactions, and more.
4+
5+
## **Overview**
6+
7+
**Bugsee** helps developers quickly identify and troubleshoot crashes, bugs, and performance issues in mobile applications. By integrating Bugsee, developers can capture detailed logs, screen recordings, and contextual data (such as user attributes) to understand and fix issues faster.
8+
9+
---
10+
11+
## **Features**
12+
13+
This implementation of Bugsee leverages the following features to provide robust exception tracking and reporting:
14+
15+
### 1. **Manual Invocation**
16+
- Developers can trigger Bugsee for testing purposes or to verify the integration. You can also use different tokens for testing in different environments.
17+
- Documentation: [Bugsee SDK Docs](https://docs.bugsee.com/)
18+
19+
### 2. **Custom Data Reporting**
20+
- Add additional user-specific data (like email addresses) or custom attributes to exception reports for better context.
21+
- **Email:** Helps identify the specific user experiencing issues.
22+
- **Attributes:** Attach custom key-value pairs for further context.
23+
- **Traces:** Track specific values or conditions before an exception occurs.
24+
- **Events:** Log events leading to exceptions and attach structured JSON data for detailed insights.
25+
- Documentation: [Bugsee Custom Data](https://docs.bugsee.com/)
26+
27+
### 3. **Exception Logging**
28+
- Bugsee automatically captures unhandled exceptions in your Dart and Flutter code.
29+
- **Dart Exceptions:** Captures logic and data errors.
30+
- **Flutter Exceptions:** Captures rendering and layout errors.
31+
- You can also manually log exceptions with additional context, such as traces and events.
32+
- Documentation: [Bugsee Exception Logging](https://bugsee.com/)
33+
34+
### 4. **Video Capture**
35+
- Bugsee automatically captures screen recordings of user interactions that lead to exceptions. This helps developers visually understand what the user was doing when the issue occurred.
36+
- You can disable video capture by setting the `videoEnabled` flag.
37+
- Documentation: [Bugsee Flutter Installation](https://docs.bugsee.com/sdk/flutter/installation/)
38+
39+
### 5. **Log Reporting and Filtering**
40+
- Bugsee integrates with your app’s logging system. By default, logs are filtered to remove sensitive information to protect user privacy.
41+
- You can customize log collection behavior using configuration options.
42+
- Documentation: [Bugsee Log Reporting](https://docs.bugsee.com/sdk/flutter/installation/)
43+
44+
### 6. **Data Obfuscation**
45+
- Sensitive user data (like passwords or personal information) in captured videos is automatically obscured by default to prevent leaks.
46+
- Documentation: [Bugsee Data Obscuration](https://docs.bugsee.com/sdk/flutter/installation/)
47+
48+
---
49+
50+
## **Default Configurations**
51+
52+
Bugsee’s behavior can be controlled via environment settings, particularly for data obscuration, log collection, and file attachment. The default configurations are defined in the `.env.staging` file as follows:
53+
54+
```env
55+
BUGSEE_IS_DATA_OBSCURE=true # Enables data obscuration for captured videos
56+
BUGSEE_DISABLE_LOG_COLLECTION=true # Disables log collection by default
57+
BUGSEE_FILTER_LOG_COLLECTION=false # Allows all logs unless manually filtered
58+
BUGSEE_ATTACH_LOG_FILE=true # Attaches log files with Bugsee reports
3859
```
3960

40-
## 2) Implementation
41-
- [Bugsee Manager](../src/app/lib/business/bugsee/bugsee_manager.dart): a service class that handle the Bugsee intialization, capturing logs, customize Bugsee fields and features (Video capture, data obscure, logs filter...) .
42-
- [Bugsee Config State](../src/app/lib/business/bugsee/bugsee_config_state.dart): a state class holds all the actual Bugsee features status (whether enabled or not).
43-
- [Bugsee Repository](../src/app/lib/access/bugsee/bugsee_repository.dart): save and retrieve Bugsee configuration from the shared preference storage.
44-
- [Bugsee saved configuration](../src/app/lib/access/bugsee/bugsee_configuration_data.dart): holds the Bugsee saved configuration in shared preference, used in [Bugsee Manager](../src/app/lib/business/bugsee/bugsee_manager.dart) to initialize [Bugsee Config State](../src/app/lib/business/bugsee/bugsee_config_state.dart).
61+
Ensure that these values are properly set for different environments (e.g., staging, production).
62+
63+
---
64+
65+
## **Implementation Details**
66+
67+
The Bugsee integration consists of several key components for handling configuration, exception tracking, and reporting.
68+
69+
### 1. **[Bugsee Manager](../src/app/lib/business/bugsee/bugsee_manager.dart)**
70+
- Responsible for initializing Bugsee, capturing logs, and configuring Bugsee features (like video capture, data obfuscation, and log filtering).
71+
72+
### 2. **[Bugsee Config State](../src/app/lib/business/bugsee/bugsee_config_state.dart)**
73+
- Maintains the current state of Bugsee’s features (enabled/disabled) within the app.
74+
75+
### 3. **[Bugsee Repository](../src/app/lib/access/bugsee/bugsee_repository.dart)**
76+
- Handles the saving and retrieving of Bugsee configurations from shared preferences.
77+
78+
### 4. **[Bugsee Saved Configuration](../src/app/lib/access/bugsee/bugsee_configuration_data.dart)**
79+
- Stores and manages the saved configurations used to initialize Bugsee upon app launch.
4580

46-
### Intecepting exceptions
47-
Bugsee implementation in this project, by default intecepts all the unhandled Dart and Flutter exception.
81+
---
82+
83+
## **Exception Handling and Reporting**
84+
85+
### Intercepting Exceptions
86+
By default, Bugsee intercepts all unhandled Dart and Flutter exceptions globally:
87+
88+
1. **Dart Exceptions**:
89+
- These are data or logic errors that happen within your Dart code.
90+
91+
2. **Flutter Exceptions**:
92+
- These occur during layout or rendering issues.
93+
94+
Both types of exceptions are captured and reported to Bugsee’s dashboard.
95+
96+
The exceptions are intercepted using `runZonedGuarded` and `FlutterError.onError`:
4897

49-
`main.dart`
5098
```dart
99+
// main.dart
100+
51101
runZonedGuarded(
52102
() async {
53103
FlutterError.onError =
@@ -58,11 +108,9 @@ runZonedGuarded(
58108
},
59109
GetIt.I.get<BugseeManager>().inteceptExceptions,
60110
);
61-
```
62-
the `inteceptExceptions` and `inteceptRenderExceptions` recerespectively report Dart and Flutter exceptions to the Bugsee Dashboard.
63111
64-
`inteceptExceptions`
65-
```dart
112+
// bugsee_manager.dart
113+
66114
@override
67115
Future<void> inteceptExceptions(
68116
Object error,
@@ -80,11 +128,8 @@ the `inteceptExceptions` and `inteceptRenderExceptions` recerespectively report
80128
},
81129
);
82130
}
83-
```
84131
85-
`inteceptRenderExceptions`
86-
```dart
87-
@override
132+
@override
88133
Future<void> inteceptRenderExceptions(FlutterErrorDetails error) async {
89134
await logException(
90135
exception: Exception(error.exception),
@@ -93,49 +138,69 @@ the `inteceptExceptions` and `inteceptRenderExceptions` recerespectively report
93138
}
94139
```
95140

96-
### Manually invoke report dialog
141+
### **Manually Reporting Issues**
97142

98-
To manually display the report dialog, you call the `showCaptureLogReport` method from the `BugseeManager` class.
143+
You can manually trigger Bugsee to capture logs and display a report dialog using the `showCaptureLogReport` method:
99144

100145
```dart
101146
final bugseeManager = Get.I.get<BugseeManager>();
102-
bugseeManger.showCaptureLogReport();
147+
bugseeManager.showCaptureLogReport();
103148
```
104149

150+
This is useful for debugging specific scenarios or reporting custom issues.
105151

106-
### Manually log an exception
152+
### **Manually Logging Exceptions**
107153

108-
To manually log an exception, you call the `logException` method from the `BugseeManager` class. You can add traces and events to the reported exception.
154+
To manually log an exception (with or without additional traces), use the `logException` method:
109155

110156
```dart
111157
final bugseeManager = Get.I.get<BugseeManager>();
112-
bugseeManger.logException(exception: Exception());
158+
bugseeManager.logException(exception: Exception("Custom error"));
113159
```
114160

161+
You can add additional context **traces**:
115162

116-
### Add attributes
163+
```dart
164+
bugseeManager.logException(
165+
exception: Exception("Custom error"),
166+
traces: ["Trace 1", "Trace 2"], // Add relevant traces
167+
);
168+
```
169+
170+
### **Adding User Attributes**
117171

118-
To attach the user's email to the logged exception use `addEmailAttribute` method and to clear this attribute you can use `clearEmailAttribute`.
172+
To provide more context about the user experiencing the issue, you can add custom attributes such as an email address:
173+
174+
- **Add Email Attribute**:
119175

120176
```dart
121177
final bugseeManager = Get.I.get<BugseeManager>();
122-
bugseeManger.addEmailAttribute("johndoe@nventive.com");
123-
//some other code..
124-
bugseeManger.clearEmailAttribute();
178+
bugseeManager.addEmailAttribute("johndoe@nventive.com");
125179
```
126180

127-
for other attributes you can use `addAttributes` with a map where key is the attribute name and value is the attribute value. To clear these attributes use `clearAttribute` and pass the attribute name to it.
181+
- **Clear Email Attribute**:
128182

129183
```dart
130-
final bugseeManager = Get.I.get<BugseeManager>();
131-
bugseeManger.addAttributes({
132-
'name': 'john',
133-
'age': 45,
184+
bugseeManager.clearEmailAttribute();
185+
```
186+
187+
- **Add Custom Attributes**:
188+
189+
You can also add custom key-value pairs as additional attributes to enrich the exception reports:
190+
191+
```dart
192+
bugseeManager.addAttributes({
193+
"userType": "premium",
194+
"accountStatus": "active"
134195
});
135-
//some other code..
136-
bugseeManger.clearAttribute('name');
137196
```
138197

139-
## 3) Deployment
198+
## **Additional Resources**
199+
200+
- [Bugsee SDK Documentation](https://docs.bugsee.com/)
201+
- [Bugsee Flutter Installation Guide](https://docs.bugsee.com/sdk/flutter/installation/)
202+
- [bugsee_flutter package](https://pub.dev/packages/bugsee_flutter)
203+
- [Handling Flutter errors](https://docs.flutter.dev/testing/errors)
204+
- [runZoneGuarded Error handling](https://api.flutter.dev/flutter/dart-async/runZonedGuarded.html)
140205

141-
The Bugsee token is injected directly in the azure devops pipeline when building the Android/iOS app for release mode in the [Android Build Job](../build/steps-build-android.yml) and [iOS Build Job](../build/steps-build-ios.yml) under the `multiDartDefine` parameter.
206+
---

src/app/lib/business/bugsee/bugsee_manager.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ abstract interface class BugseeManager {
4545
required Exception exception,
4646
StackTrace? stackTrace,
4747
Map<String, dynamic> traces,
48-
Map<String, Map<String, dynamic>?> events,
4948
});
5049

5150
/// Manually update the current BugseeEnabled flag in shared prefs and in current manager singleton.
@@ -76,7 +75,7 @@ abstract interface class BugseeManager {
7675
Future<void> inteceptExceptions(Object error, StackTrace stackTrace);
7776

7877
/// Intercept all unhandled rending exception thrown by the Flutter framework
79-
Future<void> inteceptRenderExceptions(FlutterErrorDetails error);
78+
Future<void> inteceptRenderingExceptions(FlutterErrorDetails error);
8079

8180
/// Manually add a map of attributes
8281
/// - the map entry key is the attribute name
@@ -97,6 +96,9 @@ abstract interface class BugseeManager {
9796

9897
/// Manually remove an attribute by the given key attached using [addAttributes]
9998
Future<void> clearAttribute(String attribute);
99+
100+
/// Manually log Bugsee events that will be attached to the reported issues
101+
void logEvents(Map<String, Map<String, dynamic>> events);
100102
}
101103

102104
final class _BugseeManager implements BugseeManager {
@@ -260,15 +262,11 @@ final class _BugseeManager implements BugseeManager {
260262
required Exception exception,
261263
StackTrace? stackTrace,
262264
Map<String, dynamic> traces = const {},
263-
Map<String, Map<String, dynamic>?> events = const {},
264265
}) async {
265266
if (_currentState.isBugseeEnabled) {
266267
for (var trace in traces.entries) {
267268
await Bugsee.trace(trace.key, trace.value);
268269
}
269-
for (var event in events.entries) {
270-
await Bugsee.event(event.key, event.value);
271-
}
272270
await Bugsee.logException(exception, stackTrace);
273271
}
274272
}
@@ -404,10 +402,17 @@ final class _BugseeManager implements BugseeManager {
404402
}
405403

406404
@override
407-
Future<void> inteceptRenderExceptions(FlutterErrorDetails error) async {
405+
Future<void> inteceptRenderingExceptions(FlutterErrorDetails error) async {
408406
await logException(
409407
exception: Exception(error.exception),
410408
stackTrace: error.stack,
411409
);
412410
}
411+
412+
@override
413+
void logEvents(Map<String, Map<String, dynamic>> events) async {
414+
for (var event in events.entries) {
415+
Bugsee.event(event.key, event.value);
416+
}
417+
}
413418
}

src/app/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Future<void> main() async {
4141
runZonedGuarded(
4242
() async {
4343
FlutterError.onError =
44-
GetIt.I.get<BugseeManager>().inteceptRenderExceptions;
44+
GetIt.I.get<BugseeManager>().inteceptRenderingExceptions;
4545
await initializeComponents();
4646
await registerBugseeManager();
4747
runApp(const App());

src/app/lib/presentation/diagnostic/bugsee_configuration_widget.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class _BugseeConfigurationWidgetState extends State<BugseeConfigurationWidget> {
8989
},
9090
),
9191
DiagnosticSwitch(
92-
label: 'Enabling log collection',
92+
label: 'Log collection enabled',
9393
value: state.isLogCollectionEnabled,
9494
onChanged: (value) async {
9595
await bugseeManager.setIsLogsCollectionEnabled(value);
@@ -99,7 +99,7 @@ class _BugseeConfigurationWidgetState extends State<BugseeConfigurationWidget> {
9999
},
100100
),
101101
DiagnosticSwitch(
102-
label: 'Enable log filter',
102+
label: 'Filter log enabled',
103103
value: state.isLogFilterEnabled,
104104
onChanged: (value) async {
105105
await bugseeManager.setIsLogFilterEnabeld(value);
@@ -109,7 +109,7 @@ class _BugseeConfigurationWidgetState extends State<BugseeConfigurationWidget> {
109109
},
110110
),
111111
DiagnosticSwitch(
112-
label: 'Attach log file',
112+
label: 'Log file attached',
113113
value: state.attachLogFile,
114114
onChanged: (value) async {
115115
bugseeManager.setAttachLogFileEnabled(value);
@@ -127,11 +127,10 @@ class _BugseeConfigurationWidgetState extends State<BugseeConfigurationWidget> {
127127
},
128128
),
129129
DiagnosticButton(
130-
label: 'Log Exception with events',
130+
label: 'Add events to the exception',
131131
onPressed: () {
132-
bugseeManager.logException(
133-
exception: Exception(),
134-
events: {
132+
bugseeManager.logEvents(
133+
{
135134
'data': {
136135
'date': DateTime.now().millisecondsSinceEpoch,
137136
'id': Random().nextInt(20),

0 commit comments

Comments
 (0)