1
- import type { EventProcessor , Hub , Integration } from '@sentry/types' ;
1
+ import type { Integration } from '@sentry/types' ;
2
2
import type { FullStoryClient } from './types' ;
3
3
import {
4
4
doesFullStoryExist ,
5
+ getFullStoryUrl ,
5
6
getOriginalExceptionProperties ,
6
7
getSentryUrl ,
7
8
} from './util' ;
@@ -17,83 +18,56 @@ type Options = {
17
18
baseSentryUrl ?: string ;
18
19
} ;
19
20
20
- class SentryFullStory implements Integration {
21
- public readonly name : string = SentryFullStory . id ;
22
- public static id : string = 'SentryFullStory' ;
23
- sentryOrg : string ;
24
- baseSentryUrl : string ;
25
- client : FullStoryClient ;
26
-
27
- constructor ( sentryOrg : string , options : Options ) {
28
- this . sentryOrg = sentryOrg ;
29
- this . client = options . client ;
30
- this . baseSentryUrl = options . baseSentryUrl || 'https://sentry.io' ;
31
- }
32
-
33
- getFullStoryUrl = ( ) : Promise < string > | string => {
34
- // getCurrentSessionURL isn't available until after the FullStory script is fully bootstrapped.
35
- // If an error occurs before getCurrentSessionURL is ready, make a note in Sentry and move on.
36
- // More on getCurrentSessionURL here: https://help.fullstory.com/develop-js/getcurrentsessionurl
37
- try {
38
- const res = this . client . getCurrentSessionURL ?.( true ) ;
39
- if ( ! res ) {
40
- throw new Error ( 'No FullStory session URL found' ) ;
41
- }
42
-
43
- return res ;
44
- } catch ( e ) {
45
- const reason = e instanceof Error ? e . message : String ( e ) ;
46
- throw new Error ( `Unable to get url: ${ reason } ` ) ;
47
- }
48
- } ;
21
+ const INTEGRATION_NAME = 'SentryFullStory' ;
49
22
50
- setupOnce (
51
- addGlobalEventProcessor : ( callback : EventProcessor ) => void ,
52
- getCurrentHub : ( ) => Hub
53
- ) {
54
- let fullStoryUrl : string | undefined ;
23
+ export function fullStoryIntegration (
24
+ sentryOrg : string ,
25
+ options : Options
26
+ ) : Integration {
27
+ const fullStoryClient = options . client ;
28
+ const baseSentryUrl = options . baseSentryUrl || 'https://sentry.io' ;
29
+ let fullStoryUrl : string | undefined ;
55
30
56
- addGlobalEventProcessor ( async ( event , hint ) => {
57
- const hub = getCurrentHub ( ) ;
58
- const self = hub . getIntegration ( SentryFullStory ) ;
31
+ return {
32
+ name : INTEGRATION_NAME ,
33
+ async processEvent ( event , hint , client ) {
34
+ const self = client . getIntegrationByName ( INTEGRATION_NAME ) ;
59
35
// Run the integration ONLY when it was installed on the current Hub AND isn't a transaction
60
- if ( self && event . type !== 'transaction' && doesFullStoryExist ( ) ) {
36
+ if ( self && event . type === undefined && doesFullStoryExist ( ) ) {
61
37
if ( ! fullStoryUrl ) {
62
38
try {
63
- fullStoryUrl = await this . getFullStoryUrl ( ) ;
39
+ fullStoryUrl = await getFullStoryUrl ( fullStoryClient ) ;
64
40
} catch ( e ) {
65
41
const reason = e instanceof Error ? e . message : String ( e ) ;
66
42
console . error ( `Unable to get FullStory session URL: ${ reason } ` ) ;
67
43
}
68
44
}
45
+ }
69
46
70
- if ( fullStoryUrl ) {
71
- event . contexts = {
72
- ...event . contexts ,
73
- fullStory : {
74
- fullStoryUrl,
75
- } ,
76
- } ;
77
- }
47
+ if ( fullStoryUrl ) {
48
+ event . contexts = {
49
+ ...event . contexts ,
50
+ fullStory : {
51
+ fullStoryUrl,
52
+ } ,
53
+ } ;
54
+ }
78
55
79
- try {
80
- this . client . event ( 'Sentry Error' , {
81
- sentryUrl : getSentryUrl ( {
82
- baseSentryUrl : this . baseSentryUrl ,
83
- sentryOrg : this . sentryOrg ,
84
- hint,
85
- hub,
86
- } ) ,
87
- ...getOriginalExceptionProperties ( hint ) ,
88
- } ) ;
89
- } catch ( e ) {
90
- console . debug ( 'Unable to report sentry error details to FullStory' ) ;
91
- }
56
+ try {
57
+ fullStoryClient . event ( 'Sentry Error' , {
58
+ sentryUrl : getSentryUrl ( {
59
+ baseSentryUrl : baseSentryUrl ,
60
+ sentryOrg,
61
+ hint,
62
+ client,
63
+ } ) ,
64
+ ...getOriginalExceptionProperties ( hint ) ,
65
+ } ) ;
66
+ } catch ( e ) {
67
+ console . debug ( 'Unable to report sentry error details to FullStory' ) ;
92
68
}
93
69
94
70
return event ;
95
- } ) ;
96
- }
71
+ } ,
72
+ } ;
97
73
}
98
-
99
- export default SentryFullStory ;
0 commit comments