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

Feature: Improve Dio exception reports #718

Merged
merged 33 commits into from
Feb 21, 2022
Merged

Conversation

ueman
Copy link
Collaborator

@ueman ueman commented Jan 26, 2022

📜 Description

Adds an event processor, which add chained exceptions for the inner exception of DioError,
see https://sentry.io/share/issue/638a3758a43d4f61bc2a0c62acdefd69/

This one should be merged after #728

💡 Motivation and Context

Fixes #715

💚 How did you test it?

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • I updated the docs if needed
  • All tests passing
  • No breaking changes

🔮 Next steps

flutter/example/lib/main.dart Outdated Show resolved Hide resolved
@kuhnroyal
Copy link
Contributor

I never get any DioError in the FailedRequestClient , the whole block here: https://github.com/flutterchina/dio/blob/develop/dio/lib/src/dio_mixin.dart#L620. is executed later.

@kuhnroyal
Copy link
Contributor

This works, I have the correct in-app grouping.

Copy link
Contributor

@kuhnroyal kuhnroyal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I basically copied this and and added some more code from FailedRequestClient in order to add a SentryRequest to the event. And I disabled the FailedRequestClient. This combination now gives me a pretty good result.
The only problem I see, is that the error is not tied to the transaction in any way.

dio/lib/src/dio_event_processor.dart Outdated Show resolved Hide resolved
dio/lib/src/dio_event_processor.dart Outdated Show resolved Hide resolved
@ueman
Copy link
Collaborator Author

ueman commented Jan 26, 2022

I basically copied this and and added some more code from FailedRequestClient in order to add a SentryRequest to the event. And I disabled the FailedRequestClient. This combination now gives me a pretty good result.

That's actually a pretty good idea.

The only problem I see, is that the error is not tied to the transaction in any way.

As this integration doesn't start any transactions, you basically have to write code like the one below anyway

  final transaction = Sentry.getSpan() ??
      Sentry.startTransaction(
        'dio-web-request',
        'request',
        bindToScope: true,
      );
  try {
    final response = await dio.get<String>('https://flutter.dev/');
    transaction.spanStatus = SpanStatus.ok();
  } catch (exception, stackTrace) {
    transaction.throwable = exception;
    transaction.spanStatus = SpanStatus.internalError();
    Sentry.captureException(exception, stacktrace);
  } finally {
    await transaction.finish();
  }

and then it is tied together.

@kuhnroyal
Copy link
Contributor

As this integration doesn't start any transactions, you basically have to write code like the one below anyway

True, it is all tied to my Flutter route transactions.

@codecov-commenter
Copy link

codecov-commenter commented Jan 26, 2022

Codecov Report

Merging #718 (43f2daa) into main (edc6acd) will increase coverage by 1.39%.
The diff coverage is 92.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #718      +/-   ##
==========================================
+ Coverage   90.53%   91.93%   +1.39%     
==========================================
  Files         104       18      -86     
  Lines        3328      533    -2795     
==========================================
- Hits         3013      490    -2523     
+ Misses        315       43     -272     
Impacted Files Coverage Δ
dio/lib/src/sentry_dio_extension.dart 81.81% <85.71%> (+1.81%) ⬆️
dio/lib/src/dio_event_processor.dart 93.18% <93.18%> (ø)
dio/lib/src/sentry_transformer.dart 94.44% <0.00%> (-5.56%) ⬇️
...art/lib/src/http_client/failed_request_client.dart
dart/lib/src/protocol/max_request_body_size.dart
dart/lib/src/protocol/sentry_stack_trace.dart
dart/lib/src/default_integrations.dart
dart/lib/src/protocol/debug_image.dart
dart/lib/src/protocol/sentry_runtime.dart
dart/lib/src/noop_sentry_span.dart
... and 80 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update edc6acd...43f2daa. Read the comment docs.

dio/lib/src/dio_event_processor.dart Outdated Show resolved Hide resolved
dart/lib/src/http_client/sentry_http_client.dart Outdated Show resolved Hide resolved
dio/lib/src/dio_event_processor.dart Outdated Show resolved Hide resolved
dio/lib/src/dio_event_processor.dart Outdated Show resolved Hide resolved
@kuhnroyal
Copy link
Contributor

When a description is set on the mechanism, the type is not shown in Sentry UI. Not sure why.

Bildschirmfoto 2022-01-27 um 10 56 09
Bildschirmfoto 2022-01-27 um 10 56 18

@ueman
Copy link
Collaborator Author

ueman commented Jan 27, 2022

When a description is set on the mechanism, the type is not shown in Sentry UI. Not sure why.

Bildschirmfoto 2022-01-27 um 10 56 09 Bildschirmfoto 2022-01-27 um 10 56 18

Yeah, that's also true for FlutterError which sometime have the description set.
I don't know whether that's working as expected or not. Maybe @marandaneto know.
Probably this is worth an issue at the Sentry repo itself.

@marandaneto
Copy link
Contributor

When a description is set on the mechanism, the type is not shown in Sentry UI. Not sure why.
Bildschirmfoto 2022-01-27 um 10 56 09 Bildschirmfoto 2022-01-27 um 10 56 18

Yeah, that's also true for FlutterError which sometime have the description set. I don't know whether that's working as expected or not. Maybe @marandaneto know. Probably this is worth an issue at the Sentry repo itself.

I agree, an issue there would be better, I don't know the answer either.

Comment on lines 48 to 51
if (innerDioErrorException.runtimeType == String) {
innerException =
innerException.copyWith(type: 'DioError inner stacktrace');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for not using it's type? String in this case.

@marandaneto
Copy link
Contributor

@ueman can you share a link of an issue after those changes or a screenshot? thanks.
Looks like this PR indeed makes it much better.
Logic wise LGTM, @brustolin please review :)

@ueman
Copy link
Collaborator Author

ueman commented Feb 12, 2022

await dio.get<String>('https://flutter.dev/asdfasg');, throws because 404 status code: https://sentry.io/organizations/sentry-sdks/issues/3007144862/events/31495690091f4d7684c339e6fd9a6ebc/?project=5428562

await dio.post<String>('https://flutter.dev/', data: Exception());, throws because Exception can't be serialized: https://sentry.io/organizations/sentry-sdks/issues/3009008663/events/fcb1d27e11be4af4b71b25b6c04128c6/?project=5428562

@brustolin
Copy link
Contributor

@marandaneto, as you said, code looks good.
But I don't really know how EventProcessor works in the Dart SDK, need to get familiar with this.

@ueman
Copy link
Collaborator Author

ueman commented Feb 14, 2022

@marandaneto, as you said, code looks good. But I don't really know how EventProcessor works in the Dart SDK, need to get familiar with this.

Feel free to ask (here or on Discord), I'll probably can answer at least some questions.

@marandaneto
Copy link
Contributor

@ueman sentry-dio / package-analysis is unhappy, otherwise LGTM.

Copy link
Contributor

@marandaneto marandaneto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ueman thanks for making the dio integration better :)

@marandaneto
Copy link
Contributor

@kuhnroyal also thanks for the valuable tests and insights.

@ueman
Copy link
Collaborator Author

ueman commented Feb 14, 2022

I would guess it's because pana doesn't check the dependency overrides? The getter which pana complains about isn't available in the latest stable but on main. I don't think I can do anything about that.

Pana isn't happy because of:


[x] 0/30 points: code has no errors, warnings, lints, or formatting issues

Found 3 issues. Showing the first 2:

ERROR: The getter 'exceptionFactory' isn't defined for the type 'SentryOptions'. `lib/src/dio_event_processor.dart:20:16```` ╷ 20 │ _options.exceptionFactory; │ ^^^^^^^^^^^^^^^^ ╵ ``` To reproduce make sure you are using the [lints_core](https://pub.dev/packages/lints) and run `dart analyze lib/src/dio_event_processor.dart`
ERROR: The method 'shouldAddBody' isn't defined for the type 'MaxRequestBodySize'. `lib/src/dio_event_processor.dart:127:31` ``` ╷ 127 │ if (_maxRequestBodySize.shouldAddBody(data.codeUnits.length)) { │ ^^^^^^^^^^^^^ ╵ ``` To reproduce make sure you are using the [lints_core](https://pub.dev/packages/lints) and run `dart analyze lib/src/dio_event_processor.dart`

@marandaneto
Copy link
Contributor

I would guess it's because pana doesn't check the dependency overrides? The getter which pana complains about isn't available in the latest stable but on main. I don't think I can do anything about that.

Pana isn't happy because of:

[x] 0/30 points: code has no errors, warnings, lints, or formatting issues

Found 3 issues. Showing the first 2:

ERROR: The getter 'exceptionFactory' isn't defined for the type 'SentryOptions'.
ERROR: The method 'shouldAddBody' isn't defined for the type 'MaxRequestBodySize'.

Indeed, I believe pana should respect dependency_overrides or at least offer an option to respect it since multi-module projects would run into this issue very often.
Maybe worth filing an issue on https://github.com/dart-lang/pana/ as a feature request.
Let's merge and not block on this then :)

@marandaneto
Copy link
Contributor

I'm fine if you want to address #718 (comment) or keep as it is, your call.
I'm good to merge as it is.

@marandaneto marandaneto enabled auto-merge (squash) February 21, 2022 15:15
@marandaneto marandaneto merged commit f4c06af into getsentry:main Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[dio] Improve fingerprinting
5 participants