Skip to content

Commit 7668dfc

Browse files
authored
Merge pull request #976 from DataDog/carlosnogueira/RUM-11612/fix-babel-auto-instrumented-actions
[RUM-11612] Fix babel instrumented actions not being buffered and intercepted by `actionEventMapper`
2 parents 5eb62df + bb5050e commit 7668dfc

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

packages/core/src/DdSdkReactNative.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ export class DdSdkReactNative {
367367
trackInteractions: configuration.trackInteractions,
368368
useAccessibilityLabel: configuration.useAccessibilityLabel
369369
};
370+
371+
DdBabelInteractionTracking.getInstance(DdRum);
370372
}
371373

372374
if (DdSdkReactNative.wasAutoInstrumented) {

packages/core/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
* Copyright 2016-Present Datadog, Inc.
55
*/
66

7-
import { InternalLog } from '../../../InternalLog';
8-
import { SdkVerbosity } from '../../../SdkVerbosity';
9-
import DdNativeRum from '../../../specs/NativeDdRum';
107
import DdSdk from '../../../specs/NativeDdSdk';
118
import { DefaultTimeProvider } from '../../../utils/time-provider/DefaultTimeProvider';
129
import type { TimeProvider } from '../../../utils/time-provider/TimeProvider';
10+
import type { DdRum } from '../../DdRum';
1311
import { BABEL_PLUGIN_TELEMETRY } from '../../constants';
1412
import type { RumActionType } from '../../types';
1513
import { ActionSource } from '../../types';
@@ -46,19 +44,27 @@ export class DdBabelInteractionTracking {
4644

4745
private telemetrySent: boolean = false;
4846

47+
private ddRum: typeof DdRum | null = null;
48+
4949
isInitialized: boolean = false;
5050

51-
private constructor() {
51+
private constructor(ddRum?: typeof DdRum) {
5252
if (DdBabelInteractionTracking.instance) {
5353
throw new Error(StateErrors.ALREADY_INITIALIZED);
5454
}
5555

56+
if (ddRum) {
57+
this.ddRum = ddRum;
58+
}
59+
5660
DdBabelInteractionTracking.instance = this;
5761
}
5862

59-
static getInstance() {
63+
static getInstance(ddRum?: typeof DdRum) {
6064
if (!DdBabelInteractionTracking.instance) {
61-
DdBabelInteractionTracking.instance = new DdBabelInteractionTracking();
65+
DdBabelInteractionTracking.instance = new DdBabelInteractionTracking(
66+
ddRum
67+
);
6268
}
6369

6470
return DdBabelInteractionTracking.instance;
@@ -150,17 +156,22 @@ export class DdBabelInteractionTracking {
150156
const { trackInteractions } = DdBabelInteractionTracking.config;
151157

152158
if (trackInteractions) {
153-
InternalLog.log(
154-
`Adding RUM Action “${targetName}” (${action}, auto)`,
155-
SdkVerbosity.DEBUG
156-
);
157-
158-
DdNativeRum?.addAction(
159-
action,
160-
targetName,
161-
{ '__dd.action_source': ActionSource.BABEL },
162-
this.timeProvider.now()
163-
);
159+
this.ddRum
160+
?.addAction(
161+
action,
162+
targetName,
163+
{ '__dd.action_source': ActionSource.BABEL },
164+
this.timeProvider.now()
165+
)
166+
.catch(e => {
167+
if (e instanceof Error) {
168+
DdSdk?.telemetryError(
169+
e.message,
170+
e.stack || '',
171+
'BabelActionTrack'
172+
);
173+
}
174+
});
164175
}
165176

166177
return result;

0 commit comments

Comments
 (0)