Skip to content

Pass missing captureFailedRequests param to FailedRequestInterceptor#2744

Merged
denrase merged 4 commits into
getsentry:mainfrom
Maatteogekko:main
Mar 5, 2025
Merged

Pass missing captureFailedRequests param to FailedRequestInterceptor#2744
denrase merged 4 commits into
getsentry:mainfrom
Maatteogekko:main

Conversation

@Maatteogekko

Copy link
Copy Markdown
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

@codecov

codecov Bot commented Feb 21, 2025

Copy link
Copy Markdown

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
Copy Markdown
Contributor Author

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

@krystofwoldrich

Copy link
Copy Markdown
Contributor

Hi @Maatteogekko,
thank you for the PR.

Yes, please, add a changelog entry.

@denrase denrase left a comment

Copy link
Copy Markdown
Collaborator

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! 🙇‍♂️

@denrase denrase left a comment

Copy link
Copy Markdown
Collaborator

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
@denrase

denrase commented Mar 5, 2025

Copy link
Copy Markdown
Collaborator

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