Skip to content

Commit 72216da

Browse files
feat: comprehensive sentry setup for studio, continuous tracing
1 parent 15ab9a1 commit 72216da

6 files changed

Lines changed: 507 additions & 461 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@appwrite.io/pink-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@5b26bb8",
3030
"@faker-js/faker": "^9.9.0",
3131
"@popperjs/core": "^2.11.8",
32-
"@sentry/sveltekit": "^8.55.0",
32+
"@sentry/sveltekit": "^10.25.0",
3333
"@stripe/stripe-js": "^3.5.0",
3434
"ai": "^2.2.37",
3535
"analytics": "^0.8.19",

pnpm-lock.yaml

Lines changed: 446 additions & 448 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hooks.client.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { AppwriteException } from '@appwrite.io/console';
22
import type { HandleClientError } from '@sveltejs/kit';
33
import { setupSentry } from '$lib/sentry';
44

5-
setupSentry({
6-
withSessionReplay: true
7-
});
5+
setupSentry();
86

97
export const handleError: HandleClientError = ({ error, message, status }) => {
108
console.error(error);

src/hooks.server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { handleErrorWithSentry, sentryHandle } from '@sentry/sveltekit';
33
import { setupSentry } from '$lib/sentry';
44

55
setupSentry({
6-
withSessionReplay: false
6+
withSessionReplay: false,
7+
withBrowserTracing: false
78
});
89

910
export const handle = sequence(sentryHandle());

src/lib/sentry.ts

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,41 @@ export function getTraceData(): {
2323
sentryTraceId?: string;
2424
sentryBaggage?: string;
2525
} {
26-
const traceData = Sentry.getTraceData();
27-
return {
28-
sentryTraceId: traceData['sentry-trace'],
29-
sentryBaggage: traceData.baggage
30-
};
26+
try {
27+
const traceData = Sentry.getTraceData();
28+
29+
if (traceData) {
30+
return {
31+
sentryTraceId: traceData['sentry-trace'],
32+
sentryBaggage: traceData.baggage
33+
}
34+
} else {
35+
return {
36+
sentryTraceId: undefined,
37+
sentryBaggage: undefined
38+
}
39+
}
40+
} catch (error) {
41+
return {
42+
sentryTraceId: undefined,
43+
sentryBaggage: undefined
44+
}
45+
}
3146
}
3247

33-
export function setupSentry({ withSessionReplay }: { withSessionReplay: boolean }) {
48+
export function setupSentry(
49+
{
50+
withSessionReplay = true,
51+
withBrowserTracing = true
52+
}: { withSessionReplay: boolean; withBrowserTracing: boolean } = {
53+
withSessionReplay: true,
54+
withBrowserTracing: true
55+
}
56+
) {
57+
if (Sentry.isInitialized()) {
58+
return;
59+
}
60+
3461
const dsn = env.PUBLIC_SENTRY_DSN;
3562
const environment = env.PUBLIC_SENTRY_ENVIRONMENT;
3663

@@ -53,6 +80,7 @@ export function setupSentry({ withSessionReplay }: { withSessionReplay: boolean
5380
};
5481

5582
const integrations = [];
83+
5684
if (withSessionReplay) {
5785
integrations.push(
5886
Sentry.replayIntegration({
@@ -62,6 +90,10 @@ export function setupSentry({ withSessionReplay }: { withSessionReplay: boolean
6290
);
6391
}
6492

93+
if (withBrowserTracing) {
94+
integrations.push(Sentry.browserTracingIntegration());
95+
}
96+
6597
Sentry.init({
6698
enabled: variables.enabled,
6799
dsn,
@@ -70,6 +102,14 @@ export function setupSentry({ withSessionReplay }: { withSessionReplay: boolean
70102
replaysOnErrorSampleRate: 1,
71103
integrations,
72104
debug: variables.debug,
73-
sendDefaultPii: true
105+
sendDefaultPii: true,
106+
tracePropagationTargets: [
107+
'localhost',
108+
/^\//,
109+
/^https:\/\/imagine\.dev(\/|$)/,
110+
/^https:\/\/ai-service\.imagine\.dev(\/|$)/,
111+
/^https:\/\/staging\.imagine\.dev(\/|$)/,
112+
/^https:\/\/ai-service\.staging\.imagine\.dev(\/|$)/
113+
]
74114
});
75115
}

src/lib/studio/studio-widget.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ensureMonacoStyles } from './monaco-style-manager';
77
import DEV_CSS_URL from '@imagine.dev/web-components/imagine-web-components.css?url';
88
import { getSessionId, getTraceData } from '$lib/sentry';
99
import type * as WebComponentsType from '@imagine.dev/web-components/web-components';
10+
import * as Sentry from '@sentry/sveltekit';
1011

1112
const COMPONENT_SELECTOR = 'imagine-web-components-wrapper[data-appwrite-studio]';
1213
const STYLE_ATTRIBUTE = 'data-appwrite-studio-style';
@@ -281,6 +282,14 @@ export async function initImagine(
281282
onManageDomains: (primaryDomain?: string) => void | Promise<void>;
282283
}
283284
) {
285+
const sessionId = getSessionId(userId);
286+
287+
Sentry.setTags({
288+
user_id: userId,
289+
session_id: sessionId,
290+
project_id: projectId,
291+
});
292+
284293
try {
285294
const { initImagineConfig, initImagineRouting } = await getWebComponents();
286295

@@ -294,7 +303,7 @@ export async function initImagine(
294303
},
295304
{
296305
initialTheme: get(app).themeInUse,
297-
consoleSessionId: getSessionId(userId),
306+
consoleSessionId: sessionId,
298307
sentryTraceId,
299308
sentryBaggage,
300309
callbacks

0 commit comments

Comments
 (0)