-
-
Notifications
You must be signed in to change notification settings - Fork 239
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
Unable to use no_default_http_client #2453
Comments
hey thanks for raising this issue, we're having a look |
Hi @Masadow, I tried reproducing your exception, but wasn't lucky. Here is what I tried: I used our Then I created a import 'dart:convert';
import 'dart:typed_data';
import 'package:http/http.dart';
class customHttpClient implements Client {
@override
void close() {}
@override
Future<Response> delete(Uri url,
{Map<String, String>? headers, Object? body, Encoding? encoding}) async {
return Response("foo", 200);
}
@override
Future<Response> get(Uri url, {Map<String, String>? headers}) async {
return Response("foo", 200);
}
@override
Future<Response> head(Uri url, {Map<String, String>? headers}) async {
return Response("foo", 200);
}
@override
Future<Response> patch(Uri url,
{Map<String, String>? headers, Object? body, Encoding? encoding}) async {
return Response("foo", 200);
}
@override
Future<Response> post(Uri url,
{Map<String, String>? headers, Object? body, Encoding? encoding}) async {
return Response("foo", 200);
}
@override
Future<Response> put(Uri url,
{Map<String, String>? headers, Object? body, Encoding? encoding}) async {
return Response("foo", 200);
}
@override
Future<String> read(Uri url, {Map<String, String>? headers}) async {
return "foo";
}
@override
Future<Uint8List> readBytes(Uri url, {Map<String, String>? headers}) async {
return Uint8List(0);
}
@override
Future<StreamedResponse> send(BaseRequest request) async {
return StreamedResponse(Stream.empty(), 200);
}
} I added it in the Future<void> setupSentry(
AppRunner appRunner,
String dsn, {
bool isIntegrationTest = false,
BeforeSendCallback? beforeSendCallback,
}) async {
await SentryFlutter.init(
(options) {
options.httpClient = customHttpClient();
options.dsn = exampleDsn;
options.tracesSampleRate = 1.0;
options.profilesSampleRate = 1.0;
... Build it with Started the webserver with: @Masadow can you please be a little bit more specific under which circumstances the error occurs or provide a minimal working project where the error occurs? Thanks. For completeness, here is my
|
Maybe you can try to run the following code before initializing Sentry: final client = createCustomClient();
PackageInfoPlatform.instance = PackageInfoPlusWebPlugin(client);
|
I forgot to mention that the error occurs when ran in a zonedGuarded Here's my main : Future<void> main() async {
await runZonedGuarded(() async {
await dotenv.load(fileName: "assets/.env");
await SentryFlutter.init(
(options) {
options.httpClient = httpClient();
options.dsn = dotenv.get('SENTRY_DSN');
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.tracesSampleRate = 1.0;
// The sampling rate for profiling is relative to tracesSampleRate
// Setting to 1.0 will profile 100% of sampled transactions:
options.profilesSampleRate = 1.0;
options.environment = dotenv.get('STAGE');
},
);
// ... Also, the error occurs silently, there's no error in the chrome console, no error on flutter debug console. However, the app hang on sentry init, no request is made to the network and only way to catch the error is from "Sources" tab in chrome dev tool by ticking both "Pause on exceptions" and from there, you can see an error popping from package_info_plus I'll try to replicate the issue with more details, I turned the flag off and only tested it on a live server |
I can confirm I reproduce the issue Also, I confirm that only sentry uses package_info_plus As you can see, package info plus can take an optional http client that is never passed the way its made Honestly, I looked at the source code and have absolutely no idea on how that could be fixed since package_info_plus is registered globally There's probably an issue you need to raise to them to then be able to fix the issue on your own but I might be wrong, I don't know much at this level of dart code |
Looks hacky to me, I don't feel like I should deal with package_info_plus since I don't even import it myself I also find it weird that it needs any http client for the usage you have with it I agree that the client passed to sentry is an http client to be used by sentry I also don't see a ton of usages where you would want a different client to be used by sentry vs package info. |
Hello @Masadow I opened an issue at the BR Martin |
Hello @Masadow, As mentioned by @miquelbeltran here, passing the As I mentioned in my previous comment, the code which leads to your error is only executed if Another way of dealing, would be the approach of @ueman from the previous comment here. And the third (and probably the most time-consuming way) would be as @miquelbeltran wrote here, to fork the I hope one of the above options fits your application without causing too much overhead. BR Martin |
Hello, if I am not wrong, you can do a dependency overrides with your fork, you don't need to wait for Sentry to incorporate the package. So you can fork |
that would work, yeah |
thanks for detailed explanation, I'll have a look at that, I'm not a huge fan of forking libraries on my own as I will have to deal with updates manually However, the solution from @martinhaintz looks enough to me so I'll go with that |
Platform
Dart Web
Obfuscation
Enabled
Debug Info
Enabled
Doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.3, on macOS 14.1.1 23B81 darwin-x64, locale en-FR)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.95.1)
[✓] Connected device (2 available)
[✓] Network resources
• No issues found!
Version
8.10.1
Steps to Reproduce
Set up a custom HttpClient
Then add the parameter
--dart-define=no_default_http_client=true
toflutter build
to ensure no default clients are in useExpected Result
App starting properly
Actual Result
App is raising an expection because custom http client is not passed to package_info_plus which then use the default HTTP client
Are you willing to submit a PR?
Yes
The text was updated successfully, but these errors were encountered: