|
4 | 4 | * Copyright 2016-Present Datadog, Inc. |
5 | 5 | */ |
6 | 6 |
|
7 | | -import { InternalLog } from '../../../InternalLog'; |
8 | | -import { SdkVerbosity } from '../../../SdkVerbosity'; |
9 | | -import DdNativeRum from '../../../specs/NativeDdRum'; |
10 | 7 | import DdSdk from '../../../specs/NativeDdSdk'; |
11 | 8 | import { DefaultTimeProvider } from '../../../utils/time-provider/DefaultTimeProvider'; |
12 | 9 | import type { TimeProvider } from '../../../utils/time-provider/TimeProvider'; |
| 10 | +import type { DdRum } from '../../DdRum'; |
13 | 11 | import { BABEL_PLUGIN_TELEMETRY } from '../../constants'; |
14 | 12 | import type { RumActionType } from '../../types'; |
15 | 13 | import { ActionSource } from '../../types'; |
@@ -46,19 +44,27 @@ export class DdBabelInteractionTracking { |
46 | 44 |
|
47 | 45 | private telemetrySent: boolean = false; |
48 | 46 |
|
| 47 | + private ddRum: typeof DdRum | null = null; |
| 48 | + |
49 | 49 | isInitialized: boolean = false; |
50 | 50 |
|
51 | | - private constructor() { |
| 51 | + private constructor(ddRum?: typeof DdRum) { |
52 | 52 | if (DdBabelInteractionTracking.instance) { |
53 | 53 | throw new Error(StateErrors.ALREADY_INITIALIZED); |
54 | 54 | } |
55 | 55 |
|
| 56 | + if (ddRum) { |
| 57 | + this.ddRum = ddRum; |
| 58 | + } |
| 59 | + |
56 | 60 | DdBabelInteractionTracking.instance = this; |
57 | 61 | } |
58 | 62 |
|
59 | | - static getInstance() { |
| 63 | + static getInstance(ddRum?: typeof DdRum) { |
60 | 64 | if (!DdBabelInteractionTracking.instance) { |
61 | | - DdBabelInteractionTracking.instance = new DdBabelInteractionTracking(); |
| 65 | + DdBabelInteractionTracking.instance = new DdBabelInteractionTracking( |
| 66 | + ddRum |
| 67 | + ); |
62 | 68 | } |
63 | 69 |
|
64 | 70 | return DdBabelInteractionTracking.instance; |
@@ -150,17 +156,22 @@ export class DdBabelInteractionTracking { |
150 | 156 | const { trackInteractions } = DdBabelInteractionTracking.config; |
151 | 157 |
|
152 | 158 | 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 | + }); |
164 | 175 | } |
165 | 176 |
|
166 | 177 | return result; |
|
0 commit comments