-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsentry-urls.ts
More file actions
223 lines (204 loc) · 6.19 KB
/
sentry-urls.ts
File metadata and controls
223 lines (204 loc) · 6.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/**
* Sentry URL Utilities
*
* Utilities for constructing Sentry web URLs.
* Supports self-hosted instances via SENTRY_URL environment variable.
*/
import {
DEFAULT_SENTRY_HOST,
DEFAULT_SENTRY_URL,
getConfiguredSentryUrl,
} from "./constants.js";
/**
* Get the Sentry web base URL.
* Supports self-hosted instances via SENTRY_URL env var.
*/
export function getSentryBaseUrl(): string {
return getConfiguredSentryUrl() ?? DEFAULT_SENTRY_URL;
}
/**
* Build the org-scoped base URL using the subdomain pattern.
* E.g. "https://sentry.io" + "my-org" → "https://my-org.sentry.io"
*
* @param orgSlug - Organization slug
* @returns Origin URL with org as subdomain
*/
export function getOrgBaseUrl(orgSlug: string): string {
const base = getSentryBaseUrl();
if (!isSentrySaasUrl(base)) {
return base;
}
const parsed = new URL(base);
parsed.hostname = `${orgSlug}.${parsed.hostname}`;
return parsed.origin;
}
function isSaaS(): boolean {
return isSentrySaasUrl(getSentryBaseUrl());
}
/**
* Check if a URL is a Sentry SaaS domain.
*
* Used to determine if multi-region support should be enabled and to
* validate region URLs before sending authenticated requests.
*
* @param url - URL string to validate
* @returns true if the hostname is sentry.io or a subdomain of sentry.io
*/
export function isSentrySaasUrl(url: string): boolean {
try {
const parsed = new URL(url);
return (
parsed.hostname === DEFAULT_SENTRY_HOST ||
parsed.hostname.endsWith(`.${DEFAULT_SENTRY_HOST}`)
);
} catch {
return false;
}
}
/**
* Build URL to view an organization in Sentry.
*
* @param orgSlug - Organization slug
* @returns Full URL to the organization page
*/
export function buildOrgUrl(orgSlug: string): string {
if (isSaaS()) {
return `${getOrgBaseUrl(orgSlug)}/`;
}
return `${getSentryBaseUrl()}/organizations/${orgSlug}/`;
}
/**
* Build URL to view a project in Sentry.
*
* @param orgSlug - Organization slug
* @param projectSlug - Project slug
* @returns Full URL to the project settings page
*/
export function buildProjectUrl(orgSlug: string, projectSlug: string): string {
if (isSaaS()) {
return `${getOrgBaseUrl(orgSlug)}/settings/projects/${projectSlug}/`;
}
return `${getSentryBaseUrl()}/settings/${orgSlug}/projects/${projectSlug}/`;
}
/**
* Build URL to view an issue in Sentry.
*
* @param orgSlug - Organization slug
* @param issueId - Numeric issue ID
* @returns Full URL to the issue detail page
*/
export function buildIssueUrl(orgSlug: string, issueId: string): string {
if (isSaaS()) {
return `${getOrgBaseUrl(orgSlug)}/issues/${issueId}/`;
}
return `${getSentryBaseUrl()}/organizations/${orgSlug}/issues/${issueId}/`;
}
/**
* Build URL to search for an event in Sentry.
* Uses the issues search with event.id filter.
*
* @param orgSlug - Organization slug
* @param eventId - Event ID (hexadecimal)
* @returns Full URL to search results showing the event
*/
export function buildEventSearchUrl(orgSlug: string, eventId: string): string {
if (isSaaS()) {
return `${getOrgBaseUrl(orgSlug)}/issues/?query=event.id:${eventId}`;
}
return `${getSentryBaseUrl()}/organizations/${orgSlug}/issues/?query=event.id:${eventId}`;
}
// Settings URLs
/**
* Build URL to organization settings page.
*
* @param orgSlug - Organization slug
* @param hash - Optional anchor hash (e.g., "hideAiFeatures")
* @returns Full URL to the organization settings page
*/
export function buildOrgSettingsUrl(orgSlug: string, hash?: string): string {
const url = isSaaS()
? `${getOrgBaseUrl(orgSlug)}/settings/`
: `${getSentryBaseUrl()}/settings/${orgSlug}/`;
return hash ? `${url}#${hash}` : url;
}
/**
* Build URL to Seer settings page.
*
* @param orgSlug - Organization slug
* @returns Full URL to the Seer settings page
*/
export function buildSeerSettingsUrl(orgSlug: string): string {
if (isSaaS()) {
return `${getOrgBaseUrl(orgSlug)}/settings/seer/`;
}
return `${getSentryBaseUrl()}/settings/${orgSlug}/seer/`;
}
/**
* Build URL to billing page with optional product filter.
*
* @param orgSlug - Organization slug
* @param product - Optional product to highlight (e.g., "seer")
* @returns Full URL to the billing overview page
*/
export function buildBillingUrl(orgSlug: string, product?: string): string {
const base = isSaaS()
? `${getOrgBaseUrl(orgSlug)}/settings/billing/overview/`
: `${getSentryBaseUrl()}/settings/${orgSlug}/billing/overview/`;
return product ? `${base}?product=${product}` : base;
}
// Logs URLs
/**
* Build URL to the Logs explorer, optionally filtered to a specific log entry.
*
* @param orgSlug - Organization slug
* @param logId - Optional log item ID to filter to
* @returns Full URL to the Logs explorer
*/
export function buildLogsUrl(orgSlug: string, logId?: string): string {
const base = isSaaS()
? `${getOrgBaseUrl(orgSlug)}/explore/logs/`
: `${getSentryBaseUrl()}/organizations/${orgSlug}/explore/logs/`;
return logId ? `${base}?query=sentry.item_id:${logId}` : base;
}
// Dashboard URLs
/**
* Build URL to the dashboards list page.
*
* @param orgSlug - Organization slug
* @returns Full URL to the dashboards list page
*/
export function buildDashboardsListUrl(orgSlug: string): string {
if (isSaaS()) {
return `${getOrgBaseUrl(orgSlug)}/dashboards/`;
}
return `${getSentryBaseUrl()}/organizations/${orgSlug}/dashboards/`;
}
/**
* Build URL to view a specific dashboard.
*
* @param orgSlug - Organization slug
* @param dashboardId - Dashboard ID
* @returns Full URL to the dashboard view page
*/
export function buildDashboardUrl(
orgSlug: string,
dashboardId: string
): string {
if (isSaaS()) {
return `${getOrgBaseUrl(orgSlug)}/dashboard/${dashboardId}/`;
}
return `${getSentryBaseUrl()}/organizations/${orgSlug}/dashboard/${dashboardId}/`;
}
/**
* Build URL to view a trace in Sentry.
*
* @param orgSlug - Organization slug
* @param traceId - Trace ID (32-character hex string)
* @returns Full URL to the trace view
*/
export function buildTraceUrl(orgSlug: string, traceId: string): string {
if (isSaaS()) {
return `${getOrgBaseUrl(orgSlug)}/traces/${traceId}/`;
}
return `${getSentryBaseUrl()}/organizations/${orgSlug}/traces/${traceId}/`;
}