1- import { BrowserClient , defaultStackParser , makeFetchTransport } from '@sentry/browser' ;
1+ import { eventFromException , eventFromMessage , makeFetchTransport } from '@sentry/browser' ;
22import { FetchImpl } from '@sentry/browser/types/transports/utils' ;
33import { BaseClient } from '@sentry/core' ;
44import {
@@ -7,8 +7,10 @@ import {
77 Envelope ,
88 Event ,
99 EventHint ,
10+ Exception ,
1011 Outcome ,
1112 SeverityLevel ,
13+ Thread ,
1214 Transport ,
1315 UserFeedback ,
1416} from '@sentry/types' ;
@@ -34,26 +36,24 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
3436
3537 private _outcomesBuffer : Outcome [ ] ;
3638
37- private readonly _browserClient : BrowserClient ;
38-
3939 /**
4040 * Creates a new React Native SDK instance.
4141 * @param options Configuration options for this SDK.
4242 */
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 = [ ] ;
5757
5858 // This is a workaround for now using fetch on RN, this is a known issue in react-native and only generates a warning
5959 // YellowBox deprecated and replaced with with LogBox in RN 0.63
@@ -65,33 +65,45 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
6565 YellowBox . ignoreWarnings ( [ 'Require cycle:' ] ) ;
6666 }
6767
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+ }
8070
8171
8272 /**
8373 * @inheritDoc
8474 */
8575 public eventFromException ( exception : unknown , hint : EventHint = { } ) : PromiseLike < Event > {
8676 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+ ) ) ;
8883 }
8984
9085 /**
9186 * @inheritDoc
9287 */
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+ } ) ;
95107 }
96108
97109 /**
0 commit comments