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

refactor(analytics): Update datadog #917

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions packages/analytics/lib/sdk/datadog/core/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,19 @@ enum RumUserActionType {
custom
}

/// A mapper class to map [RumUserActionType] to [datadog.RumUserActionType].
Map<RumUserActionType, datadog.RumUserActionType> rumUserActionTypeMapper =
<RumUserActionType, datadog.RumUserActionType>{
RumUserActionType.tap: datadog.RumUserActionType.tap,
RumUserActionType.scroll: datadog.RumUserActionType.scroll,
RumUserActionType.swipe: datadog.RumUserActionType.swipe,
RumUserActionType.custom: datadog.RumUserActionType.custom,
/// A mapper class to map [RumUserActionType] to [datadog.RumActionType].
Map<RumUserActionType, datadog.RumActionType> rumUserActionTypeMapper =
<RumUserActionType, datadog.RumActionType>{
RumUserActionType.tap: datadog.RumActionType.tap,
RumUserActionType.scroll: datadog.RumActionType.scroll,
RumUserActionType.swipe: datadog.RumActionType.swipe,
RumUserActionType.custom: datadog.RumActionType.custom,
};

/// Extension on [RumUserActionType].
extension RumUserActionTypeExtension on RumUserActionType {
/// The consent getter method is an extension to the [datadog.RumUserActionType]
/// enum that returns the corresponding [datadog.RumUserActionType] value for
/// The consent getter method is an extension to the [datadog.RumActionType]
/// enum that returns the corresponding [datadog.RumActionType] value for
/// the given [RumUserActionType] value.
datadog.RumUserActionType get rumUserActionType =>
rumUserActionTypeMapper[this]!;
datadog.RumActionType get rumUserActionType => rumUserActionTypeMapper[this]!;
}
31 changes: 21 additions & 10 deletions packages/analytics/lib/sdk/datadog/sdk/deriv_datadog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,22 @@ class DerivDatadog implements BaseAnalytics<DerivDatadogConfiguration> {
@override
Future<bool> setup(DerivDatadogConfiguration configuration) async {
try {
final datadog.RumConfiguration rumConfiguration =
datadog.RumConfiguration(
final datadog.DatadogRumConfiguration rumConfiguration =
datadog.DatadogRumConfiguration(
applicationId: configuration.applicationId,
sessionSamplingRate: configuration.sessionSamplingRate ?? 100,
tracingSamplingRate: configuration.tracingSamplingRate ?? 100,
traceSampleRate: configuration.tracingSamplingRate ?? 100,
);

final datadog.DdSdkConfiguration datadogConfiguration =
datadog.DdSdkConfiguration(
final datadog.DatadogConfiguration datadogConfiguration =
datadog.DatadogConfiguration(
clientToken: configuration.clientToken,
env: configuration.env,
serviceName: configuration.serviceName,
service: configuration.serviceName,
site: configuration.site?.site ?? DatadogSite.us1.site,
trackingConsent: configuration.trackingConsent.consent,
nativeCrashReportEnabled:
configuration.nativeCrashReportEnabled ?? true,
loggingConfiguration: datadog.LoggingConfiguration(),
loggingConfiguration: datadog.DatadogLoggingConfiguration(),
rumConfiguration: rumConfiguration,
);

Expand All @@ -72,7 +71,8 @@ class DerivDatadog implements BaseAnalytics<DerivDatadogConfiguration> {
return platformOriginalOnError?.call(e, st) ?? false;
};

await _datadogSDK.initialize(datadogConfiguration);
await _datadogSDK.initialize(
datadogConfiguration, configuration.trackingConsent.consent);
_datadogSDK.updateConfigurationInfo(
LateConfigurationProperty.trackErrors, true);
return true;
Expand Down Expand Up @@ -101,9 +101,20 @@ class DerivDatadog implements BaseAnalytics<DerivDatadogConfiguration> {
required String name,
Map<String, Object?> attributes = const <String, Object?>{},
}) =>
_datadogSDK.rum?.addUserAction(
_datadogSDK.rum?.addAction(
type.rumUserActionType,
name,
attributes,
);

/// Logs Source Error
void onSourceError(
String message, [
Map<String, Object?> attributes = const <String, Object?>{},
]) =>
_datadogSDK.rum?.addErrorInfo(
message,
datadog.RumErrorSource.source,
attributes: attributes,
);
}
2 changes: 1 addition & 1 deletion packages/analytics/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
firebase_core: ^3.5.0
firebase_analytics: ^11.3.2
rudder_sdk_flutter: ^2.6.0
datadog_flutter_plugin: ^1.6.2
datadog_flutter_plugin: ^2.9.0

flutter:
sdk: flutter
Expand Down
36 changes: 20 additions & 16 deletions packages/deriv_datadog/lib/sdk/deriv_datadog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class DerivDatadog implements BaseDerivDatadog {
String name, [
Map<String, Object?> attributes = const <String, Object?>{},
]) =>
_datadogSDK.rum?.addUserAction(
datadog.RumUserActionType.tap,
_datadogSDK.rum?.addAction(
datadog.RumActionType.tap,
name,
attributes,
);
Expand All @@ -47,8 +47,8 @@ class DerivDatadog implements BaseDerivDatadog {
String name, [
Map<String, Object?> attributes = const <String, Object?>{},
]) =>
_datadogSDK.rum?.addUserAction(
datadog.RumUserActionType.scroll,
_datadogSDK.rum?.addAction(
datadog.RumActionType.scroll,
name,
attributes,
);
Expand All @@ -58,8 +58,8 @@ class DerivDatadog implements BaseDerivDatadog {
String name, [
Map<String, Object?> attributes = const <String, Object?>{},
]) {
_datadogSDK.rum?.addUserAction(
datadog.RumUserActionType.swipe,
_datadogSDK.rum?.addAction(
datadog.RumActionType.swipe,
name,
attributes,
);
Expand All @@ -70,8 +70,8 @@ class DerivDatadog implements BaseDerivDatadog {
String name, [
Map<String, Object?> attributes = const <String, Object?>{},
]) =>
_datadogSDK.rum?.addUserAction(
datadog.RumUserActionType.custom,
_datadogSDK.rum?.addAction(
datadog.RumActionType.custom,
name,
attributes,
);
Expand All @@ -92,24 +92,28 @@ class DerivDatadog implements BaseDerivDatadog {
DerivDatadogConfiguration configuration,
datadog.AppRunner runner,
) async {
final datadog.RumConfiguration rumConfiguration = datadog.RumConfiguration(
final datadog.DatadogRumConfiguration rumConfiguration =
datadog.DatadogRumConfiguration(
applicationId: configuration.applicationId,
sessionSamplingRate: configuration.sessionSamplingRate ?? 100,
tracingSamplingRate: configuration.tracingSamplingRate ?? 100,
traceSampleRate: configuration.tracingSamplingRate ?? 100,
);

final datadog.DdSdkConfiguration datadogConfiguration =
datadog.DdSdkConfiguration(
final datadog.DatadogConfiguration datadogConfiguration =
datadog.DatadogConfiguration(
clientToken: configuration.clientToken,
env: configuration.env,
serviceName: configuration.serviceName,
service: configuration.serviceName,
site: configuration.site?.site ?? DatadogSite.us1.site,
trackingConsent: configuration.trackingConsent.consent,
nativeCrashReportEnabled: configuration.nativeCrashReportEnabled ?? true,
loggingConfiguration: datadog.LoggingConfiguration(),
loggingConfiguration: datadog.DatadogLoggingConfiguration(),
rumConfiguration: rumConfiguration,
);

await datadog.DatadogSdk.runApp(datadogConfiguration, runner);
await datadog.DatadogSdk.runApp(
datadogConfiguration,
configuration.trackingConsent.consent,
runner,
);
}
}
2 changes: 1 addition & 1 deletion packages/deriv_datadog/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
flutter:
sdk: flutter

datadog_flutter_plugin: ^1.3.2
datadog_flutter_plugin: ^2.9.0

dev_dependencies:
flutter_test:
Expand Down
Loading