diff --git a/packages/browser/src/profiling/integration.ts b/packages/browser/src/profiling/integration.ts index 3f5251c4583f..326af29492cf 100644 --- a/packages/browser/src/profiling/integration.ts +++ b/packages/browser/src/profiling/integration.ts @@ -1,4 +1,4 @@ -import type { EventProcessor, Hub, Integration, Transaction } from '@sentry/types'; +import type { EventEnvelope, EventProcessor, Hub, Integration, Transaction } from '@sentry/types'; import type { Profile } from '@sentry/types/src/profiling'; import { logger } from '@sentry/utils'; @@ -110,7 +110,7 @@ export class BrowserProfilingIntegration implements Integration { } } - addProfilesToEnvelope(envelope, profilesToAddToEnvelope); + addProfilesToEnvelope(envelope as EventEnvelope, profilesToAddToEnvelope); }); } else { logger.warn('[Profiling] Client does not support hooks, profiling will be disabled'); diff --git a/packages/browser/src/profiling/utils.ts b/packages/browser/src/profiling/utils.ts index 1aac3d397ca7..3edb82e0b539 100644 --- a/packages/browser/src/profiling/utils.ts +++ b/packages/browser/src/profiling/utils.ts @@ -1,7 +1,7 @@ /* eslint-disable max-lines */ import { DEFAULT_ENVIRONMENT, getClient, getCurrentHub } from '@sentry/core'; -import type { DebugImage, Envelope, Event, StackFrame, StackParser, Transaction } from '@sentry/types'; +import type { DebugImage, Envelope, Event, EventEnvelope, StackFrame, StackParser, Transaction } from '@sentry/types'; import type { Profile, ThreadCpuProfile } from '@sentry/types/src/profiling'; import { GLOBAL_OBJ, browserPerformanceTimeOrigin, forEachEnvelopeItem, logger, uuid4 } from '@sentry/utils'; @@ -300,13 +300,12 @@ export function convertJSSelfProfileToSampledFormat(input: JSSelfProfile): Profi * Adds items to envelope if they are not already present - mutates the envelope. * @param envelope */ -export function addProfilesToEnvelope(envelope: Envelope, profiles: Profile[]): Envelope { +export function addProfilesToEnvelope(envelope: EventEnvelope, profiles: Profile[]): Envelope { if (!profiles.length) { return envelope; } for (const profile of profiles) { - // @ts-expect-error untyped envelope envelope[1].push([{ type: 'profile' }, profile]); } return envelope; diff --git a/packages/types/src/envelope.ts b/packages/types/src/envelope.ts index fbe593dd21f9..8d47206f4217 100644 --- a/packages/types/src/envelope.ts +++ b/packages/types/src/envelope.ts @@ -3,6 +3,7 @@ import type { ClientReport } from './clientreport'; import type { DsnComponents } from './dsn'; import type { Event } from './event'; import type { FeedbackEvent } from './feedback'; +import type { Profile } from './profiling'; import type { ReplayEvent, ReplayRecordingData } from './replay'; import type { SdkInfo } from './sdkinfo'; import type { SerializedSession, Session, SessionAggregates } from './session'; @@ -77,6 +78,7 @@ type ReplayEventItemHeaders = { type: 'replay_event' }; type ReplayRecordingItemHeaders = { type: 'replay_recording'; length: number }; type CheckInItemHeaders = { type: 'check_in' }; type StatsdItemHeaders = { type: 'statsd' }; +type ProfileItemHeaders = { type: 'profile' }; export type EventItem = BaseEnvelopeItem; export type AttachmentItem = BaseEnvelopeItem; @@ -91,6 +93,7 @@ type ReplayEventItem = BaseEnvelopeItem; type ReplayRecordingItem = BaseEnvelopeItem; export type StatsdItem = BaseEnvelopeItem; export type FeedbackItem = BaseEnvelopeItem; +export type ProfileItem = BaseEnvelopeItem; export type EventEnvelopeHeaders = { event_id: string; sent_at: string; trace?: DynamicSamplingContext }; type SessionEnvelopeHeaders = { sent_at: string }; @@ -101,7 +104,7 @@ type StatsdEnvelopeHeaders = BaseEnvelopeHeaders; export type EventEnvelope = BaseEnvelope< EventEnvelopeHeaders, - EventItem | AttachmentItem | UserFeedbackItem | FeedbackItem + EventItem | AttachmentItem | UserFeedbackItem | FeedbackItem | ProfileItem >; export type SessionEnvelope = BaseEnvelope; export type ClientReportEnvelope = BaseEnvelope; diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 615bf71ff785..5603854170f5 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -44,6 +44,7 @@ export type { CheckInEnvelope, StatsdItem, StatsdEnvelope, + ProfileItem, } from './envelope'; export type { ExtendedError } from './error'; export type { Event, EventHint, EventType, ErrorEvent, TransactionEvent } from './event';