-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(types): Add Envelope types #4527
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { SentryRequestType } from './request'; | ||
import { SdkInfo } from './sdkinfo'; | ||
import { Session, SessionAggregates } from './session'; | ||
import { Outcome } from './transport'; | ||
import { User } from './user'; | ||
|
||
// Based on: https://develop.sentry.dev/sdk/envelopes/ | ||
|
||
type CommonEnvelopeHeaders = { | ||
dsn?: string; | ||
sdk?: SdkInfo; | ||
}; | ||
|
||
type CommonEnvelopeItemHeaders = { | ||
length?: number; | ||
}; | ||
|
||
/** | ||
* 1st Item: Item headers | ||
* 2nd Item: Item payload | ||
*/ | ||
type BaseEnvelopeItem<ItemHeader extends { type: string }, Payload = unknown> = [ | ||
CommonEnvelopeItemHeaders & ItemHeader, | ||
Payload, | ||
]; | ||
|
||
type UnknownEnvelopeItem = BaseEnvelopeItem<{ type: '__unknown__' }>; | ||
|
||
type BaseEnvelope<EnvelopeHeaders extends Record<string, unknown>, EnvelopeItems extends BaseEnvelopeItem<any>> = { | ||
h: CommonEnvelopeHeaders & EnvelopeHeaders; | ||
i: Array<EnvelopeItems | UnknownEnvelopeItem>; | ||
}; | ||
|
||
export type EventEnvelopeItem = BaseEnvelopeItem<{ type: 'event' | 'transaction' }, Event>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line causes a type error on node version 14. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh interesting. Could you open a GitHub issue please with your tsconfig, package.json and some details about your setup? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will try to do that tomorrow, we now locked the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
type AttachmentEnvelopeItem = BaseEnvelopeItem<{ type: 'attachment'; filename: 'string' }>; | ||
|
||
type UserFeedbackEnvelopeItem = BaseEnvelopeItem< | ||
{ type: 'user_report' }, | ||
{ | ||
event_id: string; | ||
email: User['email']; | ||
name: string; | ||
comments: string; | ||
} | ||
>; | ||
|
||
export type EventEnvelope = BaseEnvelope< | ||
{ event_id: string; sent_at: string }, | ||
EventEnvelopeItem | AttachmentEnvelopeItem | UserFeedbackEnvelopeItem | ||
>; | ||
|
||
export type SessionEnvelopeItem = | ||
| BaseEnvelopeItem<{ type: 'session' }, Session> | ||
| BaseEnvelopeItem<{ type: 'sessions' }, SessionAggregates>; | ||
|
||
export type SessionEnvelope = BaseEnvelope<{ sent_at: string }, SessionEnvelopeItem>; | ||
|
||
export type ClientReportEnvelopeItem = BaseEnvelopeItem< | ||
{ type: 'client_report' }, | ||
{ timestamp: number; discarded_events: { reason: Outcome; category: SentryRequestType; quantity: number } } | ||
>; | ||
|
||
export type ClientReportEnvelope = BaseEnvelope<Record<string, unknown>, ClientReportEnvelopeItem>; | ||
|
||
export type Envelope = EventEnvelope | SessionEnvelope | ClientReportEnvelope; |
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.
Two things here:
The second generic parameter should be singular, I believe, right? Because it's what's going into the array.
I get that it saves on bundle size to have the properties be single letters, but in this case the loss of readability/ease of use makes it feel not worth it to me. Especially given that envelopes are something an SDK user might have to deal with (i.e., aren't purely for internal use, though, to be fair, I'd be saying this regardless), I really think we should give these real names.
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.
Yeah the 2nd parameter can be singular, I just kept it as this because it can be union typed, so it better fit my mental model as I was laying out the types.
This is a good point that I didn't fully consider, I agree with the change
IMO I think it's pretty clear from the types what is happening. Is there a particular area that is harder to understand? It's also important to note that I'm sure these types will change a bit once we actually use them in the envelope helper functions. This is just a nice start to model out the domains appropriately.