(scope: Scope)
| 17 | * Hooks into the scope set methods and sync new data added to the given scope with the native SDKs. |
| 18 | */ |
| 19 | export function enableSyncToNative(scope: Scope): void { |
| 20 | if (syncedToNativeMap.has(scope)) { |
| 21 | return; |
| 22 | } |
| 23 | syncedToNativeMap.set(scope, true); |
| 24 | |
| 25 | fillTyped(scope, 'setUser', original => (user): Scope => { |
| 26 | NATIVE.setUser(user); |
| 27 | return original.call(scope, user); |
| 28 | }); |
| 29 | |
| 30 | fillTyped(scope, 'setTag', original => (key, value): Scope => { |
| 31 | NATIVE.setTag(key, NATIVE.primitiveProcessor(value)); |
| 32 | return original.call(scope, key, value); |
| 33 | }); |
| 34 | |
| 35 | fillTyped(scope, 'setTags', original => (tags): Scope => { |
| 36 | // As native only has setTag, we just loop through each tag key. |
| 37 | Object.keys(tags).forEach(key => { |
| 38 | NATIVE.setTag(key, NATIVE.primitiveProcessor(tags[key])); |
| 39 | }); |
| 40 | return original.call(scope, tags); |
| 41 | }); |
| 42 | |
| 43 | fillTyped(scope, 'setExtras', original => (extras): Scope => { |
| 44 | Object.keys(extras).forEach(key => { |
| 45 | NATIVE.setExtra(key, extras[key]); |
| 46 | }); |
| 47 | return original.call(scope, extras); |
| 48 | }); |
| 49 | |
| 50 | fillTyped(scope, 'setExtra', original => (key, value): Scope => { |
| 51 | NATIVE.setExtra(key, value); |
| 52 | return original.call(scope, key, value); |
| 53 | }); |
| 54 | |
| 55 | fillTyped(scope, 'addBreadcrumb', original => (breadcrumb, maxBreadcrumbs): Scope => { |
| 56 | const mergedBreadcrumb: Breadcrumb = { |
| 57 | ...breadcrumb, |
| 58 | level: breadcrumb.level || DEFAULT_BREADCRUMB_LEVEL, |
| 59 | data: breadcrumb.data ? convertToNormalizedObject(breadcrumb.data) : undefined, |
| 60 | }; |
| 61 | |
| 62 | original.call(scope, mergedBreadcrumb, maxBreadcrumbs); |
| 63 | |
| 64 | const finalBreadcrumb = scope.getLastBreadcrumb(); |
| 65 | if (finalBreadcrumb) { |
| 66 | NATIVE.addBreadcrumb(finalBreadcrumb); |
| 67 | } else { |
| 68 | logger.warn('[ScopeSync] Last created breadcrumb is undefined. Skipping sync to native.'); |
| 69 | } |
| 70 | |
| 71 | return scope; |
| 72 | }); |
| 73 | |
| 74 | fillTyped(scope, 'clearBreadcrumbs', original => (): Scope => { |
| 75 | NATIVE.clearBreadcrumbs(); |
| 76 | return original.call(scope); |
no test coverage detected