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

export async function register() {
    const dsn = process.env.GLITCHTIP_DSN || process.env.NEXT_PUBLIC_GLITCHTIP_DSN;

    if (!dsn) {
        console.log("[Sentry] Instrumentation disabled - no DSN configured");
        return;
    }

    if (process.env.NEXT_RUNTIME === "nodejs") {
        // Server-side initialization
        Sentry.init({
            dsn,
            environment: process.env.NODE_ENV,
            sampleRate: 1.0,
            tracesSampleRate: 0.1,
            debug: process.env.NODE_ENV === "development",
        });
        console.log("[Sentry] Server initialized via instrumentation");
    }

    if (process.env.NEXT_RUNTIME === "edge") {
        // Edge runtime initialization
        Sentry.init({
            dsn,
            environment: process.env.NODE_ENV,
            sampleRate: 1.0,
            tracesSampleRate: 0.05,
        });
        console.log("[Sentry] Edge initialized via instrumentation");
    }
}
