Skip to content
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

feat(types): Add profile envelope types #9798

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/browser/src/profiling/integration.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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');
Expand Down
5 changes: 2 additions & 3 deletions packages/browser/src/profiling/utils.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion packages/types/src/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<EventItemHeaders, Event>;
export type AttachmentItem = BaseEnvelopeItem<AttachmentItemHeaders, string | Uint8Array>;
Expand All @@ -91,6 +93,7 @@ type ReplayEventItem = BaseEnvelopeItem<ReplayEventItemHeaders, ReplayEvent>;
type ReplayRecordingItem = BaseEnvelopeItem<ReplayRecordingItemHeaders, ReplayRecordingData>;
export type StatsdItem = BaseEnvelopeItem<StatsdItemHeaders, string>;
export type FeedbackItem = BaseEnvelopeItem<FeedbackItemHeaders, FeedbackEvent>;
export type ProfileItem = BaseEnvelopeItem<ProfileItemHeaders, Profile>;

export type EventEnvelopeHeaders = { event_id: string; sent_at: string; trace?: DynamicSamplingContext };
type SessionEnvelopeHeaders = { sent_at: string };
Expand All @@ -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<SessionEnvelopeHeaders, SessionItem>;
export type ClientReportEnvelope = BaseEnvelope<ClientReportEnvelopeHeaders, ClientReportItem>;
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down