Skip to content

Support custom client and transport for the Flutter SDK #975

@KeterVM

Description

@KeterVM

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....

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions