Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

sentry: Enable reporting on portico and other unauth pages.

Alex Vandiver739d527b16f4
diff --git a/web/src/sentry.ts b/web/src/sentry.ts
index 231f348b0b1..036c6ba4044 100644
--- a/web/src/sentry.ts
+++ b/web/src/sentry.ts
@@ -8,7 +8,7 @@ import {page_params} from "./page_params";
type UserInfo = {
id?: string;
realm: string;
- role: string;
+ role?: string;
};
if (page_params.server_sentry_dsn) {
@@ -16,10 +16,18 @@ if (page_params.server_sentry_dsn) {
if (page_params.realm_uri !== undefined) {
url_matches.push(new RegExp("^" + _.escapeRegExp(page_params.realm_uri) + "/"));
}
- const sentry_key = page_params.realm_sentry_key || "(root)";
+ const sentry_key =
+ // No parameter is the portico pages, empty string is the empty realm
+ page_params.realm_sentry_key === undefined
+ ? "www"
+ : page_params.realm_sentry_key === ""
+ ? "(root)"
+ : page_params.realm_sentry_key;
const user_info: UserInfo = {
realm: sentry_key,
- role: page_params.is_owner
+ };
+ if (sentry_key !== "www") {
+ user_info.role = page_params.is_owner
? "Organization owner"
: page_params.is_admin
? "Organization administrator"
@@ -29,10 +37,12 @@ if (page_params.server_sentry_dsn) {
? "Guest"
: page_params.is_spectator
? "Spectator"
- : "Member",
- };
- if (page_params.user_id) {
- user_info.id = page_params.user_id.toString();
+ : page_params.user_id
+ ? "Member"
+ : "Logged out";
+ if (page_params.user_id) {
+ user_info.id = page_params.user_id.toString();
+ }
}
Sentry.init({
diff --git a/zerver/context_processors.py b/zerver/context_processors.py
index 041bcda7d9e..7a1dcf49f67 100644
--- a/zerver/context_processors.py
+++ b/zerver/context_processors.py
@@ -28,6 +28,7 @@ from zproject.backends import (
password_auth_enabled,
require_email_format_usernames,
)
+from zproject.config import get_config
DEFAULT_PAGE_PARAMS: Mapping[str, Any] = {
"development_environment": settings.DEVELOPMENT,
@@ -139,10 +140,19 @@ def zulip_default_context(request: HttpRequest) -> Dict[str, Any]:
f'<a href="mailto:{escape(support_email)}">{escape(support_email)}</a>'
)
- default_page_params = {
+ default_page_params: Dict[str, Any] = {
**DEFAULT_PAGE_PARAMS,
+ "server_sentry_dsn": settings.SENTRY_FRONTEND_DSN,
"request_language": get_language(),
}
+ if settings.SENTRY_FRONTEND_DSN is not None:
+ if realm is not None:
+ default_page_params["realm_sentry_key"] = realm.string_id
+ default_page_params["server_sentry_environment"] = get_config(
+ "machine", "deploy_type", "development"
+ )
+ default_page_params["server_sentry_sample_rate"] = settings.SENTRY_FRONTEND_SAMPLE_RATE
+ default_page_params["server_sentry_trace_rate"] = settings.SENTRY_FRONTEND_TRACE_RATE
context = {
"root_domain_landing_page": settings.ROOT_DOMAIN_LANDING_PAGE,