Skip to content

Conversation

@tsinis
Copy link
Contributor

@tsinis tsinis commented May 6, 2025

📜 Description

Exports the SentryTransformer class from the sentry_dio package (src/sentry_transformer.dart).

This makes the transformer class available for users to import and utilize directly if needed for custom Dio client transformer configurations.

💡 Motivation and Context

When integrating Sentry with Dio, the addSentry() method overwrites Dio's default transformer with Sentry's own wrapper - SentryTransformer. However, in some cases, there are performance benefits of Dio's BackgroundTransformer (that could be passed to the SentryTransformer's transformer parameter), which processes large payloads (>50KB) in separate isolates. But since SentryTransformer is not exported, there is no easy way to do it.

💚 How did you test it?

  • Verified that the package (sentry_dio) compiles successfully with the added export.
  • Manually confirmed in a sample project that SentryTransformer can be successfully imported via import 'package:sentry_dio/sentry_dio.dart';.
  • The need for this change was identified through performance analysis in an application experiencing UI freezes when decoding large (multi-MB) JSON responses after integrating sentry_dio.

📝 Checklist

  • I reviewed submitted code
  • Tests are not needed for exports
  • 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

🔮 Next steps

Consider adding documentation explaining what addSentry() does under the hood and how it could be customized.

@ueman
Copy link
Collaborator

ueman commented May 6, 2025

This is actually not needed, since you should configure dio first, and as a last step call addSentry(). Since Sentry does not override any user configuratioon, it then uses whatever transformer you configured dio to use.

See this

httpClientAdapter = SentryDioClientAdapter(
client: httpClientAdapter,
hub: hub,
);

and this

transformer = SentryTransformer(
transformer: transformer,
hub: hub,
);

This also ensures that integrating Sentry with dio is as seamless as possible, since it's just adding or removing the addSentry() call.

So here's how you should use it:

final dio = Dio();
dio.transformer = ...;
dio.httpClientAdapter = ...;
dio.addSentry(); // Dio is used with whatever transformer is configured two lines above AND also with Sentry

Disclaimer: I'm not a Sentry employe, but I wrote the Sentry dio integration and was a former dio maintainer

@tsinis
Copy link
Contributor Author

tsinis commented May 6, 2025

Hey @ueman I see, yes - make sense, but this is still not that obvious, I will provide documentation update in a separate PR, thanks!

@tsinis tsinis closed this May 6, 2025
@ueman
Copy link
Collaborator

ueman commented May 6, 2025

It's already stated in the docs here:

/// This must be the last initialization step of the [Dio] setup, otherwise
/// your configuration of Dio might overwrite the Sentry configuration.

But yeah, I guess a more exhaustive explanation can not hurt

tsinis added a commit to tsinis/sentry-dart that referenced this pull request May 6, 2025
buenaflor pushed a commit that referenced this pull request May 7, 2025
* docs(sentry-dio): improve `addSentry` method documentation with usage examples

#2911 (comment)

* fix(style): dartdoc dart format .
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.

2 participants