sentry-dart
sentry-dart copied to clipboard
Support custom client and transport for the Flutter SDK
Hi, Currently we are using the self-hosting Sentry back-end.
Due to security concerns, our devOps asked me to add some extra properties to request headers.
Im tried implements a BaseClient and pass it to the option, but it doesn't work.
if (kReleaseMode) {
await SentryFlutter.init(
(options) {
options.dsn =
'http://##########dnsLink########/2';
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.httpClient = MySentryHttpClient;
options.tracesSampleRate = 1.0;
},
appRunner: () => runApp(const MyApp()),
);
} else {
runApp(
const MyApp(),
);
}
my_sentry_http_client.dart
class MySentryHttpClient extends BaseClient {
final Client _httpClient = Client();
MySentryHttpClient();
@override
Future<StreamedResponse> send(BaseRequest request) {
var defaultHeaders = <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
"Extra-Property": "tokenABC",
};
request.headers.addAll(defaultHeaders);
return _httpClient.send(request);
}
}
Sorry for my broken english and thank you for everything....
@KeterVM we'll look into it, thanks.
The Java SDK makes it possible having a ITransportFactory and a RequestDetails parameter, so users could override the transportFactory property in the SentryOptions and mutate the requestDetails, we could do the same here.
For the Dart SDK that would be fine but for the Flutter SDK, we'd need to sync down this configuration to the Android and iOS SDK, the iOS SDK currently does not support this feature either, so we are blocked for now.
@philipphofmann @brustolin to confirm.
@KeterVM your option should work for the Dart SDK but not for the Flutter SDK (it uses the client and transport from the Native SDKs).
Adding extra HTTP headers should be possible with SentryOptions.urlSessionDelegate. Can you confirm @brustolin?
@brustolin can you confirm that?
Adding extra HTTP headers should be possible with SentryOptions.urlSessionDelegate. Can you confirm @brustolin?
No, not possible. URLSession Delegate is to respond to state changes, not mutate the request. Currently is not possible to do this in the iOS SDK.