Skip to content

Commit e9aaf70

Browse files
authored
Add web prefix config to readme (#249)
1 parent ff3b310 commit e9aaf70

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,49 @@ A custom `dist` value will also be used as the build number.
127127

128128
If provided, the plugin will take your `release` and `dist` values without further mutating them. Make sure you configure everything as outlined in the [release docs](https://docs.sentry.io/product/cli/releases/) of `sentry-cli`.
129129

130+
## Web
131+
132+
If you're publishing your app on the web and it's not deployed at the root of your URL, you need to configure a `prefix` and update your stack frames.
133+
134+
Add the prefix to your `pubspec.yaml` in addition to your other configurations. Make sure that you have `upload_source_maps` enabled:
135+
136+
```properties
137+
sentry:
138+
upload_source_maps=true
139+
prefix: ~/your_prefix/
140+
```
141+
142+
The absolute path of your stack frames also needs to include the same prefix so that the source maps can be found for deobfuscation. Below is an example of how to update the stack frame's absolute path to include the prefix using the `beforeSend` hook:
143+
144+
```dart
145+
options.beforeSend = (event, hint) async {
146+
final exceptions = event.exceptions?.map((exception) {
147+
final stackTrace = exception.stackTrace;
148+
if (stackTrace != null) {
149+
final frames = stackTrace.frames.map((frame) {
150+
const baseUrl = 'https://your-domain.com/';
151+
final modifiedAbsPath = frame.absPath?.replaceFirst(
152+
baseUrl,
153+
'${baseUrl}your_prefix/',
154+
);
155+
return frame.copyWith(absPath: modifiedAbsPath);
156+
}).toList();
157+
return exception.copyWith(
158+
stackTrace: SentryStackTrace(frames: frames),
159+
);
160+
}
161+
return exception;
162+
}).toList();
163+
return event.copyWith(exceptions: exceptions ?? []);
164+
};
165+
```
166+
167+
Don't forget to specify the prefix path when building for the web and also build with `--source-maps`:
168+
169+
```bash
170+
flutter build web --base-href=/your_prefix/ --source-maps
171+
```
172+
130173
## Troubleshooting
131174

132175
Sentry's `auth_token` requires the `project:releases` or `project:write` scope, See [docs](https://docs.sentry.io/product/cli/dif/#permissions).

0 commit comments

Comments
 (0)