Skip to content

Commit c9fa57b

Browse files
committed
feat: Delete store endpoint code
1 parent b7251cc commit c9fa57b

File tree

6 files changed

+10
-415
lines changed

6 files changed

+10
-415
lines changed

packages/core/src/api.ts

+3-44
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ function getBaseApiEndpoint(dsn: DsnComponents): string {
3535
}
3636

3737
/** Returns the ingest API endpoint for target. */
38-
function _getIngestEndpoint(dsn: DsnComponents, target: 'store' | 'envelope'): string {
39-
return `${getBaseApiEndpoint(dsn)}${dsn.projectId}/${target}/`;
38+
function _getIngestEndpoint(dsn: DsnComponents): string {
39+
return `${getBaseApiEndpoint(dsn)}${dsn.projectId}/envelope/`;
4040
}
4141

4242
/** Returns a URL-encoded string with auth config suitable for a query string. */
@@ -49,54 +49,13 @@ function _encodedAuth(dsn: DsnComponents): string {
4949
});
5050
}
5151

52-
/** Returns the store endpoint URL. */
53-
export function getStoreEndpoint(dsn: DsnComponents): string {
54-
return _getIngestEndpoint(dsn, 'store');
55-
}
56-
57-
/**
58-
* Returns the store endpoint URL with auth in the query string.
59-
*
60-
* Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
61-
*/
62-
export function getStoreEndpointWithUrlEncodedAuth(dsn: DsnComponents): string {
63-
return `${getStoreEndpoint(dsn)}?${_encodedAuth(dsn)}`;
64-
}
65-
66-
/** Returns the envelope endpoint URL. */
67-
function _getEnvelopeEndpoint(dsn: DsnComponents): string {
68-
return _getIngestEndpoint(dsn, 'envelope');
69-
}
70-
7152
/**
7253
* Returns the envelope endpoint URL with auth in the query string.
7354
*
7455
* Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
7556
*/
7657
export function getEnvelopeEndpointWithUrlEncodedAuth(dsn: DsnComponents, tunnel?: string): string {
77-
return tunnel ? tunnel : `${_getEnvelopeEndpoint(dsn)}?${_encodedAuth(dsn)}`;
78-
}
79-
80-
/**
81-
* Returns an object that can be used in request headers.
82-
* This is needed for node and the old /store endpoint in sentry
83-
*/
84-
export function getRequestHeaders(
85-
dsn: DsnComponents,
86-
clientName: string,
87-
clientVersion: string,
88-
): { [key: string]: string } {
89-
// CHANGE THIS to use metadata but keep clientName and clientVersion compatible
90-
const header = [`Sentry sentry_version=${SENTRY_API_VERSION}`];
91-
header.push(`sentry_client=${clientName}/${clientVersion}`);
92-
header.push(`sentry_key=${dsn.publicKey}`);
93-
if (dsn.pass) {
94-
header.push(`sentry_secret=${dsn.pass}`);
95-
}
96-
return {
97-
'Content-Type': 'application/json',
98-
'X-Sentry-Auth': header.join(', '),
99-
};
58+
return tunnel ? tunnel : `${_getIngestEndpoint(dsn)}?${_encodedAuth(dsn)}`;
10059
}
10160

10261
/** Returns the url to the report dialog endpoint. */

packages/core/src/baseclient.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
275275
*/
276276
public sendSession(session: Session | SessionAggregates): void {
277277
if (this._dsn) {
278-
const [env] = createSessionEnvelope(session, this._dsn, this._options._metadata, this._options.tunnel);
278+
const env = createSessionEnvelope(session, this._dsn, this._options._metadata, this._options.tunnel);
279279
this.sendEnvelope(env);
280280
}
281281
}

packages/core/src/index.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,8 @@ export {
2323
Scope,
2424
Session,
2525
} from '@sentry/hub';
26-
export {
27-
getEnvelopeEndpointWithUrlEncodedAuth,
28-
getStoreEndpointWithUrlEncodedAuth,
29-
getRequestHeaders,
30-
initAPIDetails,
31-
getReportDialogEndpoint,
32-
} from './api';
26+
export { getEnvelopeEndpointWithUrlEncodedAuth, initAPIDetails, getReportDialogEndpoint } from './api';
3327
export { BaseClient } from './baseclient';
34-
export { eventToSentryRequest, sessionToSentryRequest } from './request';
3528
export { initAndBind } from './sdk';
3629
export { createTransport } from './transports/base';
3730
export { SDK_VERSION } from './version';

packages/core/src/request.ts

+4-117
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ import {
55
EventItem,
66
SdkInfo,
77
SdkMetadata,
8-
SentryRequest,
98
SentryRequestType,
109
Session,
1110
SessionAggregates,
1211
SessionEnvelope,
1312
SessionItem,
1413
} from '@sentry/types';
15-
import { createEnvelope, dsnToString, normalize, serializeEnvelope } from '@sentry/utils';
16-
17-
import { APIDetails, getEnvelopeEndpointWithUrlEncodedAuth, getStoreEndpointWithUrlEncodedAuth } from './api';
14+
import { createEnvelope, dsnToString } from '@sentry/utils';
1815

1916
/** Extract sdk info from from the API metadata */
2017
function getSdkMetadataForEnvelopeHeader(metadata?: SdkMetadata): SdkInfo | undefined {
@@ -47,7 +44,7 @@ export function createSessionEnvelope(
4744
dsn: DsnComponents,
4845
metadata?: SdkMetadata,
4946
tunnel?: string,
50-
): [SessionEnvelope, SentryRequestType] {
47+
): SessionEnvelope {
5148
const sdkInfo = getSdkMetadataForEnvelopeHeader(metadata);
5249
const envelopeHeaders = {
5350
sent_at: new Date().toISOString(),
@@ -62,22 +59,11 @@ export function createSessionEnvelope(
6259
const envelopeItem = [{ type } as { type: 'session' | 'sessions' }, session] as SessionItem;
6360
const envelope = createEnvelope<SessionEnvelope>(envelopeHeaders, [envelopeItem]);
6461

65-
return [envelope, type];
66-
}
67-
68-
/** Creates a SentryRequest from a Session. */
69-
export function sessionToSentryRequest(session: Session | SessionAggregates, api: APIDetails): SentryRequest {
70-
const [envelope, type] = createSessionEnvelope(session, api.dsn, api.metadata, api.tunnel);
71-
return {
72-
body: serializeEnvelope(envelope),
73-
type,
74-
url: getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel),
75-
};
62+
return envelope;
7663
}
7764

7865
/**
79-
* Create an Envelope from an event. Note that this is duplicated from below,
80-
* but on purpose as this will be refactored in v7.
66+
* Create an Envelope from an event.
8167
*/
8268
export function createEventEnvelope(
8369
event: Event,
@@ -135,102 +121,3 @@ export function createEventEnvelope(
135121
];
136122
return createEnvelope<EventEnvelope>(envelopeHeaders, [eventItem]);
137123
}
138-
139-
/** Creates a SentryRequest from an event. */
140-
export function eventToSentryRequest(event: Event, api: APIDetails): SentryRequest {
141-
const sdkInfo = getSdkMetadataForEnvelopeHeader(api.metadata);
142-
const eventType = event.type || 'event';
143-
const useEnvelope = eventType === 'transaction' || !!api.tunnel;
144-
145-
const { transactionSampling } = event.sdkProcessingMetadata || {};
146-
const { method: samplingMethod, rate: sampleRate } = transactionSampling || {};
147-
148-
// TODO: Below is a temporary hack in order to debug a serialization error - see
149-
// https://github.com/getsentry/sentry-javascript/issues/2809,
150-
// https://github.com/getsentry/sentry-javascript/pull/4425, and
151-
// https://github.com/getsentry/sentry-javascript/pull/4574.
152-
//
153-
// TL; DR: even though we normalize all events (which should prevent this), something is causing `JSON.stringify` to
154-
// throw a circular reference error.
155-
//
156-
// When it's time to remove it:
157-
// 1. Delete everything between here and where the request object `req` is created, EXCEPT the line deleting
158-
// `sdkProcessingMetadata`
159-
// 2. Restore the original version of the request body, which is commented out
160-
// 3. Search for either of the PR URLs above and pull out the companion hacks in the browser playwright tests and the
161-
// baseClient tests in this package
162-
enhanceEventWithSdkInfo(event, api.metadata.sdk);
163-
event.tags = event.tags || {};
164-
event.extra = event.extra || {};
165-
166-
// In theory, all events should be marked as having gone through normalization and so
167-
// we should never set this tag/extra data
168-
if (!(event.sdkProcessingMetadata && event.sdkProcessingMetadata.baseClientNormalized)) {
169-
event.tags.skippedNormalization = true;
170-
event.extra.normalizeDepth = event.sdkProcessingMetadata ? event.sdkProcessingMetadata.normalizeDepth : 'unset';
171-
}
172-
173-
// prevent this data from being sent to sentry
174-
// TODO: This is NOT part of the hack - DO NOT DELETE
175-
delete event.sdkProcessingMetadata;
176-
177-
let body;
178-
try {
179-
// 99.9% of events should get through just fine - no change in behavior for them
180-
body = JSON.stringify(event);
181-
} catch (err) {
182-
// Record data about the error without replacing original event data, then force renormalization
183-
event.tags.JSONStringifyError = true;
184-
event.extra.JSONStringifyError = err;
185-
try {
186-
body = JSON.stringify(normalize(event));
187-
} catch (newErr) {
188-
// At this point even renormalization hasn't worked, meaning something about the event data has gone very wrong.
189-
// Time to cut our losses and record only the new error. With luck, even in the problematic cases we're trying to
190-
// debug with this hack, we won't ever land here.
191-
const innerErr = newErr as Error;
192-
body = JSON.stringify({
193-
message: 'JSON.stringify error after renormalization',
194-
// setting `extra: { innerErr }` here for some reason results in an empty object, so unpack manually
195-
extra: { message: innerErr.message, stack: innerErr.stack },
196-
});
197-
}
198-
}
199-
200-
const req: SentryRequest = {
201-
// this is the relevant line of code before the hack was added, to make it easy to undo said hack once we've solved
202-
// the mystery
203-
// body: JSON.stringify(sdkInfo ? enhanceEventWithSdkInfo(event, api.metadata.sdk) : event),
204-
body,
205-
type: eventType,
206-
url: useEnvelope
207-
? getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel)
208-
: getStoreEndpointWithUrlEncodedAuth(api.dsn),
209-
};
210-
211-
// https://develop.sentry.dev/sdk/envelopes/
212-
213-
// Since we don't need to manipulate envelopes nor store them, there is no
214-
// exported concept of an Envelope with operations including serialization and
215-
// deserialization. Instead, we only implement a minimal subset of the spec to
216-
// serialize events inline here.
217-
if (useEnvelope) {
218-
const envelopeHeaders = {
219-
event_id: event.event_id as string,
220-
sent_at: new Date().toISOString(),
221-
...(sdkInfo && { sdk: sdkInfo }),
222-
...(!!api.tunnel && { dsn: dsnToString(api.dsn) }),
223-
};
224-
const eventItem: EventItem = [
225-
{
226-
type: eventType,
227-
sample_rates: [{ id: samplingMethod, rate: sampleRate }],
228-
},
229-
req.body,
230-
];
231-
const envelope = createEnvelope<EventEnvelope>(envelopeHeaders, [eventItem]);
232-
req.body = serializeEnvelope(envelope);
233-
}
234-
235-
return req;
236-
}

packages/core/test/lib/api.test.ts

+1-30
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
/* eslint-disable deprecation/deprecation */
22
import { makeDsn } from '@sentry/utils';
33

4-
import {
5-
getEnvelopeEndpointWithUrlEncodedAuth,
6-
getReportDialogEndpoint,
7-
getRequestHeaders,
8-
getStoreEndpoint,
9-
getStoreEndpointWithUrlEncodedAuth,
10-
initAPIDetails,
11-
} from '../../src/api';
4+
import { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint, initAPIDetails } from '../../src/api';
125

136
const ingestDsn = 'https://[email protected]:1234/subpath/123';
147
const dsnPublic = 'https://[email protected]:1234/subpath/123';
@@ -19,14 +12,6 @@ const ingestDsnAPI = initAPIDetails(ingestDsn);
1912
const dsnPublicAPI = initAPIDetails(dsnPublic);
2013

2114
describe('API', () => {
22-
test('getStoreEndpoint', () => {
23-
expect(getStoreEndpointWithUrlEncodedAuth(dsnPublicAPI.dsn)).toEqual(
24-
'https://sentry.io:1234/subpath/api/123/store/?sentry_key=abc&sentry_version=7',
25-
);
26-
expect(getStoreEndpoint(dsnPublicAPI.dsn)).toEqual('https://sentry.io:1234/subpath/api/123/store/');
27-
expect(getStoreEndpoint(ingestDsnAPI.dsn)).toEqual('https://xxxx.ingest.sentry.io:1234/subpath/api/123/store/');
28-
});
29-
3015
test('getEnvelopeEndpoint', () => {
3116
expect(getEnvelopeEndpointWithUrlEncodedAuth(dsnPublicAPI.dsn)).toEqual(
3217
'https://sentry.io:1234/subpath/api/123/envelope/?sentry_key=abc&sentry_version=7',
@@ -35,20 +20,6 @@ describe('API', () => {
3520
expect(getEnvelopeEndpointWithUrlEncodedAuth(dsnPublicAPIWithTunnel.dsn, tunnel)).toEqual(tunnel);
3621
});
3722

38-
test('getRequestHeaders', () => {
39-
expect(getRequestHeaders(makeDsn(dsnPublic), 'a', '1.0')).toMatchObject({
40-
'Content-Type': 'application/json',
41-
'X-Sentry-Auth': expect.stringMatching(/^Sentry sentry_version=\d, sentry_client=a\/1\.0, sentry_key=abc$/),
42-
});
43-
44-
expect(getRequestHeaders(makeDsn(legacyDsn), 'a', '1.0')).toMatchObject({
45-
'Content-Type': 'application/json',
46-
'X-Sentry-Auth': expect.stringMatching(
47-
/^Sentry sentry_version=\d, sentry_client=a\/1\.0, sentry_key=abc, sentry_secret=123$/,
48-
),
49-
});
50-
});
51-
5223
describe('getReportDialogEndpoint', () => {
5324
test.each([
5425
[

0 commit comments

Comments
 (0)