Skip to content

Commit 76378af

Browse files
authored
feat(types): Add SerializedEvent interface (pre v8) (#10240)
Add a `SerializedEvent` interface which more accurately represents what an event envelope item contains (i.e. the JSON structure of a serialized `Event` object). Specifically, the `spans` field now correctly only contains the attributes the POJO span will continue to hold, i.e. without the deprecations and methods declared in the `Span` interface. In v8, we should change the `EventItem` type for the event envelope but doing so now is a breaking change I believe (And arguably, not too important to do now anyway).
1 parent b3f0589 commit 76378af

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

dev-packages/browser-integration-tests/suites/tracing/browsertracing/http-timings/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@playwright/test';
2-
import type { Event } from '@sentry/types';
2+
import type { SerializedEvent } from '@sentry/types';
33

44
import { sentryTest } from '../../../../utils/fixtures';
55
import { getMultipleSentryEnvelopeRequests, shouldSkipTracingTest } from '../../../../utils/helpers';
@@ -23,7 +23,7 @@ sentryTest('should create fetch spans with http timing @firefox', async ({ brows
2323

2424
const url = await getLocalTestPath({ testDir: __dirname });
2525

26-
const envelopes = await getMultipleSentryEnvelopeRequests<Event>(page, 2, { url, timeout: 10000 });
26+
const envelopes = await getMultipleSentryEnvelopeRequests<SerializedEvent>(page, 2, { url, timeout: 10000 });
2727
const tracingEvent = envelopes[envelopes.length - 1]; // last envelope contains tracing data on all browsers
2828

2929
// eslint-disable-next-line deprecation/deprecation

packages/types/src/envelope.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ type CheckInItemHeaders = { type: 'check_in' };
8383
type StatsdItemHeaders = { type: 'statsd'; length: number };
8484
type ProfileItemHeaders = { type: 'profile' };
8585

86+
// TODO (v8): Replace `Event` with `SerializedEvent`
8687
export type EventItem = BaseEnvelopeItem<EventItemHeaders, Event>;
8788
export type AttachmentItem = BaseEnvelopeItem<AttachmentItemHeaders, string | Uint8Array>;
8889
export type UserFeedbackItem = BaseEnvelopeItem<UserFeedbackItemHeaders, UserFeedback>;

packages/types/src/event.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { Request } from './request';
1111
import type { CaptureContext } from './scope';
1212
import type { SdkInfo } from './sdkinfo';
1313
import type { Severity, SeverityLevel } from './severity';
14-
import type { Span } from './span';
14+
import type { Span, SpanJSON } from './span';
1515
import type { Thread } from './thread';
1616
import type { TransactionSource } from './transaction';
1717
import type { User } from './user';
@@ -86,3 +86,14 @@ export interface EventHint {
8686
data?: any;
8787
integrations?: string[];
8888
}
89+
90+
/**
91+
* Represents the event that's sent in an event envelope, omitting interfaces that are no longer representative after
92+
* event serialization.
93+
*/
94+
export interface SerializedEvent extends Omit<Event, 'spans'> {
95+
/**
96+
* POJO objects of spans belonging to this event.
97+
*/
98+
spans?: SpanJSON[];
99+
}

packages/types/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export type {
4747
ProfileItem,
4848
} from './envelope';
4949
export type { ExtendedError } from './error';
50-
export type { Event, EventHint, EventType, ErrorEvent, TransactionEvent } from './event';
50+
export type { Event, EventHint, EventType, ErrorEvent, TransactionEvent, SerializedEvent } from './event';
5151
export type { EventProcessor } from './eventprocessor';
5252
export type { Exception } from './exception';
5353
export type { Extra, Extras } from './extra';

0 commit comments

Comments
 (0)