Skip to content

Commit

Permalink
Clarify proxy order for htpp
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed Mar 29, 2022
1 parent dd939ff commit 7803fbf
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as Sentry from '@sentry/node';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
_experiments: {
newTransport: true, // use new transport
},
});

Sentry.captureException(new Error('test_simple_error'));
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { getMultipleEnvelopeRequest, runServer } from '../../../../utils';

test('should correctly send envelope', async () => {
const url = await runServer(__dirname);
const envelopes = await getMultipleEnvelopeRequest(url, 2);

const errorEnvelope = envelopes[1];

expect(errorEnvelope).toHaveLength(3);
expect(errorEnvelope[2]).toMatchObject({
exception: {
values: [
{
type: 'Error',
value: 'test_simple_error',
},
],
},
release: '1.0',
event_id: expect.any(String),
timestamp: expect.any(Number),
});
});
30 changes: 24 additions & 6 deletions packages/node-integration-tests/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,43 @@ export const getEventRequest = async (url: string): Promise<Record<string, unkno
};

/**
* Intercepts and extracts a request containing a Sentry Envelope
*
* @param {string} url
* @return {*} {Promise<Array<Record<string, unknown>>>}
* Intercepts and extracts multiple requests containing a Sentry Envelope
* @param url
* @param count
*/
export const getEnvelopeRequest = async (url: string): Promise<Array<Record<string, unknown>>> => {
export const getMultipleEnvelopeRequest = async (url: string, count: number): Promise<Record<string, unknown>[][]> => {
const envelopes: Record<string, unknown>[][] = [];

return new Promise(resolve => {
nock('https://dsn.ingest.sentry.io')
.post('/api/1337/envelope/', body => {
const envelope = parseEnvelope(body);
resolve(envelope);
envelopes.push(envelope);

if (count === envelopes.length) {
resolve(envelopes);
}

return true;
})
.times(count)
.query(true) // accept any query params - used for sentry_key param
.reply(200);

http.get(url);
});
};

/**
* Intercepts and extracts a single request containing a Sentry Envelope
*
* @param {string} url
* @return {*} {Promise<Array<Record<string, unknown>>>}
*/
export const getEnvelopeRequest = async (url: string): Promise<Array<Record<string, unknown>>> => {
return (await getMultipleEnvelopeRequest(url, 1))[0];
};

/**
* Runs a test server
*
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/transports/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function makeNodeTransport(options: NodeTransportOptions): NewTransport {
const urlSegments = new URL(options.url);
const isHttps = urlSegments.protocol === 'https:';

// Proxy prioritization: http => `options.proxy` | `process.env.http_proxy`
// Proxy prioritization: https => `options.proxy` | `process.env.https_proxy` | `process.env.http_proxy`
const proxy = applyNoProxyOption(
urlSegments,
Expand Down

0 comments on commit 7803fbf

Please sign in to comment.