Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rewrite frames integration #2111

Open
denrase opened this issue Jun 18, 2024 · 4 comments
Open

Add rewrite frames integration #2111

denrase opened this issue Jun 18, 2024 · 4 comments

Comments

@denrase
Copy link
Collaborator

denrase commented Jun 18, 2024

We could add a rewrite frames integration similar to javascript that allows users to manipulate the frames in a specific way before sending them off.

Examples of what it would solve

Relates to getsentry/sentry-dart-plugin#222

When users provide a urlPrefix with sentry-dart-plugin and sentry-cli, stack traces are not resolved correctly, as the path cant be found.

the stack trace abs path is "http://localhost: 8900/main.dart.
the uploaded file is ~/foo/main.dart -> doesn't match

so you would need to rewrite the abs_path to the uploaded file to include the prefix.

With a rewrite frame integration it would be easy to do that.

Alternatives

Use beforeSend code snippet

beforeSendCallback: (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);
});

Demand

Please upvote if you are interested in such an integration

@denrase
Copy link
Collaborator Author

denrase commented Jun 18, 2024

@buenaflor I created this issue as we only talked in Discord about this. Is this still correct and something we want to do?

@buenaflor
Copy link
Contributor

buenaflor commented Jun 19, 2024

Yep, the most simplest way is to tell users to modify the abs path of the stackframes in beforeSend to add the prefix themselves. or we can add an integration like javascript for rewriting frames which is syntactically nicer: https://docs.sentry.io/platforms/javascript/configuration/integrations/rewriteframes/

I think we're fine in just adding the guide to configure it like so :

beforeSendCallback: (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);
});

a specific rewrite frames integration is overkill for now

@buenaflor buenaflor changed the title Amend abs_path with urlPrefix Add rewrite frames integration Jun 20, 2024
@denrase
Copy link
Collaborator Author

denrase commented Jun 24, 2024

Added to docs: getsentry/sentry-docs#10470

We could also add the sample in the sentry-dart-plugin

@buenaflor
Copy link
Contributor

We could also add the sample in the sentry-dart-plugin

let's do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

2 participants