Skip to content

Commit e682512

Browse files
authored
feat(browser)!: Remove captureUserFeedback method (#14820)
Use `captureFeedback` as a drop-in replacement instead. Closes: #14383
1 parent 65531f3 commit e682512

File tree

14 files changed

+66
-87
lines changed

14 files changed

+66
-87
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Sentry.captureUserFeedback({
1+
Sentry.captureFeedback({
22
eventId: 'test_event_id',
33
email: 'test_email',
4-
comments: 'test_comments',
4+
message: 'test_comments',
55
name: 'test_name',
66
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect } from '@playwright/test';
2+
import type { FeedbackEvent } from '@sentry/core';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
6+
7+
sentryTest('should capture simple user feedback', async ({ getLocalTestUrl, page }) => {
8+
const url = await getLocalTestUrl({ testDir: __dirname });
9+
10+
const eventData = await getFirstSentryEnvelopeRequest<FeedbackEvent>(page, url);
11+
12+
expect(eventData.contexts).toMatchObject(
13+
expect.objectContaining({
14+
feedback: {
15+
contact_email: 'test_email',
16+
message: 'test_comments',
17+
name: 'test_name',
18+
},
19+
}),
20+
);
21+
});
+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ window.Sentry = Sentry;
55
Sentry.init({
66
dsn: 'https://[email protected]/1337',
77
beforeSend(event) {
8-
Sentry.captureUserFeedback({
9-
event_id: event.event_id,
8+
Sentry.captureFeedback({
9+
associatedEventId: event.event_id,
1010
name: 'John Doe',
1111
12-
comments: 'This feedback should be attached associated with the captured message',
12+
message: 'This feedback should be attached associated with the captured error',
1313
});
1414
return event;
1515
},
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
import { expect } from '@playwright/test';
2-
import type { Event, UserFeedback } from '@sentry/core';
2+
import type { Event, FeedbackEvent } from '@sentry/core';
33

44
import { sentryTest } from '../../../../utils/fixtures';
55
import { getMultipleSentryEnvelopeRequests } from '../../../../utils/helpers';
66

77
sentryTest('capture user feedback when captureException is called', async ({ getLocalTestUrl, page }) => {
88
const url = await getLocalTestUrl({ testDir: __dirname });
99

10-
const data = (await getMultipleSentryEnvelopeRequests(page, 2, { url })) as (Event | UserFeedback)[];
10+
const data = (await getMultipleSentryEnvelopeRequests(page, 2, { url })) as (Event | FeedbackEvent)[];
1111

1212
expect(data).toHaveLength(2);
1313

1414
const errorEvent = ('exception' in data[0] ? data[0] : data[1]) as Event;
15-
const feedback = ('exception' in data[0] ? data[1] : data[0]) as UserFeedback;
15+
const feedback = ('exception' in data[0] ? data[1] : data[0]) as FeedbackEvent;
1616

17-
expect(feedback).toEqual({
18-
comments: 'This feedback should be attached associated with the captured error',
19-
20-
event_id: errorEvent.event_id,
21-
name: 'John Doe',
22-
});
17+
expect(feedback.contexts).toEqual(
18+
expect.objectContaining({
19+
feedback: {
20+
associated_event_id: errorEvent.event_id,
21+
message: 'This feedback should be attached associated with the captured error',
22+
contact_email: '[email protected]',
23+
name: 'John Doe',
24+
},
25+
}),
26+
);
2327
});
+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ window.Sentry = Sentry;
55
Sentry.init({
66
dsn: 'https://[email protected]/1337',
77
beforeSend(event) {
8-
Sentry.captureUserFeedback({
9-
event_id: event.event_id,
8+
Sentry.captureFeedback({
9+
associatedEventId: event.event_id,
1010
name: 'John Doe',
1111
12-
comments: 'This feedback should be attached associated with the captured error',
12+
message: 'This feedback should be attached associated with the captured message',
1313
});
1414
return event;
1515
},
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
import { expect } from '@playwright/test';
2-
import type { Event, UserFeedback } from '@sentry/core';
2+
import type { Event, FeedbackEvent } from '@sentry/core';
33

44
import { sentryTest } from '../../../../utils/fixtures';
55
import { getMultipleSentryEnvelopeRequests } from '../../../../utils/helpers';
66

77
sentryTest('capture user feedback when captureMessage is called', async ({ getLocalTestUrl, page }) => {
88
const url = await getLocalTestUrl({ testDir: __dirname });
99

10-
const data = (await getMultipleSentryEnvelopeRequests(page, 2, { url })) as (Event | UserFeedback)[];
10+
const data = (await getMultipleSentryEnvelopeRequests(page, 2, { url })) as (Event | FeedbackEvent)[];
1111

1212
expect(data).toHaveLength(2);
1313

1414
const errorEvent = ('exception' in data[0] ? data[0] : data[1]) as Event;
15-
const feedback = ('exception' in data[0] ? data[1] : data[0]) as UserFeedback;
15+
const feedback = ('exception' in data[0] ? data[1] : data[0]) as FeedbackEvent;
1616

17-
expect(feedback).toEqual({
18-
comments: 'This feedback should be attached associated with the captured message',
19-
20-
event_id: errorEvent.event_id,
21-
name: 'John Doe',
22-
});
17+
expect(feedback.contexts).toEqual(
18+
expect.objectContaining({
19+
feedback: {
20+
message: 'This feedback should be attached associated with the captured message',
21+
contact_email: '[email protected]',
22+
associated_event_id: errorEvent.event_id,
23+
name: 'John Doe',
24+
},
25+
}),
26+
);
2327
});

dev-packages/browser-integration-tests/suites/public-api/captureUserFeedback/simple_feedback/test.ts

-18
This file was deleted.

docs/migration/v8-to-v9.md

+8
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ Sentry.init({
7272

7373
- When `skipOpenTelemetrySetup: true` is configured, `httpIntegration({ spans: false })` will be configured by default. This means that you no longer have to specify this yourself in this scenario. With this change, no spans are emitted once `skipOpenTelemetrySetup: true` is configured, without any further configuration being needed.
7474

75+
### `@sentry/browser`
76+
77+
- The `captureUserFeedback` method has been removed. Use `captureFeedback` instead and update the `comments` field to `message`.
78+
7579
### Uncategorized (TODO)
7680

7781
TODO
@@ -128,6 +132,10 @@ Sentry.init({
128132
- The `urlEncode` method has been removed. There is no replacement.
129133
- The `getDomElement` method has been removed. There is no replacement.
130134

135+
### `@sentry/browser`
136+
137+
- The `captureUserFeedback` method has been removed. Use `captureFeedback` instead and update the `comments` field to `message`.
138+
131139
### `@sentry/nestjs`
132140

133141
- Removed `WithSentry` decorator. Use `SentryExceptionCaptured` instead.

packages/browser/src/client.ts

+1-26
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ import type {
88
ParameterizedString,
99
Scope,
1010
SeverityLevel,
11-
UserFeedback,
1211
} from '@sentry/core';
13-
import { BaseClient, applySdkMetadata, getSDKSource, logger } from '@sentry/core';
14-
import { DEBUG_BUILD } from './debug-build';
12+
import { BaseClient, applySdkMetadata, getSDKSource } from '@sentry/core';
1513
import { eventFromException, eventFromMessage } from './eventbuilder';
1614
import { WINDOW } from './helpers';
1715
import type { BrowserTransportOptions } from './transports/types';
18-
import { createUserFeedbackEnvelope } from './userfeedback';
1916

2017
/**
2118
* Configuration options for the Sentry Browser SDK.
@@ -105,28 +102,6 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
105102
return eventFromMessage(this._options.stackParser, message, level, hint, this._options.attachStacktrace);
106103
}
107104

108-
/**
109-
* Sends user feedback to Sentry.
110-
*
111-
* @deprecated Use `captureFeedback` instead.
112-
*/
113-
public captureUserFeedback(feedback: UserFeedback): void {
114-
if (!this._isEnabled()) {
115-
DEBUG_BUILD && logger.warn('SDK not enabled, will not capture user feedback.');
116-
return;
117-
}
118-
119-
const envelope = createUserFeedbackEnvelope(feedback, {
120-
metadata: this.getSdkMetadata(),
121-
dsn: this.getDsn(),
122-
tunnel: this.getOptions().tunnel,
123-
});
124-
125-
// sendEnvelope should not throw
126-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
127-
this.sendEnvelope(envelope);
128-
}
129-
130105
/**
131106
* @inheritDoc
132107
*/

packages/browser/src/exports.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export {
2727
addIntegration,
2828
captureException,
2929
captureEvent,
30+
captureFeedback,
3031
captureMessage,
3132
close,
3233
createTransport,
@@ -92,8 +93,6 @@ export {
9293
init,
9394
onLoad,
9495
showReportDialog,
95-
// eslint-disable-next-line deprecation/deprecation
96-
captureUserFeedback,
9796
} from './sdk';
9897

9998
export { breadcrumbsIntegration } from './integrations/breadcrumbs';

packages/browser/src/sdk.ts

+1-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
consoleSandbox,
33
dedupeIntegration,
44
functionToStringIntegration,
5-
getClient,
65
getCurrentScope,
76
getIntegrationsToSetup,
87
getReportDialogEndpoint,
@@ -13,7 +12,7 @@ import {
1312
stackParserFromStackParserOptions,
1413
supportsFetch,
1514
} from '@sentry/core';
16-
import type { Client, DsnLike, Integration, Options, UserFeedback } from '@sentry/core';
15+
import type { Client, DsnLike, Integration, Options } from '@sentry/core';
1716
import type { BrowserClientOptions, BrowserOptions } from './client';
1817
import { BrowserClient } from './client';
1918
import { DEBUG_BUILD } from './debug-build';
@@ -307,16 +306,3 @@ export function forceLoad(): void {
307306
export function onLoad(callback: () => void): void {
308307
callback();
309308
}
310-
311-
/**
312-
* Captures user feedback and sends it to Sentry.
313-
*
314-
* @deprecated Use `captureFeedback` instead.
315-
*/
316-
export function captureUserFeedback(feedback: UserFeedback): void {
317-
const client = getClient<BrowserClient>();
318-
if (client) {
319-
// eslint-disable-next-line deprecation/deprecation
320-
client.captureUserFeedback(feedback);
321-
}
322-
}

0 commit comments

Comments
 (0)