(options: Partial<TracingOptions> = {})
| 59 | } |
| 60 | |
| 61 | export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixins => { |
| 62 | const hooks = (options.hooks || []) |
| 63 | .concat(DEFAULT_HOOKS) |
| 64 | // Removing potential duplicates |
| 65 | .filter((value, index, self) => self.indexOf(value) === index); |
| 66 | |
| 67 | const mixins: Mixins = {}; |
| 68 | |
| 69 | const rootComponentSpanFinalTimeout = options.timeout || 2000; |
| 70 | |
| 71 | for (const operation of hooks) { |
| 72 | // Retrieve corresponding hooks from Vue lifecycle. |
| 73 | // eg. mount => ['beforeMount', 'mounted'] |
| 74 | const internalHooks = HOOKS[operation]; |
| 75 | if (!internalHooks) { |
| 76 | DEBUG_BUILD && debug.warn(`Unknown hook: ${operation}`); |
| 77 | continue; |
| 78 | } |
| 79 | |
| 80 | for (const internalHook of internalHooks) { |
| 81 | mixins[internalHook] = function (this: VueSentry) { |
| 82 | const isRootComponent = this.$root === this; |
| 83 | |
| 84 | // 1. Root Component span creation |
| 85 | if (isRootComponent) { |
| 86 | this.$_sentryRootComponentSpan = |
| 87 | this.$_sentryRootComponentSpan || |
| 88 | startInactiveSpan({ |
| 89 | name: 'Application Render', |
| 90 | op: `${VUE_OP}.render`, |
| 91 | attributes: { |
| 92 | [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.vue', |
| 93 | }, |
| 94 | onlyIfParent: true, |
| 95 | }); |
| 96 | |
| 97 | // call debounced end function once directly, just in case no child components call it |
| 98 | maybeEndRootComponentSpan(this, timestampInSeconds(), rootComponentSpanFinalTimeout); |
| 99 | } |
| 100 | |
| 101 | // 2. Component tracking filter |
| 102 | const componentName = formatComponentName(this, false); |
| 103 | |
| 104 | const shouldTrack = |
| 105 | isRootComponent || // We always want to track the root component |
| 106 | (Array.isArray(options.trackComponents) |
| 107 | ? findTrackComponent(options.trackComponents, componentName) |
| 108 | : options.trackComponents); |
| 109 | |
| 110 | // We always want to track root component |
| 111 | if (!shouldTrack) { |
| 112 | // even if we don't track `this` component, we still want to end the root span eventually |
| 113 | maybeEndRootComponentSpan(this, timestampInSeconds(), rootComponentSpanFinalTimeout); |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | this.$_sentryComponentSpans = this.$_sentryComponentSpans || {}; |
| 118 |
no test coverage detected