-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(flutter): Add
Rewrite Frames
documentation (#10470)
* docs(flutter): Add documentation * style updates
- Loading branch information
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
title: Rewrite Frames | ||
sidebar_order: 70 | ||
description: "Learn how and why to rewrite stack trace frames in Sentry's flutter SDK." | ||
--- | ||
|
||
There are times when you may want to rewrite stack trace frames before sending them to Sentry. For example, if you're publishing your Flutter application on the web and want to set a `url_prefix` because it's not deployed at the root of your URL. In this case, the absolute path of your stack frames also needs to include the same prefix so that the source maps can be found for deobfuscation. | ||
|
||
To set the `url_prefix`, use the [Sentry Dart Plugin](https://github.com/getsentry/sentry-dart-plugin). Below is an example of how to update the stack frame's absolute path to include the prefix using the <PlatformLink to="/configuration/options/#before-send"><PlatformIdentifier name="before-send" /></PlatformLink> hook. | ||
|
||
```dart | ||
options.beforeSend = (event, hint) async { | ||
final exceptions = event.exceptions?.map((exception) { | ||
final stackTrace = exception.stackTrace; | ||
if (stackTrace != null) { | ||
final frames = stackTrace.frames.map((frame) { | ||
const baseUrl = 'https://example.com/'; | ||
final modifiedAbsPath = frame.absPath?.replaceFirst( | ||
baseUrl, | ||
'${baseUrl}my_prefix/', | ||
); | ||
return frame.copyWith(absPath: modifiedAbsPath); | ||
}).toList(); | ||
return exception.copyWith( | ||
stackTrace: SentryStackTrace(frames: frames), | ||
); | ||
} | ||
return exception; | ||
}).toList(); | ||
return event.copyWith(exceptions: exceptions ?? []); | ||
}; | ||
``` |