Skip to content

feat(browser)!: Remove captureUserFeedback method #14820

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
Dec 23, 2024
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Sentry.captureUserFeedback({
Sentry.captureFeedback({
eventId: 'test_event_id',
email: 'test_email',
comments: 'test_comments',
message: 'test_comments',
name: 'test_name',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { expect } from '@playwright/test';
import type { FeedbackEvent } from '@sentry/core';

import { sentryTest } from '../../../../utils/fixtures';
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';

sentryTest('should capture simple user feedback', async ({ getLocalTestUrl, page }) => {
const url = await getLocalTestUrl({ testDir: __dirname });

const eventData = await getFirstSentryEnvelopeRequest<FeedbackEvent>(page, url);

expect(eventData.contexts).toMatchObject(
expect.objectContaining({
feedback: {
contact_email: 'test_email',
message: 'test_comments',
name: 'test_name',
},
}),
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ window.Sentry = Sentry;
Sentry.init({
dsn: 'https://[email protected]/1337',
beforeSend(event) {
Sentry.captureUserFeedback({
event_id: event.event_id,
Sentry.captureFeedback({
associatedEventId: event.event_id,
name: 'John Doe',
email: '[email protected]',
comments: 'This feedback should be attached associated with the captured message',
message: 'This feedback should be attached associated with the captured error',
});
return event;
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import { expect } from '@playwright/test';
import type { Event, UserFeedback } from '@sentry/core';
import type { Event, FeedbackEvent } from '@sentry/core';

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

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

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

expect(data).toHaveLength(2);

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

expect(feedback).toEqual({
comments: 'This feedback should be attached associated with the captured error',
email: '[email protected]',
event_id: errorEvent.event_id,
name: 'John Doe',
});
expect(feedback.contexts).toEqual(
expect.objectContaining({
feedback: {
associated_event_id: errorEvent.event_id,
message: 'This feedback should be attached associated with the captured error',
contact_email: '[email protected]',
name: 'John Doe',
},
}),
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ window.Sentry = Sentry;
Sentry.init({
dsn: 'https://[email protected]/1337',
beforeSend(event) {
Sentry.captureUserFeedback({
event_id: event.event_id,
Sentry.captureFeedback({
associatedEventId: event.event_id,
name: 'John Doe',
email: '[email protected]',
comments: 'This feedback should be attached associated with the captured error',
message: 'This feedback should be attached associated with the captured message',
});
return event;
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import { expect } from '@playwright/test';
import type { Event, UserFeedback } from '@sentry/core';
import type { Event, FeedbackEvent } from '@sentry/core';

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

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

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

expect(data).toHaveLength(2);

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

expect(feedback).toEqual({
comments: 'This feedback should be attached associated with the captured message',
email: '[email protected]',
event_id: errorEvent.event_id,
name: 'John Doe',
});
expect(feedback.contexts).toEqual(
expect.objectContaining({
feedback: {
message: 'This feedback should be attached associated with the captured message',
contact_email: '[email protected]',
associated_event_id: errorEvent.event_id,
name: 'John Doe',
},
}),
);
});

This file was deleted.

8 changes: 8 additions & 0 deletions docs/migration/v8-to-v9.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ Sentry.init({

- 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.

### `@sentry/browser`

- The `captureUserFeedback` method has been removed. Use `captureFeedback` instead and update the `comments` field to `message`.

### Uncategorized (TODO)

TODO
Expand Down Expand Up @@ -128,6 +132,10 @@ Sentry.init({
- The `urlEncode` method has been removed. There is no replacement.
- The `getDomElement` method has been removed. There is no replacement.

### `@sentry/browser`

- The `captureUserFeedback` method has been removed. Use `captureFeedback` instead and update the `comments` field to `message`.

### `@sentry/nestjs`

- Removed `WithSentry` decorator. Use `SentryExceptionCaptured` instead.
Expand Down
27 changes: 1 addition & 26 deletions packages/browser/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ import type {
ParameterizedString,
Scope,
SeverityLevel,
UserFeedback,
} from '@sentry/core';
import { BaseClient, applySdkMetadata, getSDKSource, logger } from '@sentry/core';
import { DEBUG_BUILD } from './debug-build';
import { BaseClient, applySdkMetadata, getSDKSource } from '@sentry/core';
import { eventFromException, eventFromMessage } from './eventbuilder';
import { WINDOW } from './helpers';
import type { BrowserTransportOptions } from './transports/types';
import { createUserFeedbackEnvelope } from './userfeedback';

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

/**
* Sends user feedback to Sentry.
*
* @deprecated Use `captureFeedback` instead.
*/
public captureUserFeedback(feedback: UserFeedback): void {
if (!this._isEnabled()) {
DEBUG_BUILD && logger.warn('SDK not enabled, will not capture user feedback.');
return;
}

const envelope = createUserFeedbackEnvelope(feedback, {
metadata: this.getSdkMetadata(),
dsn: this.getDsn(),
tunnel: this.getOptions().tunnel,
});

// sendEnvelope should not throw
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.sendEnvelope(envelope);
}

/**
* @inheritDoc
*/
Expand Down
3 changes: 1 addition & 2 deletions packages/browser/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export {
addIntegration,
captureException,
captureEvent,
captureFeedback,
captureMessage,
close,
createTransport,
Expand Down Expand Up @@ -92,8 +93,6 @@ export {
init,
onLoad,
showReportDialog,
// eslint-disable-next-line deprecation/deprecation
captureUserFeedback,
} from './sdk';

export { breadcrumbsIntegration } from './integrations/breadcrumbs';
Expand Down
16 changes: 1 addition & 15 deletions packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
consoleSandbox,
dedupeIntegration,
functionToStringIntegration,
getClient,
getCurrentScope,
getIntegrationsToSetup,
getReportDialogEndpoint,
Expand All @@ -13,7 +12,7 @@ import {
stackParserFromStackParserOptions,
supportsFetch,
} from '@sentry/core';
import type { Client, DsnLike, Integration, Options, UserFeedback } from '@sentry/core';
import type { Client, DsnLike, Integration, Options } from '@sentry/core';
import type { BrowserClientOptions, BrowserOptions } from './client';
import { BrowserClient } from './client';
import { DEBUG_BUILD } from './debug-build';
Expand Down Expand Up @@ -307,16 +306,3 @@ export function forceLoad(): void {
export function onLoad(callback: () => void): void {
callback();
}

/**
* Captures user feedback and sends it to Sentry.
*
* @deprecated Use `captureFeedback` instead.
*/
export function captureUserFeedback(feedback: UserFeedback): void {
const client = getClient<BrowserClient>();
if (client) {
// eslint-disable-next-line deprecation/deprecation
client.captureUserFeedback(feedback);
}
}
Loading