import * as Sentry from "@sentry/browser";

Sentry.init({
	dsn: xhiveframework.boot.sentry_dsn,
	release: xhiveframework?.boot?.versions?.xhiveframework,
	autoSessionTracking: false,
	initialScope: {
		// don't use xhiveframework.session.user, it's set much later and will fail because of async loading
		user: { id: xhiveframework.boot.sitename },
		tags: { xhiveframework_user: xhiveframework.boot.user.name ?? "Unidentified" },
	},
	beforeSend(event, hint) {
		// Check if it was caused by xhiveframework.throw()
		if (
			hint.originalException instanceof Error &&
			hint.originalException.stack &&
			hint.originalException.stack.includes("xhiveframework.throw")
		) {
			return null;
		}
		return event;
	},
});
