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

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