Skip to content

Commit 8fdf340

Browse files
authored
ref: Deprecate lastEventId() (#10043)
1 parent b1458d6 commit 8fdf340

File tree

22 files changed

+93
-10
lines changed

22 files changed

+93
-10
lines changed

MIGRATION.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ Instead, import this directly from `@sentry/utils`.
4444

4545
Generally, in most cases you should probably use `continueTrace` instead, which abstracts this away from you and handles scope propagation for you.
4646

47+
## Deprecate `lastEventId()`
48+
49+
Instead, if you need the ID of a recently captured event, we recommend using `beforeSend` instead:
50+
51+
```ts
52+
import * as Sentry from "@sentry/browser";
53+
54+
Sentry.init({
55+
dsn: "__DSN__",
56+
beforeSend(event, hint) {
57+
const lastCapturedEventId = event.event_id;
58+
59+
// Do something with `lastCapturedEventId` here
60+
61+
return event;
62+
},
63+
});
64+
```
65+
4766
## Deprecate `timestampWithMs` export - #7878
4867

4968
The `timestampWithMs` util is deprecated in favor of using `timestampInSeconds`.

packages/angular/src/errorhandler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import { runOutsideAngular } from './zone';
1313
export interface ErrorHandlerOptions {
1414
logErrors?: boolean;
1515
showDialog?: boolean;
16-
dialogOptions?: Sentry.ReportDialogOptions;
16+
// eslint-disable-next-line deprecation/deprecation
17+
dialogOptions?: Omit<Sentry.ReportDialogOptions, 'eventId'>;
1718
/**
1819
* Custom implementation of error extraction from the raw value captured by the Angular.
1920
* @param error Value captured by Angular's ErrorHandler provider
@@ -120,6 +121,7 @@ class SentryErrorHandler implements AngularErrorHandler {
120121
if (client && client.on && !this._registeredAfterSendEventHandler) {
121122
client.on('afterSendEvent', (event: Event) => {
122123
if (!event.type) {
124+
// eslint-disable-next-line deprecation/deprecation
123125
Sentry.showReportDialog({ ...this._options.dialogOptions, eventId: event.event_id });
124126
}
125127
});

packages/astro/src/index.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export {
4848
makeNodeTransport,
4949
defaultIntegrations,
5050
defaultStackParser,
51+
// eslint-disable-next-line deprecation/deprecation
5152
lastEventId,
5253
flush,
5354
close,

packages/astro/src/index.types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export declare const defaultStackParser: StackParser;
2121

2222
export declare function close(timeout?: number | undefined): PromiseLike<boolean>;
2323
export declare function flush(timeout?: number | undefined): PromiseLike<boolean>;
24+
25+
/**
26+
* @deprecated This function will be removed in the next major version of the Sentry SDK.
27+
*/
2428
export declare function lastEventId(): string | undefined;
2529

2630
export default sentryAstro;

packages/browser/src/exports.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export type {
1818
} from '@sentry/types';
1919

2020
export type { BrowserOptions } from './client';
21+
22+
// eslint-disable-next-line deprecation/deprecation
2123
export type { ReportDialogOptions } from './helpers';
2224

2325
export {
@@ -39,6 +41,7 @@ export {
3941
getClient,
4042
getCurrentScope,
4143
Hub,
44+
// eslint-disable-next-line deprecation/deprecation
4245
lastEventId,
4346
makeMain,
4447
Scope,

packages/browser/src/helpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ export function wrap(
156156

157157
/**
158158
* All properties the report dialog supports
159+
*
160+
* @deprecated This type will be removed in the next major version of the Sentry SDK. `showReportDialog` will still be around, however the `eventId` option will now be required.
159161
*/
160162
export interface ReportDialogOptions {
161163
// eslint-disable-next-line @typescript-eslint/no-explicit-any

packages/browser/src/sdk.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,32 @@ export function init(options: BrowserOptions = {}): void {
133133
}
134134
}
135135

136-
/**
137-
* Present the user with a report dialog.
138-
*
139-
* @param options Everything is optional, we try to fetch all info need from the global scope.
140-
*/
141-
export function showReportDialog(options: ReportDialogOptions = {}, hub: Hub = getCurrentHub()): void {
136+
type NewReportDialogOptions = ReportDialogOptions & { eventId: string }; // eslint-disable-line
137+
138+
interface ShowReportDialogFunction {
139+
/**
140+
* Present the user with a report dialog.
141+
*
142+
* @param options Everything is optional, we try to fetch all info need from the global scope.
143+
*/
144+
(options: NewReportDialogOptions): void;
145+
146+
/**
147+
* Present the user with a report dialog.
148+
*
149+
* @param options Everything is optional, we try to fetch all info need from the global scope.
150+
*
151+
* @deprecated Please always pass an `options` argument with `eventId`. The `hub` argument will not be used in the next version of the SDK.
152+
*/
153+
// eslint-disable-next-line deprecation/deprecation
154+
(options?: ReportDialogOptions, hub?: Hub): void;
155+
}
156+
157+
export const showReportDialog: ShowReportDialogFunction = (
158+
// eslint-disable-next-line deprecation/deprecation
159+
options: ReportDialogOptions = {},
160+
hub: Hub = getCurrentHub(),
161+
) => {
142162
// doesn't work without a document (React Native)
143163
if (!WINDOW.document) {
144164
DEBUG_BUILD && logger.error('Global document not defined in showReportDialog call');
@@ -159,7 +179,10 @@ export function showReportDialog(options: ReportDialogOptions = {}, hub: Hub = g
159179
};
160180
}
161181

182+
// TODO(v8): Remove this entire if statement. `eventId` will be a required option.
183+
// eslint-disable-next-line deprecation/deprecation
162184
if (!options.eventId) {
185+
// eslint-disable-next-line deprecation/deprecation
163186
options.eventId = hub.lastEventId();
164187
}
165188

@@ -192,7 +215,7 @@ export function showReportDialog(options: ReportDialogOptions = {}, hub: Hub = g
192215
} else {
193216
DEBUG_BUILD && logger.error('Not injecting report dialog. No injection point found in HTML');
194217
}
195-
}
218+
};
196219

197220
/**
198221
* This function is here to be API compatible with the loader.

packages/browser/test/unit/index.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ describe('SentryBrowser', () => {
8888
getCurrentScope().setUser(EX_USER);
8989
getCurrentHub().bindClient(client);
9090

91+
// eslint-disable-next-line deprecation/deprecation
9192
showReportDialog();
9293

9394
expect(getReportDialogEndpoint).toHaveBeenCalledTimes(1);
@@ -102,6 +103,7 @@ describe('SentryBrowser', () => {
102103
getCurrentHub().bindClient(client);
103104

104105
const DIALOG_OPTION_USER = { email: '[email protected]' };
106+
// eslint-disable-next-line deprecation/deprecation
105107
showReportDialog({ user: DIALOG_OPTION_USER });
106108

107109
expect(getReportDialogEndpoint).toHaveBeenCalledTimes(1);
@@ -135,6 +137,7 @@ describe('SentryBrowser', () => {
135137

136138
it('should call `onClose` when receiving `__sentry_reportdialog_closed__` MessageEvent', async () => {
137139
const onClose = jest.fn();
140+
// eslint-disable-next-line deprecation/deprecation
138141
showReportDialog({ onClose });
139142

140143
await waitForPostMessage('__sentry_reportdialog_closed__');
@@ -149,6 +152,7 @@ describe('SentryBrowser', () => {
149152
const onClose = jest.fn(() => {
150153
throw new Error();
151154
});
155+
// eslint-disable-next-line deprecation/deprecation
152156
showReportDialog({ onClose });
153157

154158
await waitForPostMessage('__sentry_reportdialog_closed__');
@@ -161,6 +165,7 @@ describe('SentryBrowser', () => {
161165

162166
it('should not call `onClose` for other MessageEvents', async () => {
163167
const onClose = jest.fn();
168+
// eslint-disable-next-line deprecation/deprecation
164169
showReportDialog({ onClose });
165170

166171
await waitForPostMessage('some_message');

packages/bun/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export {
4747
getGlobalScope,
4848
getIsolationScope,
4949
Hub,
50+
// eslint-disable-next-line deprecation/deprecation
5051
lastEventId,
5152
makeMain,
5253
runWithAsyncContext,

packages/core/src/exports.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ export async function close(timeout?: number): Promise<boolean> {
300300
* This is the getter for lastEventId.
301301
*
302302
* @returns The last event id of a captured event.
303+
* @deprecated This function will be removed in the next major version of the Sentry SDK.
303304
*/
304305
export function lastEventId(): string | undefined {
305306
return getCurrentHub().lastEventId();

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export {
1717
// eslint-disable-next-line deprecation/deprecation
1818
configureScope,
1919
flush,
20+
// eslint-disable-next-line deprecation/deprecation
2021
lastEventId,
2122
startTransaction,
2223
setContext,

packages/deno/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export {
4646
getGlobalScope,
4747
getIsolationScope,
4848
Hub,
49+
// eslint-disable-next-line deprecation/deprecation
4950
lastEventId,
5051
makeMain,
5152
runWithAsyncContext,

packages/node-experimental/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export {
2222
captureMessage,
2323
addGlobalEventProcessor,
2424
addEventProcessor,
25+
// eslint-disable-next-line deprecation/deprecation
2526
lastEventId,
2627
setContext,
2728
setExtra,

packages/node-experimental/src/sdk/api.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ export function withIsolationScope<T>(callback: (isolationScope: Scope) => T): T
5656
});
5757
}
5858

59-
/** Get the ID of the last sent error event. */
59+
/**
60+
* Get the ID of the last sent error event.
61+
* @deprecated This function will be removed in the next major version of the Sentry SDK.
62+
*/
6063
export function lastEventId(): string | undefined {
6164
return getCurrentScope().lastEventId();
6265
}

packages/node/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export {
4646
getGlobalScope,
4747
getIsolationScope,
4848
Hub,
49+
// eslint-disable-next-line deprecation/deprecation
4950
lastEventId,
5051
makeMain,
5152
runWithAsyncContext,

packages/react/src/errorboundary.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export type ErrorBoundaryProps = {
2828
* Options to be passed into the Sentry report dialog.
2929
* No-op if {@link showDialog} is false.
3030
*/
31-
dialogOptions?: ReportDialogOptions | undefined;
31+
// eslint-disable-next-line deprecation/deprecation
32+
dialogOptions?: Omit<ReportDialogOptions, 'eventId'> | undefined;
3233
/**
3334
* A fallback component that gets rendered when the error boundary encounters an error.
3435
*
@@ -111,6 +112,7 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
111112
this._openFallbackReportDialog = false;
112113
client.on('afterSendEvent', event => {
113114
if (!event.type && event.event_id === this._lastEventId) {
115+
// eslint-disable-next-line deprecation/deprecation
114116
showReportDialog({ ...props.dialogOptions, eventId: this._lastEventId });
115117
}
116118
});

packages/remix/src/index.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export {
4747
makeNodeTransport,
4848
defaultIntegrations,
4949
defaultStackParser,
50+
// eslint-disable-next-line deprecation/deprecation
5051
lastEventId,
5152
flush,
5253
close,

packages/remix/src/index.types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ declare const runtime: 'client' | 'server';
2525

2626
export const close = runtime === 'client' ? clientSdk.close : serverSdk.close;
2727
export const flush = runtime === 'client' ? clientSdk.flush : serverSdk.flush;
28+
29+
/**
30+
* @deprecated This function will be removed in the next major version of the Sentry SDK.
31+
*/
32+
// eslint-disable-next-line deprecation/deprecation
2833
export const lastEventId = runtime === 'client' ? clientSdk.lastEventId : serverSdk.lastEventId;

packages/serverless/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export {
5151
flush,
5252
getSentryRelease,
5353
init,
54+
// eslint-disable-next-line deprecation/deprecation
5455
lastEventId,
5556
DEFAULT_USER_INCLUDES,
5657
addRequestDataToEvent,

packages/sveltekit/src/index.types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@ export declare const defaultStackParser: StackParser;
4444

4545
export declare function close(timeout?: number | undefined): PromiseLike<boolean>;
4646
export declare function flush(timeout?: number | undefined): PromiseLike<boolean>;
47+
48+
/**
49+
* @deprecated This function will be removed in the next major version of the Sentry SDK.
50+
*/
4751
export declare function lastEventId(): string | undefined;

packages/sveltekit/src/server/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export {
4545
makeNodeTransport,
4646
defaultIntegrations,
4747
defaultStackParser,
48+
// eslint-disable-next-line deprecation/deprecation
4849
lastEventId,
4950
flush,
5051
close,

packages/vercel-edge/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export {
4646
getGlobalScope,
4747
getIsolationScope,
4848
Hub,
49+
// eslint-disable-next-line deprecation/deprecation
4950
lastEventId,
5051
makeMain,
5152
runWithAsyncContext,

0 commit comments

Comments
 (0)