1
- import { BaseClient , Scope , SDK_VERSION } from '@sentry/core' ;
1
+ import { BaseClient , getEnvelopeEndpointWithUrlEncodedAuth , initAPIDetails , Scope , SDK_VERSION } from '@sentry/core' ;
2
2
import { SessionFlusher } from '@sentry/hub' ;
3
- import { Event , EventHint } from '@sentry/types' ;
4
- import { logger } from '@sentry/utils' ;
3
+ import { Event , EventHint , Severity , Transport , TransportOptions } from '@sentry/types' ;
4
+ import { logger , makeDsn , resolvedSyncPromise } from '@sentry/utils' ;
5
5
6
6
import { NodeBackend } from './backend' ;
7
+ import { eventFromMessage , eventFromUnknownInput } from './eventbuilder' ;
7
8
import { IS_DEBUG_BUILD } from './flags' ;
9
+ import { HTTPSTransport , HTTPTransport , makeNodeTransport } from './transports' ;
8
10
import { NodeOptions } from './types' ;
9
11
10
12
/**
11
13
* The Sentry Node SDK Client.
12
14
*
13
15
* @see NodeOptions for documentation on configuration options.
14
16
* @see SentryClient for usage documentation.
17
+ *
18
+ * TODO: remove NodeBackend
15
19
*/
16
20
export class NodeClient extends BaseClient < NodeBackend , NodeOptions > {
17
21
protected _sessionFlusher : SessionFlusher | undefined ;
@@ -33,6 +37,7 @@ export class NodeClient extends BaseClient<NodeBackend, NodeOptions> {
33
37
version : SDK_VERSION ,
34
38
} ;
35
39
40
+ // TODO: remove NodeBackend param
36
41
super ( NodeBackend , options ) ;
37
42
}
38
43
@@ -106,6 +111,21 @@ export class NodeClient extends BaseClient<NodeBackend, NodeOptions> {
106
111
}
107
112
}
108
113
114
+ /**
115
+ * @inheritDoc
116
+ */
117
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
118
+ public eventFromException ( exception : any , hint ?: EventHint ) : PromiseLike < Event > {
119
+ return resolvedSyncPromise ( eventFromUnknownInput ( exception , hint ) ) ;
120
+ }
121
+
122
+ /**
123
+ * @inheritDoc
124
+ */
125
+ public eventFromMessage ( message : string , level : Severity = Severity . Info , hint ?: EventHint ) : PromiseLike < Event > {
126
+ return resolvedSyncPromise ( eventFromMessage ( message , level , hint , this . _options . attachStacktrace ) ) ;
127
+ }
128
+
109
129
/**
110
130
* @inheritDoc
111
131
*/
@@ -128,4 +148,45 @@ export class NodeClient extends BaseClient<NodeBackend, NodeOptions> {
128
148
this . _sessionFlusher . incrementSessionStatusCount ( ) ;
129
149
}
130
150
}
151
+
152
+ /**
153
+ * @inheritDoc
154
+ */
155
+ protected _setupTransport ( ) : Transport {
156
+ if ( ! this . _options . dsn ) {
157
+ // We return the noop transport here in case there is no Dsn.
158
+ return super . _setupTransport ( ) ;
159
+ }
160
+
161
+ const dsn = makeDsn ( this . _options . dsn ) ;
162
+
163
+ const transportOptions : TransportOptions = {
164
+ ...this . _options . transportOptions ,
165
+ ...( this . _options . httpProxy && { httpProxy : this . _options . httpProxy } ) ,
166
+ ...( this . _options . httpsProxy && { httpsProxy : this . _options . httpsProxy } ) ,
167
+ ...( this . _options . caCerts && { caCerts : this . _options . caCerts } ) ,
168
+ dsn : this . _options . dsn ,
169
+ tunnel : this . _options . tunnel ,
170
+ _metadata : this . _options . _metadata ,
171
+ } ;
172
+
173
+ if ( this . _options . transport ) {
174
+ return new this . _options . transport ( transportOptions ) ;
175
+ }
176
+
177
+ const api = initAPIDetails ( transportOptions . dsn , transportOptions . _metadata , transportOptions . tunnel ) ;
178
+ const url = getEnvelopeEndpointWithUrlEncodedAuth ( api . dsn , api . tunnel ) ;
179
+
180
+ this . _newTransport = makeNodeTransport ( {
181
+ url,
182
+ headers : transportOptions . headers ,
183
+ proxy : transportOptions . httpProxy ,
184
+ caCerts : transportOptions . caCerts ,
185
+ } ) ;
186
+
187
+ if ( dsn . protocol === 'http' ) {
188
+ return new HTTPTransport ( transportOptions ) ;
189
+ }
190
+ return new HTTPSTransport ( transportOptions ) ;
191
+ }
131
192
}
0 commit comments