Skip to content

Commit

Permalink
Make user feedback tree shakable
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich committed Apr 5, 2023
1 parent a0394a0 commit e295944
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 38 deletions.
14 changes: 0 additions & 14 deletions packages/browser/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
Options,
Severity,
SeverityLevel,
UserFeedback,
} from '@sentry/types';
import { createClientReportEnvelope, dsnToString, getSDKSource, logger } from '@sentry/utils';

Expand All @@ -17,7 +16,6 @@ import { WINDOW } from './helpers';
import type { Breadcrumbs } from './integrations';
import { BREADCRUMB_INTEGRATION_ID } from './integrations/breadcrumbs';
import type { BrowserTransportOptions } from './transports/types';
import { createUserFeedbackEnvelope } from './userfeedback';

/**
* Configuration options for the Sentry Browser SDK.
Expand Down Expand Up @@ -108,18 +106,6 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
super.sendEvent(event, hint);
}

/**
* Sends user feedback to Sentry.
*/
public captureUserFeedback(feedback: UserFeedback): void {
const envelope = createUserFeedbackEnvelope(feedback, {
metadata: this.getSdkMetadata(),
dsn: this.getDsn(),
tunnel: this.getOptions().tunnel,
});
void this._sendEnvelope(envelope);
}

/**
* @inheritDoc
*/
Expand Down
14 changes: 2 additions & 12 deletions packages/browser/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ export {
winjsStackLineParser,
} from './stack-parsers';
export { eventFromException, eventFromMessage } from './eventbuilder';
export {
defaultIntegrations,
forceLoad,
init,
lastEventId,
onLoad,
showReportDialog,
flush,
close,
wrap,
captureUserFeedback,
} from './sdk';
export { defaultIntegrations, forceLoad, init, lastEventId, onLoad, showReportDialog, flush, close, wrap } from './sdk';
export { captureUserFeedback } from './userfeedback';
export { GlobalHandlers, TryCatch, Breadcrumbs, LinkedErrors, HttpContext, Dedupe } from './integrations';
11 changes: 0 additions & 11 deletions packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
initAndBind,
Integrations as CoreIntegrations,
} from '@sentry/core';
import type { UserFeedback } from '@sentry/types';
import {
addInstrumentationHandler,
logger,
Expand Down Expand Up @@ -290,13 +289,3 @@ function startSessionTracking(): void {
}
});
}

/**
* Captures user feedback and sends it to Sentry.
*/
export function captureUserFeedback(feedback: UserFeedback): void {
const client = getCurrentHub().getClient<BrowserClient>();
if (client) {
client.captureUserFeedback(feedback);
}
}
27 changes: 26 additions & 1 deletion packages/browser/src/userfeedback.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import { getCurrentHub } from '@sentry/core';
import type { DsnComponents, EventEnvelope, SdkMetadata, UserFeedback, UserFeedbackItem } from '@sentry/types';
import { createEnvelope, dsnToString } from '@sentry/utils';
import { createEnvelope, dsnToString, logger } from '@sentry/utils';

/**
* Sends user feedback to Sentry.
*/
export function captureUserFeedback(feedback: UserFeedback): void {
const hub = getCurrentHub();
const client = hub.getClient();
const transport = client && client.getTransport();

if (!transport) {
if (__DEBUG_BUILD__) {
logger.log('[UserFeedback] getTransport did not return a Transport, user feedback will not be sent.');
}
return;
}

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

void transport.send(envelope);
}

/**
* Creates an envelope from a user feedback.
Expand Down

0 comments on commit e295944

Please sign in to comment.