-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(feedback): Add
captureFeedback
method
- Loading branch information
Showing
11 changed files
with
117 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import type { Attachment, EventHint, FeedbackEvent } from '@sentry/types'; | ||
import { getClient, getCurrentScope } from './currentScopes'; | ||
import { createAttachmentEnvelope } from './envelope'; | ||
|
||
interface FeedbackParams { | ||
message: string; | ||
name?: string; | ||
email?: string; | ||
attachments?: Attachment[]; | ||
url?: string; | ||
source?: string; | ||
relatedEventId?: string; | ||
} | ||
|
||
/** | ||
* Send user feedback to Sentry. | ||
*/ | ||
export function captureFeedback( | ||
feedbackParams: FeedbackParams, | ||
hint?: EventHint & { includeReplay?: boolean }, | ||
): string { | ||
const { message, name, email, url, source, attachments } = feedbackParams; | ||
|
||
const client = getClient(); | ||
const transport = client && client.getTransport(); | ||
const dsn = client && client.getDsn(); | ||
|
||
if (!client || !transport || !dsn) { | ||
throw new Error('Invalid Sentry client'); | ||
} | ||
|
||
const feedbackEvent: FeedbackEvent = { | ||
contexts: { | ||
feedback: { | ||
contact_email: email, | ||
name, | ||
message, | ||
url, | ||
source, | ||
}, | ||
}, | ||
type: 'feedback', | ||
level: 'info', | ||
}; | ||
|
||
// TODO: What to do with `relatedEventId` ? | ||
|
||
if (client) { | ||
client.emit('beforeSendFeedback', feedbackEvent, hint); | ||
} | ||
|
||
const eventId = getCurrentScope().captureEvent(feedbackEvent, hint); | ||
|
||
// For now, we have to send attachments manually in a separate envelope | ||
// Because we do not support attachments in the feedback envelope | ||
// Once the Sentry API properly supports this, we can get rid of this and send it through the event envelope | ||
if (client && attachments && attachments.length) { | ||
const transport = client.getTransport(); | ||
const dsn = client.getDsn(); | ||
|
||
if (dsn && transport) { | ||
// TODO: https://docs.sentry.io/platforms/javascript/enriching-events/attachments/ | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
void transport.send( | ||
createAttachmentEnvelope( | ||
feedbackEvent, | ||
attachments, | ||
dsn, | ||
client.getOptions()._metadata, | ||
client.getOptions().tunnel, | ||
), | ||
); | ||
} | ||
} | ||
|
||
return eventId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.