sentry_dio 7.0.0-alpha.5 copy "sentry_dio: ^7.0.0-alpha.5" to clipboard
sentry_dio: ^7.0.0-alpha.5 copied to clipboard

An integration which adds support for performance tracing for the Dio package.

example/example.dart

import 'package:dio/dio.dart';
import 'package:sentry/sentry.dart';
import 'package:sentry_dio/sentry_dio.dart';

Future<void> main() async {
  // ATTENTION: Change the DSN below with your own to see the events in Sentry. Get one at sentry.io
  const dsn =
      'https://[email protected]/5428562';

  await Sentry.init(
    (options) {
      options.dsn = dsn;
      options.tracesSampleRate =
          1.0; // needed for Dio `captureFailedRequests` feature
      options.debug = true;
      options.sendDefaultPii = true;

      options.maxRequestBodySize = MaxRequestBodySize.small;
      options.maxResponseBodySize = MaxResponseBodySize.small;
    },
    appRunner: runApp, // Init your App.
  );
}

Future<void> runApp() async {
  final dio = Dio();
  dio.addSentry();

  final transaction = Sentry.startTransaction(
    'dio-web-request',
    'request',
    bindToScope: true,
  );

  try {
    final response = await dio
        .get<Map<String, Object?>>('https://www.google.com/idontexist');

    print(response.toString());

    transaction.status =
        SpanStatus.fromHttpStatusCode(response.statusCode ?? -1);
  } catch (exception) {
    transaction.throwable = exception;
    transaction.status = const SpanStatus.internalError();
  } finally {
    await transaction.finish();
  }

  await Sentry.close();
}
24
likes
0
pub points
97%
popularity

Publisher

verified publishersentry.io

An integration which adds support for performance tracing for the Dio package.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

dio, sentry

More

Packages that depend on sentry_dio