Skip to content

Commit

Permalink
Basic pref-driven sentry replay loading
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed Jul 30, 2024
1 parent 15cbaf1 commit f4b0344
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions client/src/stores/userStore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as Sentry from "@sentry/vue";
import { defineStore } from "pinia";
import { computed, ref } from "vue";

import { type AnonymousUser, type User } from "@/api";
import { getGalaxyInstance } from "@/app";
import { useUserLocalStorage } from "@/composables/userLocalStorage";
import { useHistoryStore } from "@/stores/historyStore";
import {
Expand All @@ -14,10 +16,25 @@ import {
interface Preferences {
theme: string;
favorites: { tools: string[] };
sentryReplay?: boolean;
extra_user_preferences?: string; // This is actually a big JSON string that needs parsing on access
}

type ListViewMode = "grid" | "list";

export function allowSentryReplay(userPreferences: Preferences | null) {
// TODO: refactor into extra prefs handling to simplify access, this is
// overly similar to tool caching pref handling.
if (userPreferences?.extra_user_preferences) {
const extra_user_preferences = JSON.parse(userPreferences.extra_user_preferences);
const key = "use_sentry_replay|use_sentry_replay_checkbox";
const hasKey = key in extra_user_preferences;
return hasKey ? ["true", true].includes(extra_user_preferences[key]) : false;
} else {
return false;
}
}

export const useUserStore = defineStore("userStore", () => {
const currentUser = ref<User | AnonymousUser | null>(null);
const currentPreferences = ref<Preferences | null>(null);
Expand Down Expand Up @@ -73,6 +90,17 @@ export const useUserStore = defineStore("userStore", () => {
// load first few histories for user to start pagination
await historyStore.loadHistories();
}
// If a user has sentry replay enabled, turn on the integration now.
// TODO: refactor and move this to a more appropriate place
const Galaxy = getGalaxyInstance();
if (Galaxy.Sentry && allowSentryReplay(currentPreferences.value)) {
const replay = Sentry.replayIntegration({
// extra config we might want to configure? Masking text?
});
if (replay) {
Galaxy.Sentry.addIntegration(replay);
}
}
})
.catch((e) => {
console.error("Failed to load user", e);
Expand Down

0 comments on commit f4b0344

Please sign in to comment.