// Grafana Alloy — Faro RUM receiver
//
// Receives browser telemetry (Web Vitals, traces, logs, exceptions) from the
// LibNovel SvelteKit frontend via the @grafana/faro-web-sdk.
//
// Pipeline:
//   faro.receiver  → receives HTTP POST /collect from browsers
//   otelcol.exporter.otlphttp → forwards traces to OTel Collector → Tempo
//   loki.write                → forwards logs/exceptions to Loki
//
// The Faro endpoint is exposed publicly at faro.libnovel.cc via cloudflared.
// CORS is configured to allow requests from libnovel.cc.

faro.receiver "faro" {
  server {
    listen_address = "0.0.0.0"
    listen_port    = 12347

    cors_allowed_origins = ["https://libnovel.cc", "https://www.libnovel.cc"]
  }

  output {
    logs   = [loki.write.faro.receiver]
    traces = [otelcol.exporter.otlphttp.faro.input]
  }
}

// Forward Faro traces to the OTel Collector (which routes to Tempo)
otelcol.exporter.otlphttp "faro" {
  client {
    endpoint = "http://otel-collector:4318"
    tls {
      insecure = true
    }
  }
}

// Forward Faro logs/exceptions directly to Loki
loki.write "faro" {
  endpoint {
    url = "http://loki:3100/loki/api/v1/push"
  }
}
