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

Pass missing captureFailedRequests param to FailedRequestInterceptor #2744

Merged
merged 4 commits into from
Mar 5, 2025

Conversation

Maatteogekko
Copy link
Contributor

📜 Description

dio.addSentry() captureFailedRequest param passed through to FailedRequestInterceptor.

💡 Motivation and Context

Fixes #2737.

💚 How did you test it?

I have run the fix in my app and it works as expected.

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPii is enabled
  • I updated the docs if needed
  • All tests passing
  • No breaking changes

Sorry, something went wrong.

Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.55%. Comparing base (f511159) to head (cee4901).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2744      +/-   ##
==========================================
+ Coverage   88.96%   94.55%   +5.59%     
==========================================
  Files         263        9     -254     
  Lines        8925      202    -8723     
==========================================
- Hits         7940      191    -7749     
+ Misses        985       11     -974     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Maatteogekko
Copy link
Contributor Author

Should I add the changelog entry like the failing job suggests?

@krystofwoldrich
Copy link
Member

Hi @Maatteogekko,
thank you for the PR.

Yes, please, add a changelog entry.

Copy link
Collaborator

@denrase denrase left a comment

Choose a reason for hiding this comment

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

Hey @Maatteogekko ! Thank you for contributing!

Code looks good, I took the liberty to write a test locally which you could just paste in addition to syncing with main. After that we can merge.

  • In sentry_dio_extension.dart please also pass the hub:
interceptors.insert(
    0,
    FailedRequestInterceptor(
          hub: hub,
          failedRequestStatusCodes: failedRequestStatusCodes,
          failedRequestTargets: failedRequestTargets,
          captureFailedRequests: captureFailedRequests,
    ),
);
  • In sentry_dio_extension.test replace the addSentry adds $FailedRequestInterceptor if override true with the following:
test('addSentry adds $FailedRequestInterceptor if override true', () {
final dio = fixture.getSut();

fixture.hub.options.captureFailedRequests = false;

dio.addSentry(hub: fixture.hub, captureFailedRequests: true);

expect(
  dio.interceptors.whereType<FailedRequestInterceptor>().length,
  1,
);

final interceptor = dio.interceptors.whereType<FailedRequestInterceptor>().first;

final requestOptions = RequestOptions(path: 'https://example.com');
final error = DioError(
  requestOptions: requestOptions,
  response: Response(statusCode: 500, requestOptions: requestOptions),
);
interceptor.onError(error, fixture.errorInterceptorHandler);

expect(fixture.hub.captureExceptionCalls.length, 1);
});

and fixure:

class Fixture {
  final MockHub hub = MockHub();
  final errorInterceptorHandler = MockedErrorInterceptorHandler();

  Dio getSut() {
    return Dio();
  }
}

That way we have covered your contribution by a test case. Thank you! 🙇‍♂️

Copy link
Collaborator

@denrase denrase left a comment

Choose a reason for hiding this comment

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

Looks good, if CI is successful we can merge.

@denrase denrase merged commit f0adcc8 into getsentry:main Mar 5, 2025
13 of 15 checks passed
@denrase
Copy link
Collaborator

denrase commented Mar 5, 2025

Ok, looks like auto-merge is ignoring CI. 🤦‍♂️ @kahest I'm gonna check out main and fix if needed.

@denrase denrase mentioned this pull request Mar 5, 2025
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.

captureFailedRequests not correctly passed to FailedRequestInterceptor
3 participants