Skip to content

Commit

Permalink
docs(flutter): Add Rewrite Frames documentation (#10470)
Browse files Browse the repository at this point in the history
* docs(flutter): Add  documentation

* style updates
  • Loading branch information
denrase authored Jun 25, 2024
1 parent e69598d commit bf081f2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/platforms/flutter/configuration/draining.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Shutdown and Draining
sidebar_order: 70
sidebar_order: 80
description: "Learn more about the default behavior of our SDK if the application shuts down unexpectedly."
---

Expand Down
32 changes: 32 additions & 0 deletions docs/platforms/flutter/configuration/rewriteframes.mdx
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 ?? []);
};
```

0 comments on commit bf081f2

Please sign in to comment.