1
- import { BrowserClient , defaultStackParser , makeFetchTransport } from '@sentry/browser' ;
1
+ import { eventFromException , eventFromMessage , makeFetchTransport } from '@sentry/browser' ;
2
2
import { FetchImpl } from '@sentry/browser/types/transports/utils' ;
3
3
import { BaseClient } from '@sentry/core' ;
4
4
import {
@@ -7,8 +7,10 @@ import {
7
7
Envelope ,
8
8
Event ,
9
9
EventHint ,
10
+ Exception ,
10
11
Outcome ,
11
12
SeverityLevel ,
13
+ Thread ,
12
14
Transport ,
13
15
UserFeedback ,
14
16
} from '@sentry/types' ;
@@ -34,26 +36,24 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
34
36
35
37
private _outcomesBuffer : Outcome [ ] ;
36
38
37
- private readonly _browserClient : BrowserClient ;
38
-
39
39
/**
40
40
* Creates a new React Native SDK instance.
41
41
* @param options Configuration options for this SDK.
42
42
*/
43
- public constructor ( options : ReactNativeClientOptions ) {
44
- if ( ! options . transport ) {
45
- options . transport = ( options : ReactNativeTransportOptions , nativeFetch ?: FetchImpl ) : Transport => {
46
- if ( NATIVE . isNativeTransportAvailable ( ) ) {
47
- return makeReactNativeTransport ( options ) ;
48
- }
49
- return makeFetchTransport ( options , nativeFetch ) ;
50
- } ;
51
- }
52
- options . _metadata = options . _metadata || { } ;
53
- options . _metadata . sdk = options . _metadata . sdk || defaultSdkInfo ;
54
- super ( options ) ;
55
-
56
- this . _outcomesBuffer = [ ] ;
43
+ public constructor ( options : ReactNativeClientOptions ) {
44
+ if ( ! options . transport ) {
45
+ options . transport = ( options : ReactNativeTransportOptions , nativeFetch ?: FetchImpl ) : Transport => {
46
+ if ( NATIVE . isNativeTransportAvailable ( ) ) {
47
+ return makeReactNativeTransport ( options ) ;
48
+ }
49
+ return makeFetchTransport ( options , nativeFetch ) ;
50
+ } ;
51
+ }
52
+ options . _metadata = options . _metadata || { } ;
53
+ options . _metadata . sdk = options . _metadata . sdk || defaultSdkInfo ;
54
+ super ( options ) ;
55
+
56
+ this . _outcomesBuffer = [ ] ;
57
57
58
58
// This is a workaround for now using fetch on RN, this is a known issue in react-native and only generates a warning
59
59
// YellowBox deprecated and replaced with with LogBox in RN 0.63
@@ -65,33 +65,45 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
65
65
YellowBox . ignoreWarnings ( [ 'Require cycle:' ] ) ;
66
66
}
67
67
68
- this . _browserClient = new BrowserClient ( {
69
- dsn : options . dsn ,
70
- transport : options . transport ,
71
- transportOptions : options . transportOptions ,
72
- stackParser : options . stackParser || defaultStackParser ,
73
- integrations : [ ] ,
74
- _metadata : options . _metadata ,
75
- attachStacktrace : options . attachStacktrace ,
76
- } ) ;
77
-
78
- void this . _initNativeSdk ( ) ;
79
- }
68
+ void this . _initNativeSdk ( ) ;
69
+ }
80
70
81
71
82
72
/**
83
73
* @inheritDoc
84
74
*/
85
75
public eventFromException ( exception : unknown , hint : EventHint = { } ) : PromiseLike < Event > {
86
76
return Screenshot . attachScreenshotToEventHint ( hint , this . _options )
87
- . then ( enrichedHint => this . _browserClient . eventFromException ( exception , enrichedHint ) ) ;
77
+ . then ( hintWithScreenshot => eventFromException (
78
+ this . _options . stackParser ,
79
+ exception ,
80
+ hintWithScreenshot ,
81
+ this . _options . attachStacktrace ,
82
+ ) ) ;
88
83
}
89
84
90
85
/**
91
86
* @inheritDoc
92
87
*/
93
- public eventFromMessage ( _message : string , _level ?: SeverityLevel , _hint ?: EventHint ) : PromiseLike < Event > {
94
- return this . _browserClient . eventFromMessage ( _message , _level , _hint ) ;
88
+ public eventFromMessage ( message : string , level ?: SeverityLevel , hint ?: EventHint ) : PromiseLike < Event > {
89
+ return eventFromMessage (
90
+ this . _options . stackParser ,
91
+ message ,
92
+ level ,
93
+ hint ,
94
+ this . _options . attachStacktrace ,
95
+ ) . then ( ( event : Event ) => {
96
+ // TMP! Remove this function once JS SDK uses threads for messages
97
+ if ( ! event . exception ?. values || event . exception . values . length <= 0 ) {
98
+ return event ;
99
+ }
100
+ const values = event . exception . values . map ( ( exception : Exception ) : Thread => ( {
101
+ stacktrace : exception . stacktrace ,
102
+ } ) ) ;
103
+ ( event as { threads ?: { values : Thread [ ] } } ) . threads = { values } ;
104
+ delete event . exception ;
105
+ return event ;
106
+ } ) ;
95
107
}
96
108
97
109
/**
0 commit comments