-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathddUtils.tsx
More file actions
113 lines (101 loc) · 3.7 KB
/
Copy pathddUtils.tsx
File metadata and controls
113 lines (101 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import {
DatadogProviderConfiguration,
DdLogs,
DdRum,
DdSdkReactNative,
CoreConfiguration,
SdkVerbosity,
TrackingConsent,
BatchSize,
UploadFrequency,
DdFlags,
PropagatorType,
} from '@datadog/mobile-react-native';
import { DatadogOpenFeatureProvider } from '@datadog/mobile-react-native-openfeature';
import { OpenFeature } from '@openfeature/react-sdk';
import {APPLICATION_ID, CLIENT_TOKEN, ENVIRONMENT} from './ddCredentials';
import { BatchProcessingLevel } from '@datadog/mobile-react-native/src/config/types';
// New SDK Setup - not available for react-native-navigation
export function getDatadogConfig(trackingConsent: TrackingConsent) {
const config = new DatadogProviderConfiguration(
CLIENT_TOKEN,
ENVIRONMENT,
trackingConsent,
{
batchSize: BatchSize.SMALL,
uploadFrequency: UploadFrequency.FREQUENT,
batchProcessingLevel: BatchProcessingLevel.MEDIUM,
additionalConfiguration: {
customProperty: "sdk-example-app"
},
rumConfiguration: {
applicationId: APPLICATION_ID,
trackInteractions: true,
trackResources: true,
trackErrors: true,
sessionSampleRate: 100,
nativeCrashReportEnabled: true,
firstPartyHosts: [{
match: "example.com",
propagatorTypes: [PropagatorType.B3MULTI, PropagatorType.TRACECONTEXT]
}]
},
logsConfiguration: {
logEventMapper: (logEvent) => {
logEvent.message = `[CUSTOM] ${logEvent.message}`;
return logEvent;
}
},
traceConfiguration: {}
}
);
config.service = "com.datadoghq.reactnative.sample"
config.verbosity = SdkVerbosity.DEBUG;
return config
}
export function onDatadogInitialization() {
DdLogs.info('The RN Sdk was properly initialized')
DdSdkReactNative.setUserInfo({id: "1337", name: "Xavier", email: "xg@example.com", extraInfo: { type: "premium" } })
DdSdkReactNative.addAttributes({campaign: "ad-network"})
setTimeout(async () => {
await DdRum.reportAppFullyDisplayed();
}, 5000);
}
// Legacy SDK Setup
export function initializeDatadog(trackingConsent: TrackingConsent) {
const config = new CoreConfiguration(
CLIENT_TOKEN,
ENVIRONMENT,
trackingConsent,
{
rumConfiguration: {
applicationId: APPLICATION_ID,
trackInteractions: true,
trackResources: true,
trackErrors: true,
sessionSampleRate: 100,
nativeCrashReportEnabled: true,
firstPartyHosts: [{
match: "example.com",
propagatorTypes: [PropagatorType.B3MULTI, PropagatorType.TRACECONTEXT]
}]
}
}
)
config.verbosity = SdkVerbosity.DEBUG;
config.service = "com.datadoghq.reactnative.sample"
DdSdkReactNative.initialize(config).then(() => {
DdLogs.info('The RN Sdk was properly initialized')
DdSdkReactNative.setUserInfo({id: "1337", name: "Xavier", email: "xg@example.com", extraInfo: { type: "premium" } })
DdSdkReactNative.addAttributes({campaign: "ad-network"})
setTimeout(async () => {
await DdRum.reportAppFullyDisplayed();
}, 5000);
});
// Enable the Flags feature.
DdFlags.enable().then(() => {
// Set the provider with OpenFeature.
const provider = new DatadogOpenFeatureProvider();
OpenFeature.setProvider(provider);
})
}