Skip to content

Commit 739d904

Browse files
authored
fix: Make full url customizable for Spotlight (#9652)
1 parent 075cc6e commit 739d904

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

packages/node/src/integrations/spotlight.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import type { Client, Integration } from '@sentry/types';
1+
import type { Client, Envelope, Integration } from '@sentry/types';
22
import { logger, serializeEnvelope } from '@sentry/utils';
33
import * as http from 'http';
44
import { URL } from 'url';
55

66
type SpotlightConnectionOptions = {
77
/**
88
* Set this if the Spotlight Sidecar is not running on localhost:8969
9-
* By default, the Url is set to http://localhost:8969
9+
* By default, the Url is set to http://localhost:8969/stream
1010
*/
1111
sidecarUrl?: string;
1212
};
@@ -26,7 +26,7 @@ export class Spotlight implements Integration {
2626

2727
public constructor(options?: SpotlightConnectionOptions) {
2828
this._options = {
29-
sidecarUrl: options?.sidecarUrl || 'http://localhost:8969',
29+
sidecarUrl: options?.sidecarUrl || 'http://localhost:8969/stream',
3030
};
3131
}
3232

@@ -61,7 +61,7 @@ function connectToSpotlight(client: Client, options: Required<SpotlightConnectio
6161
return;
6262
}
6363

64-
client.on('beforeEnvelope', envelope => {
64+
client.on('beforeEnvelope', (envelope: Envelope) => {
6565
if (failedRequests > 3) {
6666
logger.warn('[Spotlight] Disabled Sentry -> Spotlight integration due to too many failed requests');
6767
return;
@@ -72,7 +72,7 @@ function connectToSpotlight(client: Client, options: Required<SpotlightConnectio
7272
const req = http.request(
7373
{
7474
method: 'POST',
75-
path: '/stream',
75+
path: spotlightUrl.pathname,
7676
hostname: spotlightUrl.hostname,
7777
port: spotlightUrl.port,
7878
headers: {
@@ -102,7 +102,7 @@ function connectToSpotlight(client: Client, options: Required<SpotlightConnectio
102102

103103
function parseSidecarUrl(url: string): URL | undefined {
104104
try {
105-
return new URL(`${url}/stream`);
105+
return new URL(`${url}`);
106106
} catch {
107107
logger.warn(`[Spotlight] Invalid sidecar URL: ${url}`);
108108
return undefined;

packages/node/test/integrations/spotlight.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,45 @@ describe('Spotlight', () => {
7373
);
7474
});
7575

76+
it('sends an envelope POST request to a custom sidecar url', () => {
77+
const httpSpy = jest.spyOn(http, 'request').mockImplementationOnce(() => {
78+
return {
79+
on: jest.fn(),
80+
write: jest.fn(),
81+
end: jest.fn(),
82+
} as any;
83+
});
84+
85+
let callback: (envelope: Envelope) => void = () => {};
86+
const clientWithSpy = {
87+
...client,
88+
on: jest.fn().mockImplementationOnce((_, cb) => (callback = cb)),
89+
};
90+
91+
const integration = new Spotlight({ sidecarUrl: 'http://mylocalhost:8888/abcd' });
92+
// @ts-expect-error - this is fine in tests
93+
integration.setup(clientWithSpy);
94+
95+
const envelope = createEnvelope<EventEnvelope>({ event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2', sent_at: '123' }, [
96+
[{ type: 'event' }, { event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2' }],
97+
]);
98+
99+
callback(envelope);
100+
101+
expect(httpSpy).toHaveBeenCalledWith(
102+
{
103+
headers: {
104+
'Content-Type': 'application/x-sentry-envelope',
105+
},
106+
hostname: 'mylocalhost',
107+
method: 'POST',
108+
path: '/abcd',
109+
port: '8888',
110+
},
111+
expect.any(Function),
112+
);
113+
});
114+
76115
describe('no-ops if', () => {
77116
it('an invalid URL is passed', () => {
78117
const integration = new Spotlight({ sidecarUrl: 'invalid-url' });

0 commit comments

Comments
 (0)