dynatrace_flutter_plugin_dio 3.303.2 dynatrace_flutter_plugin_dio: ^3.303.2 copied to clipboard
An extension of the Dynatrace Flutter Plugin which allows support for instrumentation of the Dio package.
Dynatrace Flutter Plugin support with Dio #
This plugin adds support/instrumentation for dio when used with the Dynatrace Flutter Plugin.
Requirements #
- Dynatrace Flutter Plugin.
- Flutter Version >= 1.12.0
- Dart Version >= 2.15
- Dio Version >= 5.0.0
- Gradle: >= 5.x
- Android API Level >= 21
- iOS SDK >= 12
Overview #
Usage #
Our plugin for Dio provides an extension method, .instrument()
, which can be used to automatically tag and time the web requests that are called with the Dio package.
import 'package:dynatrace_flutter_plugin_dio/dynatrace_flutter_plugin_dio.dart';
final dio = Dio();
dio.instrument();
Create a user action and correlate the dio
request shown in the Waterfall analysis:
import 'package:dynatrace_flutter_plugin_dio/dynatrace_flutter_plugin_dio.dart';
import 'package:dynatrace_flutter_plugin/dynatrace_flutter_plugin.dart';
final dio = Dio();
dio.instrument();
var url = 'https://dynatrace.com';
DynatraceRootAction dioAction =
Dynatrace().enterAction('Dio Action');
try {
await dio.get(url);
} catch (error) {
// insert error handling here
} finally {
dioAction.leaveAction();
}
Note:
If you do not create a user action around the dio
request, our plugin will automatically create a user action which will include the request in the Waterfall analysis of such action. The name of this action is **Dio Request:
Request & Response size calculation #
The web request instrumentation is by default reporting request and response bytes. This calculation has some limitations, therefore the instrument
function allows you to pass DynatraceClientAdapterOptions
. Per default, Dio
will append following headers:
- "Accept-Encoding": "gzip"
- "User-Agent": "Dart/X.X (dart:io)"
These headers are not visible at the request size calculation, but can be modified via HttpClient
used in Dio
(e.g request.headers.removeAll(HttpHeaders.acceptEncodingHeader)
). If the header value will be overridden by a different value, our calculation will not be able to consider this as we expect the default header value. For example, if "Accept-Encoding" is removed, use DynatraceClientAdapterOptions
to get correct values for the request size calculation (see the example below). If headers are changed on request basis and a different "Accept-Encoding" value is appended directly, the calculation will consider this. Also DynatraceClientAdapterOptions
provides functionality for excluding urls which you do not want to be tracked.
import 'package:dynatrace_flutter_plugin_dio/dynatrace_flutter_plugin_dio.dart';
import 'package:dynatrace_flutter_plugin/dynatrace_flutter_plugin.dart';
Map<String, String> _myNewDefaultHeaders = {
"User-Agent": "Dart/X.X (dart:io)"
};
DynatraceClientAdapterOptions _options = DynatraceClientAdapterOptions(_myNewDefaultHeaders, exclusionList: ['url-to-exclude.com']);
final dio = Dio();
dio.instrument(options: _options);
var url = 'https://dynatrace.com';
DynatraceRootAction dioAction =
Dynatrace().enterAction('Dio Action');
try {
await dio.get(url);
} catch (error) {
// insert error handling here
} finally {
dioAction.leaveAction();
}