mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 14:35:27 +00:00
sentry: Add frontend event monitoring.
Zulip already has integrations for server-side Sentry integration; however, it has historically used the Zulip-specific `blueslip` library for monitoring browser-side errors. However, the latter sends errors to email, as well optionally to an internal `#errors` stream. While this is sufficient for low volumes of users, and useful in that it does not rely on outside services, at higher volumes it is very difficult to do any analysis or filtering of the errors. Client-side errors are exceptionally noisy, with many false positives due to browser extensions or similar, so determining real real errors from a stream of un-grouped emails or messages in a stream is quite difficult. Add a client-side Javascript sentry integration. To provide useful backtraces, this requires extending the pre-deploy hooks to upload the source-maps to Sentry. Additional keys are added to the non-public API of `page_params` to control the DSN, realm identifier, and sample rates.
This commit is contained in:
committed by
Tim Abbott
parent
fc40d74cda
commit
8f8a9f6f04
@@ -1,3 +1,4 @@
|
||||
import "../sentry";
|
||||
import "../webpack_public_path";
|
||||
import "../../debug-require";
|
||||
import "../alert_popup";
|
||||
|
||||
@@ -28,14 +28,23 @@ export const page_params: {
|
||||
realm_move_messages_between_streams_policy: number;
|
||||
realm_name_changes_disabled: boolean;
|
||||
realm_push_notifications_enabled: boolean;
|
||||
realm_sentry_key: string | undefined;
|
||||
realm_uri: string;
|
||||
realm_user_group_edit_policy: number;
|
||||
realm_waiting_period_threshold: number;
|
||||
request_language: string;
|
||||
server_avatar_changes_disabled: boolean;
|
||||
server_name_changes_disabled: boolean;
|
||||
server_sentry_dsn: string | undefined;
|
||||
server_sentry_environment: string | undefined;
|
||||
server_sentry_sample_rate: number | undefined;
|
||||
server_sentry_trace_rate: number | undefined;
|
||||
server_web_public_streams_enabled: boolean;
|
||||
translation_data: Record<string, string>;
|
||||
user_id: number | undefined;
|
||||
webpack_public_path: string;
|
||||
zulip_plan_is_not_limited: boolean;
|
||||
zulip_version: string;
|
||||
muted_users: {id: number; timestamp: number}[];
|
||||
} = $("#page-params").remove().data("params");
|
||||
const t2 = performance.now();
|
||||
|
||||
59
web/src/sentry.ts
Normal file
59
web/src/sentry.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import * as Sentry from "@sentry/browser";
|
||||
import {HttpClient as HttpClientIntegration} from "@sentry/integrations";
|
||||
import {BrowserTracing} from "@sentry/tracing";
|
||||
import _ from "lodash";
|
||||
|
||||
import {page_params} from "./page_params";
|
||||
|
||||
type UserInfo = {
|
||||
id?: string;
|
||||
realm: string;
|
||||
role: string;
|
||||
};
|
||||
|
||||
if (page_params.server_sentry_dsn) {
|
||||
const url_regex = new RegExp("^" + _.escapeRegExp(page_params.realm_uri) + "/");
|
||||
const user_info: UserInfo = {
|
||||
realm: page_params.realm_sentry_key!,
|
||||
role: page_params.is_owner
|
||||
? "Organization owner"
|
||||
: page_params.is_admin
|
||||
? "Organization administrator"
|
||||
: page_params.is_moderator
|
||||
? "Moderator"
|
||||
: page_params.is_guest
|
||||
? "Guest"
|
||||
: page_params.is_spectator
|
||||
? "Spectator"
|
||||
: "Member",
|
||||
};
|
||||
if (page_params.user_id) {
|
||||
user_info.id = page_params.user_id.toString();
|
||||
}
|
||||
|
||||
Sentry.init({
|
||||
dsn: page_params.server_sentry_dsn,
|
||||
environment: page_params.server_sentry_environment || "development",
|
||||
|
||||
release: "zulip-server@" + ZULIP_VERSION,
|
||||
integrations: [
|
||||
new BrowserTracing({
|
||||
tracePropagationTargets: [url_regex],
|
||||
}),
|
||||
new HttpClientIntegration({
|
||||
failedRequestStatusCodes: [500, 502, 503, 504],
|
||||
failedRequestTargets: [url_regex],
|
||||
}),
|
||||
],
|
||||
allowUrls: [url_regex, page_params.webpack_public_path],
|
||||
sampleRate: page_params.server_sentry_sample_rate || 0,
|
||||
tracesSampleRate: page_params.server_sentry_trace_rate || 0,
|
||||
initialScope: {
|
||||
tags: {
|
||||
realm: page_params.realm_sentry_key || "(root)",
|
||||
server_version: page_params.zulip_version,
|
||||
},
|
||||
user: user_info,
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user