Skip to content

fix(replay): Fix ts errors with replay_type #6681

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 3 commits into from
Jan 9, 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
7 changes: 3 additions & 4 deletions packages/replay/src/replay.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-lines */ // TODO: We might want to split this file up
import { addGlobalEventProcessor, captureException, getCurrentHub, setContext } from '@sentry/core';
import { Breadcrumb, ReplayEvent, TransportMakeRequestResponse } from '@sentry/types';
import type { Breadcrumb, ReplayEvent, ReplayRecordingMode, TransportMakeRequestResponse } from '@sentry/types';
import { addInstrumentationHandler, logger } from '@sentry/utils';
import { EventType, record } from 'rrweb';

Expand Down Expand Up @@ -34,7 +34,6 @@ import type {
RecordingOptions,
ReplayContainer as ReplayContainerInterface,
ReplayPluginOptions,
ReplayRecordingMode,
SendReplay,
Session,
} from './types';
Expand Down Expand Up @@ -922,7 +921,7 @@ export class ReplayContainer implements ReplayContainerInterface {
const transport = client && client.getTransport();
const dsn = client?.getDsn();

if (!client || !scope || !transport || !dsn) {
if (!client || !scope || !transport || !dsn || !this.session || !this.session.sampled) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should never be the case in this method but needed for ts and got rid of optional chaining

return;
}

Expand All @@ -936,7 +935,7 @@ export class ReplayContainer implements ReplayContainerInterface {
urls,
replay_id: replayId,
segment_id,
replay_type: this.session?.sampled,
replay_type: this.session.sampled,
};

const replayEvent = await getReplayEvent({ scope, client, replayId, event: baseEvent });
Expand Down
4 changes: 1 addition & 3 deletions packages/replay/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReplayRecordingData } from '@sentry/types';
import type { ReplayRecordingData, ReplayRecordingMode } from '@sentry/types';

import type { eventWithTime, recordOptions } from './types/rrweb';

Expand All @@ -9,8 +9,6 @@ export type RecordedEvents = Uint8Array | string;

export type AllPerformanceEntry = PerformancePaintTiming | PerformanceResourceTiming | PerformanceNavigationTiming;

export type ReplayRecordingMode = 'session' | 'error';

export interface SendReplay {
events: RecordedEvents;
replayId: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/replay/test/unit/util/getReplayEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('getReplayEvent', () => {
urls: ['https://sentry.io/'],
replay_id: replayId,
event_id: replayId,
replay_type: 'session',
segment_id: 3,
};

Expand All @@ -46,6 +47,7 @@ describe('getReplayEvent', () => {
trace_ids: ['trace-ID'],
urls: ['https://sentry.io/'],
replay_id: 'replay-ID',
replay_type: 'session',
segment_id: 3,
platform: 'javascript',
event_id: 'replay-ID',
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type { ExtractedNodeRequestData, HttpHeaderValue, Primitive, WorkerLocati
export type { ClientOptions, Options } from './options';
export type { Package } from './package';
export type { PolymorphicEvent, PolymorphicRequest } from './polymorphics';
export type { ReplayEvent, ReplayRecordingData } from './replay';
export type { ReplayEvent, ReplayRecordingData, ReplayRecordingMode } from './replay';
export type { QueryParams, Request } from './request';
export type { Runtime } from './runtime';
export type { CaptureContext, Scope, ScopeContext } from './scope';
Expand Down
7 changes: 7 additions & 0 deletions packages/types/src/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ export interface ReplayEvent extends Event {
trace_ids: string[];
replay_id: string;
segment_id: number;
replay_type: ReplayRecordingMode;
}

/**
* NOTE: These types are still considered Beta and subject to change.
* @hidden
*/
export type ReplayRecordingData = string | Uint8Array;

/**
* NOTE: These types are still considered Beta and subject to change.
* @hidden
*/
export type ReplayRecordingMode = 'session' | 'error';