Skip to content

Commit 7803fbf

Browse files
author
Luca Forstner
committed
Clarify proxy order for htpp
1 parent dd939ff commit 7803fbf

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as Sentry from '@sentry/node';
2+
3+
Sentry.init({
4+
dsn: 'https://[email protected]/1337',
5+
release: '1.0',
6+
_experiments: {
7+
newTransport: true, // use new transport
8+
},
9+
});
10+
11+
Sentry.captureException(new Error('test_simple_error'));
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { getMultipleEnvelopeRequest, runServer } from '../../../../utils';
2+
3+
test('should correctly send envelope', async () => {
4+
const url = await runServer(__dirname);
5+
const envelopes = await getMultipleEnvelopeRequest(url, 2);
6+
7+
const errorEnvelope = envelopes[1];
8+
9+
expect(errorEnvelope).toHaveLength(3);
10+
expect(errorEnvelope[2]).toMatchObject({
11+
exception: {
12+
values: [
13+
{
14+
type: 'Error',
15+
value: 'test_simple_error',
16+
},
17+
],
18+
},
19+
release: '1.0',
20+
event_id: expect.any(String),
21+
timestamp: expect.any(Number),
22+
});
23+
});

packages/node-integration-tests/utils/index.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,43 @@ export const getEventRequest = async (url: string): Promise<Record<string, unkno
101101
};
102102

103103
/**
104-
* Intercepts and extracts a request containing a Sentry Envelope
105-
*
106-
* @param {string} url
107-
* @return {*} {Promise<Array<Record<string, unknown>>>}
104+
* Intercepts and extracts multiple requests containing a Sentry Envelope
105+
* @param url
106+
* @param count
108107
*/
109-
export const getEnvelopeRequest = async (url: string): Promise<Array<Record<string, unknown>>> => {
108+
export const getMultipleEnvelopeRequest = async (url: string, count: number): Promise<Record<string, unknown>[][]> => {
109+
const envelopes: Record<string, unknown>[][] = [];
110+
110111
return new Promise(resolve => {
111112
nock('https://dsn.ingest.sentry.io')
112113
.post('/api/1337/envelope/', body => {
113114
const envelope = parseEnvelope(body);
114-
resolve(envelope);
115+
envelopes.push(envelope);
116+
117+
if (count === envelopes.length) {
118+
resolve(envelopes);
119+
}
120+
115121
return true;
116122
})
123+
.times(count)
124+
.query(true) // accept any query params - used for sentry_key param
117125
.reply(200);
118126

119127
http.get(url);
120128
});
121129
};
122130

131+
/**
132+
* Intercepts and extracts a single request containing a Sentry Envelope
133+
*
134+
* @param {string} url
135+
* @return {*} {Promise<Array<Record<string, unknown>>>}
136+
*/
137+
export const getEnvelopeRequest = async (url: string): Promise<Array<Record<string, unknown>>> => {
138+
return (await getMultipleEnvelopeRequest(url, 1))[0];
139+
};
140+
123141
/**
124142
* Runs a test server
125143
*

packages/node/src/transports/new.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export function makeNodeTransport(options: NodeTransportOptions): NewTransport {
3838
const urlSegments = new URL(options.url);
3939
const isHttps = urlSegments.protocol === 'https:';
4040

41+
// Proxy prioritization: http => `options.proxy` | `process.env.http_proxy`
4142
// Proxy prioritization: https => `options.proxy` | `process.env.https_proxy` | `process.env.http_proxy`
4243
const proxy = applyNoProxyOption(
4344
urlSegments,

0 commit comments

Comments
 (0)