Send user text as context

This commit is contained in:
James Salter 2021-08-11 17:19:15 +01:00
parent c6202bf653
commit ba1618812c
3 changed files with 24 additions and 22 deletions

View file

@ -29,7 +29,7 @@ import BaseDialog from "./BaseDialog";
import Field from '../elements/Field';
import Spinner from "../elements/Spinner";
import DialogButtons from "../elements/DialogButtons";
import {sendSentryReport} from "../../../sentry";
import { sendSentryReport } from "../../../sentry";
interface IProps {
onFinished: (success: boolean) => void;
@ -116,11 +116,7 @@ export default class BugReportDialog extends React.Component<IProps, IState> {
}
});
// Send a Sentry report if the user agreed to send logs and if there's an error object (Sentry won't be very
// useful for grouping errors without exception information to aggregate with)
if (sendLogs) {
sendSentryReport(userText, this.props.label, this.props.error);
}
sendSentryReport(userText, this.state.issueUrl, this.props.error);
};
private onDownload = async (): Promise<void> => {

View file

@ -51,6 +51,7 @@ export default class TileErrorBoundary extends React.Component<IProps, IState> {
private onBugReport = (): void => {
Modal.createTrackedDialog('Bug Report Dialog', '', BugReportDialog, {
label: 'react-soft-crash-tile',
error: this.state.error,
});
};

View file

@ -98,30 +98,35 @@ function getDeviceContext(client: MatrixClient): Record<String, String> {
return result;
}
async function getContext() {
async function getContexts() {
const client = MatrixClientPeg.get();
return {
"contexts": {
"user": getUserContext(client),
"crypto": await getCryptoContext(client),
"device": getDeviceContext(client),
"storage": await getStorageOptions(),
},
"extra": {
},
"user": getUserContext(client),
"crypto": await getCryptoContext(client),
"device": getDeviceContext(client),
"storage": await getStorageOptions(),
};
}
export async function sendSentryReport(userText: string, label: string, error: Error): void {
if (!SdkConfig.get()["sentry"]) return;
export async function sendSentryReport(userText: string, issueUrl: string, error: Error): void {
const sentryConfig = SdkConfig.get()["sentry"];
if (!sentryConfig) return;
// Ignore reports without errors, as they're not useful in sentry and can't easily be aggregated
const captureContext = {
"contexts": await getContexts(),
"extra": {
"userText": userText,
"issue_url": issueUrl,
},
};
// If there's no error and no issueUrl, the report will just produce non-grouped noise in Sentry, so don't
// upload it
if (error) {
Sentry.captureException(error, await getContext());
Sentry.captureException(error, captureContext);
} else if (issueUrl) {
Sentry.captureMessage(`Issue: ${issueUrl}`, captureContext);
}
// TODO: use https://docs.sentry.io/api/projects/submit-user-feedback/ to submit userText
}
interface ISentryConfig {