Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOCS-9372] Move tracking stuff from setup to advanced config #26882

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,26 @@ A custom endpoint for sending RUM data.
**Default**: `20.0`
The sampling rate for telemetry data, such as errors and debug logs.

## Automatic view tracking
## Automatically track resources

If you are using Flutter Navigator v2.0, your setup for automatic view tracking differs depending on your routing middleware. See [Flutter Integrated Libraries][18] for instructions on how to integrate with [go_router][8], [AutoRoute][9], and [Beamer][10].
Use the [Datadog Tracking HTTP Client][12] package to enable automatic tracking of resources and HTTP calls from your views.

Add the package to your `pubspec.yaml` and add the following to your initialization file:

```dart
final configuration = DatadogConfiguration(
// configuration
firstPartyHosts: ['example.com'],
)..enableHttpTracking()
```

**Note**: The Datadog Tracking HTTP Client modifies [`HttpOverrides.global`][27]. If you are using your own custom `HttpOverrides`, you may need to inherit from [`DatadogHttpOverrides`][28]. In this case, you do not need to call `enableHttpTracking`. Versions of `datadog_tracking_http_client` >= 1.3 check the value of `HttpOverrides.current` and use this for client creation, so you only need to make sure to initialize `HttpOverrides.global` prior to initializing Datadog.

In order to enable Datadog [Distributed Tracing][29], you must set the `DatadogConfiguration.firstPartyHosts` property in your configuration object to a domain that supports distributed tracing. You can also modify the sampling rate for distributed tracing by setting the `tracingSamplingRate` on your `DatadogRumConfiguration`.

- `firstPartyHosts` does not allow wildcards, but matches any subdomains for a given domain. For example, `api.example.com` matches `staging.api.example.com` and `prod.api.example.com`, not `news.example.com`.

- `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`.

## Enrich user sessions

Expand Down Expand Up @@ -457,4 +474,9 @@ if (DatadogSdk.instance.isFirstPartyHost(host)){
[21]: /real_user_monitoring/connect_rum_and_traces/?tab=browserrum#how-are-rum-resources-linked-to-traces
[22]: https://github.com/openzipkin/b3-propagation#single-headers
[23]: https://github.com/openzipkin/b3-propagation#multiple-headers
[24]: https://www.w3.org/TR/trace-context/#tracestate-header
[24]: https://www.w3.org/TR/trace-context/#tracestate-header
[25]: https://pub.dev/packages/go_router
[26]: https://pub.dev/documentation/datadog_flutter_plugin/latest/datadog_flutter_plugin/ViewInfoExtractor.html
[27]: https://api.flutter.dev/flutter/dart-io/HttpOverrides/current.html
[28]: https://pub.dev/documentation/datadog_tracking_http_client/latest/datadog_tracking_http_client/DatadogTrackingHttpOverrides-class.html
[29]: /serverless/aws_lambda/distributed_tracing/
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ This loads the CDN-delivered Datadog Browser SDKs for Logs and RUM. The synchron

For more information on available configuration options, see the [DatadogConfiguration object documentation][4].

To ensure the safety of your data, you must use a client token. You cannot use Datadog API keys to configure the Datadog Flutter Plugin.
To ensure the safety of your data, you must use a client token. You cannot use Datadog API keys to configure the Datadog [Flutter Plugin][5].

- If you are using RUM, set up a **Client Token** and **Application ID**.
- If you are only using Logs, initialize the library with a client token.
Expand All @@ -176,15 +176,15 @@ To ensure the safety of your data, you must use a client token. You cannot use D

You can initialize the library using one of two methods in your `main.dart` file.

- Use `DatadogSdk.runApp` to automatically set up [Error Tracking][5].
- Use `DatadogSdk.runApp` to automatically set up [Error Tracking][6].

```dart
await DatadogSdk.runApp(configuration, TrackingConsent.granted, () async {
runApp(const MyApp());
})
```

- You can also manually set up [Error Tracking][5] and resource tracking. `DatadogSdk.runApp` calls `WidgetsFlutterBinding.ensureInitialized`, so if you are not using `DatadogSdk.runApp`, you need to call this method prior to calling `DatadogSdk.instance.initialize`.
- You can also manually set up [Error Tracking][6] and resource tracking. `DatadogSdk.runApp` calls `WidgetsFlutterBinding.ensureInitialized`, so if you are not using `DatadogSdk.runApp`, you need to call this method prior to calling `DatadogSdk.instance.initialize`.

```dart
WidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -243,6 +243,8 @@ The SDK changes its behavior according to the new value. For example, if the cur

## Automatically track views

If you are using Flutter Navigator v2.0, your setup for automatic view tracking differs depending on your routing middleware. See [Flutter Integrated Libraries][12] for instructions on how to integrate with [go_router][7], [AutoRoute][9], and [Beamer][10].

### Flutter Navigator v1

The Datadog Flutter Plugin can automatically track named routes using the `DatadogNavigationObserver` on your MaterialApp:
Expand All @@ -262,7 +264,7 @@ If you are not using named routes, you can use `DatadogRouteAwareMixin` in conju

### Flutter Navigator v2

If you are using Flutter Navigator v2.0, which uses the `MaterialApp.router` named constructor, the setup varies based on the routing middleware you are using, if any. Since [`go_router`][6] uses the same observer interface as Flutter Navigator v1, `DatadogNavigationObserver` can be added to other observers as a parameter to `GoRouter`.
If you are using Flutter Navigator v2.0, which uses the `MaterialApp.router` named constructor, the setup varies based on the routing middleware you are using, if any. Since [`go_router`][7] uses the same observer interface as Flutter Navigator v1, `DatadogNavigationObserver` can be added to other observers as a parameter to `GoRouter`.

```dart
final _router = GoRouter(
Expand All @@ -279,11 +281,12 @@ MaterialApp.router(
)
```

For examples that use routers other than `go_router`, see [Advanced Configuration - Automatic View Tracking][7].
For examples that use routers other than `go_router`, see [Automatically track views](#automatically-track-views).


### Renaming Views

For all setups, you can rename views or supply custom paths by providing a [`viewInfoExtractor`][8] callback. This function can fall back to the default behavior of the observer by calling `defaultViewInfoExtractor`. For example:
For all setups, you can rename views or supply custom paths by providing a [`viewInfoExtractor`][11] callback. This function can fall back to the default behavior of the observer by calling `defaultViewInfoExtractor`. For example:

```dart
RumViewInfo? infoExtractor(Route<dynamic> route) {
Expand All @@ -304,28 +307,6 @@ var observer = DatadogNavigationObserver(
);
```

## Automatically track resources

Use the [Datadog Tracking HTTP Client][9] package to enable automatic tracking of resources and HTTP calls from your views.

Add the package to your `pubspec.yaml` and add the following to your initialization file:

```dart
final configuration = DatadogConfiguration(
// configuration
firstPartyHosts: ['example.com'],
)..enableHttpTracking()
```

**Note**: The Datadog Tracking HTTP Client modifies [`HttpOverrides.global`][10]. If you are using your own custom `HttpOverrides`, you may need to inherit from [`DatadogHttpOverrides`][11]. In this case, you do not need to call `enableHttpTracking`. Versions of `datadog_tracking_http_client` >= 1.3 check the value of `HttpOverrides.current` and use this for client creation, so you only need to make sure to initialize `HttpOverrides.global` prior to initializing Datadog.

In order to enable Datadog [Distributed Tracing][12], you must set the `DatadogConfiguration.firstPartyHosts` property in your configuration object to a domain that supports distributed tracing. You can also modify the sampling rate for distributed tracing by setting the `tracingSamplingRate` on your `DatadogRumConfiguration`.

- `firstPartyHosts` does not allow wildcards, but matches any subdomains for a given domain. For example, `api.example.com` matches `staging.api.example.com` and `prod.api.example.com`, not `news.example.com`.

- `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`.


## Automatically track actions

Use [`RumUserActionDetector`][13] to track user taps that happen in a given Widget tree:
Expand Down Expand Up @@ -390,13 +371,13 @@ This means that even if users open your application while offline, no data is lo
[2]: /error_tracking/
[3]: /account_management/api-app-keys/#client-tokens
[4]: https://pub.dev/documentation/datadog_flutter_plugin/latest/datadog_flutter_plugin/DatadogConfiguration-class.html
[5]: /real_user_monitoring/error_tracking/flutter
[6]: https://pub.dev/packages/go_router
[7]: /real_user_monitoring/mobile_and_tv_monitoring/flutter/advanced_configuration/#automatic-view-tracking
[8]: https://pub.dev/documentation/datadog_flutter_plugin/latest/datadog_flutter_plugin/ViewInfoExtractor.html
[9]: https://pub.dev/packages/datadog_tracking_http_client
[10]: https://api.flutter.dev/flutter/dart-io/HttpOverrides/current.html
[11]: https://pub.dev/documentation/datadog_tracking_http_client/latest/datadog_tracking_http_client/DatadogTrackingHttpOverrides-class.html
[12]: /serverless/distributed_tracing
[13]: https://pub.dev/documentation/datadog_flutter_plugin/latest/datadog_flutter_plugin/RumUserActionDetector-class.html
[14]: https://pub.dev/documentation/datadog_flutter_plugin/latest/datadog_flutter_plugin/RumUserActionAnnotation-class.html
[5]: https://pub.dev/documentation/datadog_flutter_plugin/latest/datadog_flutter_plugin/ViewInfoExtractor.html
[6]: /real_user_monitoring/error_tracking/flutter
[7]: https://pub.dev/packages?q=go_router
[8]: /real_user_monitoring/mobile_and_tv_monitoring/flutter/advanced_configuration/#automatic-view-tracking
[9]: https://pub.dev/packages/auto_route
[10]: https://pub.dev/packages/beamer
[11]: https://pub.dev/documentation/datadog_flutter_plugin/latest/datadog_flutter_plugin/ViewInfoExtractor.html
[12]: /real_user_monitoring/mobile_and_tv_monitoring/flutter/integrated_libraries/
[13]: https://pub.dev/documentation/datadog_flutter_plugin/latest/datadog_flutter_plugin/RumUserActionAnnotation-class.html
[14]: https://pub.dev/documentation/datadog_flutter_plugin/latest/datadog_flutter_plugin/RumUserActionDetector-class.html
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,26 @@ Datadog.setUserInfo(id: "1234", name: "John Doe", email: "[email protected]")
{{% /tab %}}
{{< /tabs >}}

## Track background events

<div class="alert alert-info"><p>Tracking background events may lead to additional sessions, which can impact billing. For questions, <a href="https://docs.datadoghq.com/help/">contact Datadog support.</a></p>
</div>

You can track events such as crashes and network requests when your application is in the background (for example, no active view is available).

To track background events, add the following snippet during initialization in your Datadog configuration:

```swift
import DatadogRUM

RUM.enable(
with: RUM.Configuration(
...
trackBackgroundEvents: true
)
)
```

## Initialization Parameters

You can use the following properties in `Datadog.Configuration` when creating the Datadog configuration to initialize the library:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,26 +475,6 @@ struct BarView: View {
}
```

## Track background events

<div class="alert alert-info"><p>Tracking background events may lead to additional sessions, which can impact billing. For questions, <a href="https://docs.datadoghq.com/help/">contact Datadog support.</a></p>
</div>

You can track events such as crashes and network requests when your application is in the background (for example, no active view is available).

Add the following snippet during initialization in your Datadog configuration:

```swift
import DatadogRUM

RUM.enable(
with: RUM.Configuration(
...
trackBackgroundEvents: true
)
)
```

## Track iOS errors

[iOS Crash Reporting and Error Tracking][8] displays any issues in your application and the latest available errors. You can view error details and attributes including JSON in the [RUM Explorer][9].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ GlobalRumMonitor.get().addAttribute(key, value)
GlobalRumMonitor.get().removeAttribute(key)
```

## Track background events

You can track events such as crashes and network requests when your application is in the background (for example, no active view is available).

Add the following snippet during RUM configuration:

```kotlin
.trackBackgroundEvents(true)
```
<div class="alert alert-info"><p>Tracking background events may lead to additional sessions, which can impact billing. For questions, <a href="https://docs.datadoghq.com/help/">contact Datadog support.</a></p>
</div>

## Initialization parameters

You can use the following methods in `Configuration.Builder` when creating the Datadog configuration to initialize the library:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,18 +378,6 @@ val ktorClient = HttpClient {

This records each request processed by the `HttpClient` as a resource in RUM, with all the relevant information automatically filled (URL, method, status code, and error). Only the network requests that started when a view is active are tracked. To track requests when your application is in the background, [create a view manually][11] or enable [background view tracking](#track-background-events).

## Track background events

You can track events such as crashes and network requests when your application is in the background (for example, no active view is available).

Add the following snippet during RUM configuration:

```kotlin
.trackBackgroundEvents(true)
```
<div class="alert alert-info"><p>Tracking background events may lead to additional sessions, which can impact billing. For questions, <a href="https://docs.datadoghq.com/help/">contact Datadog support.</a></p>
</div>

## Track errors

[Kotlin Multiplatform Crash Reporting and Error Tracking][12] displays any issues in your application and the latest available errors. You can view error details and attributes including JSON in the [RUM Explorer][13].
Expand Down
Loading
Loading