Skip to content

Commit 1522dc9

Browse files
authored
Merge pull request #1089 from DataDog/marcosaia/chore/refactor-init-apis
[CHORE] [V3] Refactor Initialization APIs
2 parents 6efb940 + 6cfc1bd commit 1522dc9

File tree

105 files changed

+2851
-1983
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+2851
-1983
lines changed

benchmarks/src/testSetup/testUtils.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
DatadogProviderConfiguration,
1010
DdSdkReactNative,
1111
CoreConfiguration,
12-
RumConfiguration,
1312
SdkVerbosity,
1413
TrackingConsent
1514
} from '@datadog/mobile-react-native';
@@ -41,14 +40,25 @@ export const getDatadogProviderConfig = () => {
4140
let config = new DatadogProviderConfiguration(
4241
baseConfig.clientToken ?? '',
4342
baseConfig.env ?? '',
44-
TrackingConsent.GRANTED
43+
TrackingConsent.GRANTED,
44+
{
45+
rumConfiguration: {
46+
applicationId: baseConfig.applicationID ?? '',
47+
trackInteractions: true,
48+
trackResources: true,
49+
trackErrors: true,
50+
sessionSampleRate: 100,
51+
nativeCrashReportEnabled: true
52+
},
53+
logsConfiguration: {
54+
bundleLogsWithRum: true,
55+
bundleLogsWithTraces: true,
56+
},
57+
traceConfiguration: {}
58+
}
4559
);
4660
config.service = `com.rn.${platform}.benchmark`
4761
config.verbosity = SdkVerbosity.DEBUG;
48-
config.nativeCrashReportEnabled = true
49-
50-
config.rumConfiguration = new RumConfiguration(baseConfig.applicationID ?? '', true, true, true);
51-
config.rumConfiguration.sessionSampleRate = 100;
5262

5363
return config;
5464
};
@@ -58,13 +68,25 @@ export const initializeDatadog = (clientToken?: string, environment?: string, ap
5868
const config = new CoreConfiguration(
5969
clientToken ?? '',
6070
environment ?? '',
61-
TrackingConsent.GRANTED
71+
TrackingConsent.GRANTED,
72+
{
73+
rumConfiguration: {
74+
applicationId: appId ?? "",
75+
trackInteractions: true,
76+
trackResources: true,
77+
trackErrors: true,
78+
sessionSampleRate: 100,
79+
nativeCrashReportEnabled: true,
80+
},
81+
logsConfiguration: {
82+
bundleLogsWithRum: true,
83+
bundleLogsWithTraces: true,
84+
},
85+
traceConfiguration: {}
86+
}
6287
);
6388
config.service = `com.rn.${platform}.benchmark`
6489
config.verbosity = SdkVerbosity.DEBUG;
65-
config.nativeCrashReportEnabled = true
66-
config.rumConfiguration = new RumConfiguration(appId ?? '', true, true, true)
67-
config.rumConfiguration.sessionSampleRate = 100;
6890

6991
return DdSdkReactNative.initialize(config);
7092
};

example-new-architecture/App.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
RumActionType,
99
DdLogs,
1010
DdTrace,
11-
RumConfiguration,
11+
TrackingConsent,
1212
} from '@datadog/mobile-react-native';
1313
import React from 'react';
1414
import type {PropsWithChildren} from 'react';
@@ -36,18 +36,21 @@ import {APPLICATION_ID, CLIENT_TOKEN, ENVIRONMENT} from './ddCredentials';
3636
const config = new CoreConfiguration(
3737
CLIENT_TOKEN,
3838
ENVIRONMENT,
39+
TrackingConsent.GRANTED,
40+
{
41+
rumConfiguration: {
42+
applicationId: APPLICATION_ID,
43+
trackInteractions: true,
44+
trackResources: true,
45+
trackFrustrations: true,
46+
sessionSampleRate: 100,
47+
telemetrySampleRate: 100
48+
}
49+
}
3950
);
4051
config.verbosity = SdkVerbosity.DEBUG;
4152
config.uploadFrequency = UploadFrequency.FREQUENT;
4253
config.batchSize = BatchSize.SMALL;
43-
config.rumConfiguration = new RumConfiguration(
44-
APPLICATION_ID,
45-
true,
46-
true,
47-
true
48-
)
49-
config.rumConfiguration.sessionSampleRate = 100;
50-
config.rumConfiguration.telemetrySampleRate = 100;
5154

5255
await DdSdkReactNative.initialize(config);
5356
await DdRum.startView('main', 'Main');

example/src/App.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ const configuration = getDatadogConfig(TrackingConsent.GRANTED)
6666
// see https://docs.datadoghq.com/real_user_monitoring/guide/initialize-your-native-sdk-before-react-native-starts
6767

6868
// const configuration = new DatadogProviderConfiguration("fake_value", "fake_value");
69-
// configuration.rumConfiguration = new RumConfiguration("fake_value")
7069

7170
export default function App() {
7271

example/src/ddUtils.tsx

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,49 @@ import {
33
DdLogs,
44
DdSdkReactNative,
55
CoreConfiguration,
6-
RumConfiguration,
76
SdkVerbosity,
8-
TrackingConsent
7+
TrackingConsent,
8+
BatchSize,
9+
UploadFrequency,
910
} from '@datadog/mobile-react-native';
1011

1112
import {APPLICATION_ID, CLIENT_TOKEN, ENVIRONMENT} from './ddCredentials';
13+
import { BatchProcessingLevel } from '@datadog/mobile-react-native/src/config/types';
1214

1315
// New SDK Setup - not available for react-native-navigation
1416
export function getDatadogConfig(trackingConsent: TrackingConsent) {
1517
const config = new DatadogProviderConfiguration(
1618
CLIENT_TOKEN,
1719
ENVIRONMENT,
1820
trackingConsent,
21+
{
22+
batchSize: BatchSize.SMALL,
23+
uploadFrequency: UploadFrequency.FREQUENT,
24+
batchProcessingLevel: BatchProcessingLevel.MEDIUM,
25+
additionalConfiguration: {
26+
customProperty: "sdk-example-app"
27+
},
28+
rumConfiguration: {
29+
applicationId: APPLICATION_ID,
30+
trackInteractions: true,
31+
trackResources: true,
32+
trackErrors: true,
33+
sessionSampleRate: 100,
34+
nativeCrashReportEnabled: true
35+
},
36+
logsConfiguration: {
37+
logEventMapper: (logEvent) => {
38+
logEvent.message = `[CUSTOM] ${logEvent.message}`;
39+
return logEvent;
40+
}
41+
},
42+
traceConfiguration: {}
43+
}
1944
);
2045

2146
config.service = "com.datadoghq.reactnative.sample"
22-
config.nativeCrashReportEnabled = true
2347
config.verbosity = SdkVerbosity.DEBUG;
24-
config.rumConfiguration = new RumConfiguration(APPLICATION_ID, true, true, true);
25-
config.rumConfiguration.sessionSampleRate = 100
48+
2649
return config
2750
}
2851

@@ -38,13 +61,21 @@ export function initializeDatadog(trackingConsent: TrackingConsent) {
3861
const config = new CoreConfiguration(
3962
CLIENT_TOKEN,
4063
ENVIRONMENT,
41-
trackingConsent
64+
trackingConsent,
65+
{
66+
rumConfiguration: {
67+
applicationId: APPLICATION_ID,
68+
trackInteractions: true,
69+
trackResources: true,
70+
trackErrors: true,
71+
sessionSampleRate: 100,
72+
nativeCrashReportEnabled: true
73+
}
74+
}
4275
)
43-
config.nativeCrashReportEnabled = true
76+
4477
config.verbosity = SdkVerbosity.DEBUG;
4578
config.service = "com.datadoghq.reactnative.sample"
46-
config.rumConfiguration = new RumConfiguration(APPLICATION_ID, true, true, true);
47-
config.rumConfiguration.sessionSampleRate = 100
4879

4980
DdSdkReactNative.initialize(config).then(() => {
5081
DdLogs.info('The RN Sdk was properly initialized')

example/src/screens/MainScreen.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { APPLICATION_KEY, API_KEY } from '../../src/ddCredentials';
1414
import { DdLogs, DdSdkReactNative, TrackingConsent } from '@datadog/mobile-react-native';
1515
import { getTrackingConsent, saveTrackingConsent } from '../utils';
1616
import { ConsentModal } from '../components/consent';
17-
import { DdRum } from '../../../packages/core/src/rum/DdRum';
1817

1918
const axios = require('../axiosConfig');
2019

packages/codepush/src/__tests__/index.test.tsx

Lines changed: 52 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jest.mock('@datadog/mobile-react-native', () => {
2020
const flushPromises = () =>
2121
new Promise(jest.requireActual('timers').setImmediate);
2222

23-
const createCodepushPackageMock = label => ({
23+
const createCodepushPackageMock = (label: string | null) => ({
2424
label,
2525
isMandatory: false,
2626
install: jest.fn(),
@@ -285,23 +285,28 @@ describe('AppCenter Codepush integration', () => {
285285
} = require('@datadog/mobile-react-native');
286286

287287
const autoInstrumentationConfig = {
288+
clientToken: 'fake-client-token',
289+
env: 'fake-env',
288290
rumConfiguration: {
291+
applicationId: 'fake-app-id',
292+
useAccessibilityLabel: true,
289293
actionNameAttribute: 'test-action-name-attr',
290294
trackErrors: true,
291295
trackResources: true,
292-
trackInteractions: true
296+
trackInteractions: true,
297+
resourceTraceSampleRate: 100,
298+
nativeCrashReportEnabled: true,
299+
nativeLongTaskThresholdMs: false,
300+
nativeViewTracking: true,
301+
firstPartyHosts: [
302+
{
303+
match: 'example.com',
304+
propagatorTypes: [PropagatorType.DATADOG]
305+
}
306+
]
293307
},
294-
firstPartyHosts: [
295-
{
296-
match: 'example.com',
297-
propagatorTypes: [PropagatorType.DATADOG]
298-
}
299-
],
300-
useAccessibilityLabel: true,
301308
logsConfiguration: {},
302-
traceConfiguration: {
303-
resourceTraceSampleRate: 100
304-
}
309+
traceConfiguration: {}
305310
};
306311

307312
const configuration = new FileBasedConfiguration({
@@ -320,27 +325,28 @@ describe('AppCenter Codepush integration', () => {
320325
DdSdkReactNative._enableFeaturesFromDatadogProvider
321326
).toHaveBeenCalledWith({
322327
rumConfiguration: {
328+
useAccessibilityLabel: true,
323329
actionNameAttribute: 'test-action-name-attr',
324330
actionEventMapper: null,
331+
nativeCrashReportEnabled: true,
332+
nativeLongTaskThresholdMs: false,
333+
nativeViewTracking: true,
325334
resourceEventMapper: null,
326335
errorEventMapper: null,
327336
trackErrors: true,
328337
trackResources: true,
329-
trackInteractions: true
338+
trackInteractions: true,
339+
resourceTraceSampleRate: 100,
340+
firstPartyHosts: [
341+
{
342+
match: 'example.com',
343+
propagatorTypes: [PropagatorType.DATADOG]
344+
}
345+
]
330346
},
331347
logsConfiguration: {
332348
logEventMapper: null
333-
},
334-
traceConfiguration: {
335-
resourceTraceSampleRate: 100
336-
},
337-
firstPartyHosts: [
338-
{
339-
match: 'example.com',
340-
propagatorTypes: [PropagatorType.DATADOG]
341-
}
342-
],
343-
useAccessibilityLabel: true
349+
}
344350
});
345351

346352
expect(
@@ -358,27 +364,14 @@ describe('AppCenter Codepush integration', () => {
358364
const { DatadogCodepushProvider } = require('..');
359365
const {
360366
DdSdkReactNative,
361-
PropagatorType,
362367
FileBasedConfiguration
363368
} = require('@datadog/mobile-react-native');
364369

365370
const autoInstrumentationConfig = {
371+
clientToken: 'fake-client-token',
372+
env: 'fake-env',
366373
rumConfiguration: {
367-
actionNameAttribute: 'test-action-name-attr',
368-
trackErrors: true,
369-
trackResources: true,
370-
trackInteractions: true
371-
},
372-
logsConfiguration: {},
373-
firstPartyHosts: [
374-
{
375-
match: 'example.com',
376-
propagatorTypes: [PropagatorType.DATADOG]
377-
}
378-
],
379-
useAccessibilityLabel: true,
380-
traceConfiguration: {
381-
resourceTraceSampleRate: 100
374+
applicationId: 'fake-app-id'
382375
}
383376
};
384377

@@ -396,30 +389,25 @@ describe('AppCenter Codepush integration', () => {
396389
});
397390
expect(
398391
DdSdkReactNative._enableFeaturesFromDatadogProvider
399-
).toHaveBeenCalledWith({
400-
rumConfiguration: {
401-
actionNameAttribute: 'test-action-name-attr',
402-
trackErrors: true,
403-
trackResources: true,
404-
trackInteractions: true,
405-
actionEventMapper: null,
406-
resourceEventMapper: null,
407-
errorEventMapper: null
408-
},
409-
logsConfiguration: {
410-
logEventMapper: null
411-
},
412-
firstPartyHosts: [
413-
{
414-
match: 'example.com',
415-
propagatorTypes: [PropagatorType.DATADOG]
416-
}
417-
],
418-
traceConfiguration: {
419-
resourceTraceSampleRate: 100
420-
},
421-
useAccessibilityLabel: true
422-
});
392+
).toHaveBeenCalledWith(
393+
expect.objectContaining({
394+
rumConfiguration: expect.objectContaining({
395+
useAccessibilityLabel: true,
396+
actionNameAttribute: undefined,
397+
trackErrors: false,
398+
trackResources: false,
399+
trackInteractions: false,
400+
actionEventMapper: null,
401+
resourceEventMapper: null,
402+
errorEventMapper: null,
403+
resourceTraceSampleRate: 100,
404+
firstPartyHosts: []
405+
}),
406+
logsConfiguration: expect.objectContaining({
407+
logEventMapper: null
408+
})
409+
})
410+
);
423411

424412
expect(
425413
DdSdkReactNative._enableFeaturesFromDatadogProvider

0 commit comments

Comments
 (0)