-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Delete store endpoint code #4969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { | ||
DsnComponents, | ||
Event, | ||
EventEnvelope, | ||
EventItem, | ||
SdkInfo, | ||
SdkMetadata, | ||
SentryRequestType, | ||
Session, | ||
SessionAggregates, | ||
SessionEnvelope, | ||
SessionItem, | ||
} from '@sentry/types'; | ||
import { createEnvelope, dsnToString } from '@sentry/utils'; | ||
|
||
/** Extract sdk info from from the API metadata */ | ||
function getSdkMetadataForEnvelopeHeader(metadata?: SdkMetadata): SdkInfo | undefined { | ||
if (!metadata || !metadata.sdk) { | ||
return; | ||
} | ||
const { name, version } = metadata.sdk; | ||
return { name, version }; | ||
} | ||
|
||
/** | ||
* Apply SdkInfo (name, version, packages, integrations) to the corresponding event key. | ||
* Merge with existing data if any. | ||
**/ | ||
function enhanceEventWithSdkInfo(event: Event, sdkInfo?: SdkInfo): Event { | ||
if (!sdkInfo) { | ||
return event; | ||
} | ||
event.sdk = event.sdk || {}; | ||
event.sdk.name = event.sdk.name || sdkInfo.name; | ||
event.sdk.version = event.sdk.version || sdkInfo.version; | ||
event.sdk.integrations = [...(event.sdk.integrations || []), ...(sdkInfo.integrations || [])]; | ||
event.sdk.packages = [...(event.sdk.packages || []), ...(sdkInfo.packages || [])]; | ||
return event; | ||
} | ||
|
||
/** Creates an envelope from a Session */ | ||
export function createSessionEnvelope( | ||
session: Session | SessionAggregates, | ||
dsn: DsnComponents, | ||
metadata?: SdkMetadata, | ||
tunnel?: string, | ||
): SessionEnvelope { | ||
const sdkInfo = getSdkMetadataForEnvelopeHeader(metadata); | ||
const envelopeHeaders = { | ||
sent_at: new Date().toISOString(), | ||
...(sdkInfo && { sdk: sdkInfo }), | ||
...(!!tunnel && { dsn: dsnToString(dsn) }), | ||
}; | ||
|
||
// I know this is hacky but we don't want to add `sessions` to request type since it's never rate limited | ||
const type = 'aggregates' in session ? ('sessions' as SentryRequestType) : 'session'; | ||
|
||
// TODO (v7) Have to cast type because envelope items do not accept a `SentryRequestType` | ||
const envelopeItem = [{ type } as { type: 'session' | 'sessions' }, session] as SessionItem; | ||
const envelope = createEnvelope<SessionEnvelope>(envelopeHeaders, [envelopeItem]); | ||
|
||
return envelope; | ||
} | ||
|
||
/** | ||
* Create an Envelope from an event. | ||
*/ | ||
export function createEventEnvelope( | ||
event: Event, | ||
dsn: DsnComponents, | ||
metadata?: SdkMetadata, | ||
tunnel?: string, | ||
): EventEnvelope { | ||
const sdkInfo = getSdkMetadataForEnvelopeHeader(metadata); | ||
const eventType = event.type || 'event'; | ||
|
||
const { transactionSampling } = event.sdkProcessingMetadata || {}; | ||
const { method: samplingMethod, rate: sampleRate } = transactionSampling || {}; | ||
|
||
// TODO: Below is a temporary hack in order to debug a serialization error - see | ||
// https://github.com/getsentry/sentry-javascript/issues/2809, | ||
// https://github.com/getsentry/sentry-javascript/pull/4425, and | ||
// https://github.com/getsentry/sentry-javascript/pull/4574. | ||
// | ||
// TL; DR: even though we normalize all events (which should prevent this), something is causing `JSON.stringify` to | ||
// throw a circular reference error. | ||
// | ||
// When it's time to remove it: | ||
// 1. Delete everything between here and where the request object `req` is created, EXCEPT the line deleting | ||
// `sdkProcessingMetadata` | ||
// 2. Restore the original version of the request body, which is commented out | ||
// 3. Search for either of the PR URLs above and pull out the companion hacks in the browser playwright tests and the | ||
// baseClient tests in this package | ||
enhanceEventWithSdkInfo(event, metadata && metadata.sdk); | ||
event.tags = event.tags || {}; | ||
event.extra = event.extra || {}; | ||
|
||
// In theory, all events should be marked as having gone through normalization and so | ||
// we should never set this tag/extra data | ||
if (!(event.sdkProcessingMetadata && event.sdkProcessingMetadata.baseClientNormalized)) { | ||
event.tags.skippedNormalization = true; | ||
event.extra.normalizeDepth = event.sdkProcessingMetadata ? event.sdkProcessingMetadata.normalizeDepth : 'unset'; | ||
} | ||
|
||
// prevent this data from being sent to sentry | ||
// TODO: This is NOT part of the hack - DO NOT DELETE | ||
delete event.sdkProcessingMetadata; | ||
|
||
const envelopeHeaders = { | ||
event_id: event.event_id as string, | ||
sent_at: new Date().toISOString(), | ||
...(sdkInfo && { sdk: sdkInfo }), | ||
...(!!tunnel && { dsn: dsnToString(dsn) }), | ||
}; | ||
const eventItem: EventItem = [ | ||
{ | ||
type: eventType, | ||
sample_rates: [{ id: samplingMethod, rate: sampleRate }], | ||
}, | ||
event, | ||
]; | ||
return createEnvelope<EventEnvelope>(envelopeHeaders, [eventItem]); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should def write tests for the functions in this file. Don't know whether this PR is the place for this tho. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should write tests - I can write up a ticket after this gets merged in.