8000 feat(types): Add profile envelope types (#9798) · adam187/sentry-javascript@13e3425 · GitHub
[go: up one dir, main page]

Skip to content

Commit 13e3425

Browse files
authored
feat(types): Add profile envelope types (getsentry#9798)
1 parent 2b4d56b commit 13e3425

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

packages/browser/src/profiling/integration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EventProcessor, Hub, Integration, Transaction } from '@sentry/types';
1+
import type { EventEnvelope, EventProcessor, Hub, Integration, Transaction } from '@sentry/types';
22
import type { Profile } from '@sentry/types/src/profiling';
33
import { logger } from '@sentry/utils';
44

@@ -110,7 +110,7 @@ export class BrowserProfilingIntegration implements Integration {
110110
}
111111
}
112112

113-
addProfilesToEnvelope(envelope, profilesToAddToEnvelope);
113+
addProfilesToEnvelope(envelope as EventEnvelope, profilesToAddToEnvelope);
114114
});
115115
} else {
116116
logger.warn('[Profiling] Client does not support hooks, profiling will be disabled');

packages/browser/src/profiling/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable max-lines */
22

33
import { DEFAULT_ENVIRONMENT, getClient, getCurrentHub } from '@sentry/core';
4-
import type { DebugImage, Envelope, Event, StackFrame, StackParser, Transaction } from '@sentry/types';
4+
import type { DebugImage, Envelope, Event, EventEnvelope, StackFrame, StackParser, Transaction } from '@sentry/types';
55
import type { Profile, ThreadCpuProfile } from '@sentry/types/src/profiling';
66
import { GLOBAL_OBJ, browserPerformanceTimeOrigin, forEachEnvelopeItem, logger, uuid4 } from '@sentry/utils';
77

@@ -300,13 +300,12 @@ export function convertJSSelfProfileToSampledFormat(input: JSSelfProfile): Profi
300300
* Adds items to envelope if they are not already present - mutates the envelope.
301301
* @param envelope
302302
*/
303-
export function addProfilesToEnvelope(envelope: Envelope, profiles: Profile[]): Envelope {
303+
export function addProfilesToEnvelope(envelope: EventEnvelope, profiles: Profile[]): Envelope {
304304
if (!profiles.length) {
305305
return envelope;
306306
}
307307

308308
for (const profile of profiles) {
309-
// @ts-expect-error untyped envelope
310309
envelope[1].push([{ type: 'profile' }, profile]);
311310
}
312311
return envelope;

packages/types/src/envelope.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ClientReport } from './clientreport';
33
import type { DsnComponents } from './dsn';
44
import type { Event } from './event';
55
import type { FeedbackEvent } from './feedback';
6+
import type { Profile } from './profiling';
67
import type { ReplayEvent, ReplayRecordingData } from './replay';
78
import type { SdkInfo } from './sdkinfo';
89
import type { SerializedSession, Session, SessionAggregates } from './session';
@@ -77,6 +78,7 @@ type ReplayEventItemHeaders = { type: 'replay_event' };
7778
type ReplayRecordingItemHeaders = { type: 'replay_recording'; length: number };
7879
type CheckInItemHeaders = { type: 'check_in' };
7980
type StatsdItemHeaders = { type: 'statsd' };
81+
type ProfileItemHeaders = { type: 'profile' };
8082

8183
export type EventItem = BaseEnvelopeItem<EventItemHeaders, Event>;
8284
export type AttachmentItem = BaseEnvelopeItem<AttachmentItemHeaders, string | Uint8Array>;
@@ -91,6 +93,7 @@ type ReplayEventItem = BaseEnvelopeItem<ReplayEventItemHeaders, ReplayEvent>;
9193
type ReplayRecordingItem = BaseEnvelopeItem<ReplayRecordingItemHeaders, ReplayRecordingData>;
9294
export type StatsdItem = BaseEnvelopeItem<StatsdItemHeaders, string>;
9395
export type FeedbackItem = BaseEnvelopeItem<FeedbackItemHeaders, FeedbackEvent>;
96+
export type ProfileItem = BaseEnvelopeItem<ProfileItemHeaders, Profile>;
9497

9598
export type EventEnvelopeHeaders = { event_id: string; sent_at: string; trace?: DynamicSamplingContext };
9699
type SessionEnvelopeHeaders = { sent_at: string };
@@ -101,7 +104,7 @@ type StatsdEnvelopeHeaders = BaseEnvelopeHeaders;
101104

102105
export type EventEnvelope = BaseEnvelope<
103106
EventEnvelopeHeaders,
104-
EventItem | AttachmentItem | UserFeedbackItem | FeedbackItem
107+
EventItem | AttachmentItem | UserFeedbackItem | FeedbackItem | ProfileItem
105108
>;
106109
export type SessionEnvelope = BaseEnvelope<SessionEnvelopeHeaders, SessionItem>;
107110
export type ClientReportEnvelope = BaseEnvelope<ClientReportEnvelopeHeaders, ClientReportItem>;

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export type {
4444
CheckInEnvelope,
4545
StatsdItem,
4646
StatsdEnvelope,
47+
ProfileItem,
4748
} from './envelope';
4849
export type { ExtendedError } from './error';
4950
export type { Event, EventHint, EventType, ErrorEvent, TransactionEvent } from './event';

0 commit comments

Comments
 (0)
0