Skip to content

Commit e1771eb

Browse files
committed
port NodeBackend to NodeClient
1 parent 64dc255 commit e1771eb

File tree

1 file changed

+64
-3
lines changed

1 file changed

+64
-3
lines changed

packages/node/src/client.ts

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
1+
import { BaseClient, getEnvelopeEndpointWithUrlEncodedAuth, initAPIDetails, Scope, SDK_VERSION } from '@sentry/core';
22
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';
55

66
import { NodeBackend } from './backend';
7+
import { eventFromMessage, eventFromUnknownInput } from './eventbuilder';
78
import { IS_DEBUG_BUILD } from './flags';
9+
import { HTTPSTransport, HTTPTransport, makeNodeTransport } from './transports';
810
import { NodeOptions } from './types';
911

1012
/**
1113
* The Sentry Node SDK Client.
1214
*
1315
* @see NodeOptions for documentation on configuration options.
1416
* @see SentryClient for usage documentation.
17+
*
18+
* TODO: remove NodeBackend
1519
*/
1620
export class NodeClient extends BaseClient<NodeBackend, NodeOptions> {
1721
protected _sessionFlusher: SessionFlusher | undefined;
@@ -33,6 +37,7 @@ export class NodeClient extends BaseClient<NodeBackend, NodeOptions> {
3337
version: SDK_VERSION,
3438
};
3539

40+
// TODO: remove NodeBackend param
3641
super(NodeBackend, options);
3742
}
3843

@@ -106,6 +111,21 @@ export class NodeClient extends BaseClient<NodeBackend, NodeOptions> {
106111
}
107112
}
108113

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+
109129
/**
110130
* @inheritDoc
111131
*/
@@ -128,4 +148,45 @@ export class NodeClient extends BaseClient<NodeBackend, NodeOptions> {
128148
this._sessionFlusher.incrementSessionStatusCount();
129149
}
130150
}
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+
}
131192
}

0 commit comments

Comments
 (0)