Skip to content

Commit 1e3c4dd

Browse files
fuzzybinaryrtrieu
andauthored
Add documentation for new datadog_dio Flutter package. (#32509)
* Add documentation for new datadog_dio Flutter package. * Apply suggestions from code review Co-authored-by: Rosa Trieu <107086888+rtrieu@users.noreply.github.com> * Update content/en/real_user_monitoring/application_monitoring/flutter/integrated_libraries.md --------- Co-authored-by: Rosa Trieu <107086888+rtrieu@users.noreply.github.com> Co-authored-by: Rosa Trieu <rosa.trieu@datadoghq.com>
1 parent 9686256 commit 1e3c4dd

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

content/en/real_user_monitoring/application_monitoring/flutter/advanced_configuration.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ In order to enable Datadog [Distributed Tracing][13], you must set the `DatadogC
201201

202202
- `DatadogRumConfiguration.traceSampleRate` sets a default sampling rate of 20%. If you want all resources requests to generate a full distributed trace, set this value to `100.0`.
203203

204+
### Track resources from other packages
205+
206+
While `Datadog Tracking HTTP Client` can track most common network calls in Flutter, Datadog supplies packages for integration into specific networking libraries, including gRPC, GraphQL and Dio. For more information about these libraries, see [Integrated Libraries][22].
207+
204208
## Enrich user sessions
205209

206210
Flutter RUM automatically tracks attributes such as user activity, views (using the `DatadogNavigationObserver`), errors, native crashes, and network requests (using the Datadog Tracking HTTP Client). See the [RUM Data Collection documentation][14] to learn about the RUM events and default attributes. You can further enrich user session information and gain finer control over the attributes collected by tracking custom events.
@@ -422,7 +426,7 @@ To enable the collection of Flutter-specific performance metrics, set `reportFlu
422426

423427
## OpenTelemetry setup
424428

425-
The [Datadog Tracking HTTP Client][10] package and [gRPC Interceptor][19] package both support distributed traces through both automatic header generation and header ingestion. This section describes how to use OpenTelemetry with RUM Flutter.
429+
All of Datadog's automatic network tracking packages ([Datadog Tracking HTTP Client][10], [gRPC Interceptor][19], [GQL Link][20], and [Dio Interceptor][21]) support distributed traces through both automatic header generation and header ingestion. This section describes how to use OpenTelemetry with RUM Flutter.
426430

427431
### Datadog header generation
428432

@@ -484,3 +488,6 @@ if (DatadogSdk.instance.isFirstPartyHost(host)){
484488
[17]: https://pub.dev/documentation/datadog_flutter_plugin/latest/datadog_flutter_plugin/
485489
[18]: /real_user_monitoring/application_monitoring/mobile_vitals/?tab=flutter
486490
[19]: https://pub.dev/packages/datadog_grpc_interceptor
491+
[20]: https://pub.dev/packages/datadog_gql_link
492+
[21]: https://pub.dev/packages/datadog_dio
493+
[22]: /real_user_monitoring/application_monitoring/flutter/integrated_libraries

content/en/real_user_monitoring/application_monitoring/flutter/integrated_libraries.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,49 @@ final datadogConfig = DatadogConfiguration(
216216
);
217217
```
218218

219+
## Dio
219220

221+
<div class="alert alert-info">
222+
For most Dio setups, use Datadog Tracking Http Client instead of the specialized Dio interceptor. Only use the Dio interceptor if you're using a non-standard Dio <code>HttpClientAdapter</code> that cannot be tracked by Datadog Tracking Http Client.
223+
</div>
224+
225+
Datadog provides [`datadog_dio`][6] for use with the [Dio Flutter package][7]. The Dio interceptor automatically tracks requests from a given Dio client as RUM Resources and enables distributed tracing with APM.
226+
227+
### Setup
228+
229+
Add `datadog_dio` to your `pubspec.yaml` or by running `flutter pub add datadog_dio` from your terminal:
230+
231+
```yaml
232+
dependencies:
233+
# Other dependencies
234+
datadog_dio: ^1.0.0
235+
```
236+
237+
To use this plugin, call `addDatadogInterceptor` at the end of your Dio initialization:
238+
239+
```dart
240+
import 'package:datadog_dio/datadog_dio.dart'
241+
242+
// Initialize Datadog - be sure to set the [DatadogConfiguration.firstPartyHosts] member
243+
// Enable Datadog Distributed Tracing
244+
final config = DatadogConfiguration(
245+
// ...
246+
firstPartyHosts = ['localhost']
247+
)
248+
249+
// Create our Dio client
250+
final dio = Dio()
251+
// Dio configuration...
252+
..addDatadogInterceptor(DatadogSdk.instance);
253+
```
254+
255+
Calling `addDatadogInterceptor` adds the Datadog interceptor as the first interceptor in your list. This ensures all network requests from Dio are sent to Datadog, since other interceptors may not forward information down the chain. Call `addDatadogInterceptor` after completing all other Dio configuration.
256+
257+
### Use with other Datadog Network Tracking
258+
259+
To track all network requests, including those made by `dart:io` and widgets like `NetworkImage`, use `datadog_tracking_http_client` to capture these requests. However, depending on your setup, the global override method used in `enableHttpTracking` may cause resources to be double reported (once by the global override and once by the Dio interceptor)
260+
261+
To avoid this, use the `ignoreUrlPatterns` parameter when calling `enableHttpTracking` to ignore requests made by your Dio client.
220262

221263
## Further Reading
222264

@@ -232,3 +274,4 @@ final datadogConfig = DatadogConfiguration(
232274
[8]: https://pub.dev/packages/webview_flutter
233275
[9]: https://pub.dev/packages/flutter_inappwebview
234276
[10]: /real_user_monitoring/application_monitoring/web_view_tracking?tab=flutter
277+
[11]: https://pub.dev/packages/datadog_dio

0 commit comments

Comments
 (0)