Asset Bundle Instrumentation
Learn more about the Sentry Asset Bundle Instrumentation for the Flutter SDK.
Not available in stream mode
Asset bundle instrumentation isn't supported in stream mode yet — it creates spans only in the default transaction mode.
AssetBundle instrumentation provides insight into how long your app takes to load its assets, such as files.
The instrumentation starts a span from an active transaction that's bound to the scope of the following calls:
loadandloadString- The SDK sets the spanoperationtofile.read.loadStructuredData- The SDK sets the spanoperationtoserialize.
Before starting, ensure:
Wrap the runApp method with a DefaultAssetBundle and SentryAssetBundle.
Copied
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) => options.dsn = '___PUBLIC_DSN___',
appRunner: () => runApp(
DefaultAssetBundle(
bundle: SentryAssetBundle(),
child: MyApp(),
),
),
);
}
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) => options.dsn = '___PUBLIC_DSN___',
appRunner: () => runApp(
DefaultAssetBundle(
bundle: SentryAssetBundle(),
child: MyApp(),
),
),
);
}
Copied
final transaction = Sentry.startTransaction(
'asset-bundle-transaction',
'load',
bindToScope: true,
);
final text = await DefaultAssetBundle.of(context).loadString('assets/lorem-ipsum.txt');
await transaction.finish(status: const SpanStatus.ok());
final transaction = Sentry.startTransaction(
'asset-bundle-transaction',
'load',
bindToScope: true,
);
final text = await DefaultAssetBundle.of(context).loadString('assets/lorem-ipsum.txt');
await transaction.finish(status: const SpanStatus.ok());
To view the recorded transaction, log into sentry.io and open your project. Clicking Performance will open a page with transactions, where you can select the just recorded transaction with the name asset-bundle-transaction.
The loadStructuredData is an opt-out feature. The following example shows how to disable it:
Copied
import 'package:sentry_flutter/sentry_flutter.dart';
SentryAssetBundle(enableStructuredDataTracing: false)
import 'package:sentry_flutter/sentry_flutter.dart';
SentryAssetBundle(enableStructuredDataTracing: false)
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").