Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 33 additions & 52 deletions packages/node/src/integrations/spotlight.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as http from 'node:http';
import type { Client, Envelope, IntegrationFn } from '@sentry/core';
import { defineIntegration, logger, serializeEnvelope } from '@sentry/core';
import { defineIntegration, logger, serializeEnvelope, suppressTracing } from '@sentry/core';

type SpotlightConnectionOptions = {
/**
Expand Down Expand Up @@ -52,40 +52,40 @@ function connectToSpotlight(client: Client, options: Required<SpotlightConnectio
}

const serializedEnvelope = serializeEnvelope(envelope);

const request = getNativeHttpRequest();
const req = request(
{
method: 'POST',
path: spotlightUrl.pathname,
hostname: spotlightUrl.hostname,
port: spotlightUrl.port,
headers: {
'Content-Type': 'application/x-sentry-envelope',
suppressTracing(() => {
const req = http.request(
{
method: 'POST',
path: spotlightUrl.pathname,
hostname: spotlightUrl.hostname,
port: spotlightUrl.port,
headers: {
'Content-Type': 'application/x-sentry-envelope',
},
},
},
res => {
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 400) {
// Reset failed requests counter on success
failedRequests = 0;
}
res.on('data', () => {
// Drain socket
});

res.on('end', () => {
// Drain socket
});
res.setEncoding('utf8');
},
);

req.on('error', () => {
failedRequests++;
logger.warn('[Spotlight] Failed to send envelope to Spotlight Sidecar');
res => {
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 400) {
// Reset failed requests counter on success
failedRequests = 0;
}
res.on('data', () => {
// Drain socket
});

res.on('end', () => {
// Drain socket
});
res.setEncoding('utf8');
},
);

req.on('error', () => {
failedRequests++;
logger.warn('[Spotlight] Failed to send envelope to Spotlight Sidecar');
});
req.write(serializedEnvelope);
req.end();
});
req.write(serializedEnvelope);
req.end();
});
}

Expand All @@ -97,22 +97,3 @@ function parseSidecarUrl(url: string): URL | undefined {
return undefined;
}
}

type HttpRequestImpl = typeof http.request;
type WrappedHttpRequest = HttpRequestImpl & { __sentry_original__: HttpRequestImpl };

/**
* We want to get an unpatched http request implementation to avoid capturing our own calls.
*/
export function getNativeHttpRequest(): HttpRequestImpl {
const { request } = http;
if (isWrapped(request)) {
return request.__sentry_original__;
}

return request;
}

function isWrapped(impl: HttpRequestImpl): impl is WrappedHttpRequest {
return '__sentry_original__' in impl;
}
Loading