# OpenTelemetry Collector configuration for deflock-api
# Receives logs and metrics from the API, forwards to Grafana Cloud via the
# unified OTLP gateway (routes logs → Loki, metrics → Mimir automatically).
#
# Required environment variables (set in /etc/systemd/system/otelcol.service):
#   GRAFANA_OTLP_ENDPOINT   e.g. https://otlp-gateway-prod-us-east-0.grafana.net/otlp
#                           Found in Grafana Cloud portal → OpenTelemetry
#   GRAFANA_INSTANCE_ID     numeric stack ID (same for all signals)
#   GRAFANA_API_KEY         Grafana Cloud API key (Metrics Publisher role is sufficient)

receivers:
  otlp:
    protocols:
      http:
        endpoint: 127.0.0.1:4318

processors:
  batch:
    timeout: 5s
    send_batch_size: 256

  # Drop 404 log records to reduce noise
  filter/drop_404_logs:
    error_mode: ignore
    logs:
      log_record:
        - 'attributes["http.response.status_code"] == 404'

exporters:
  otlp_http/grafana:
    endpoint: ${env:GRAFANA_OTLP_ENDPOINT}
    auth:
      authenticator: basicauth/grafana

extensions:
  basicauth/grafana:
    client_auth:
      username: ${env:GRAFANA_INSTANCE_ID}
      password: ${env:GRAFANA_API_KEY}

  health_check:
    endpoint: 127.0.0.1:13133

service:
  telemetry:
    metrics:
      level: none
  extensions: [basicauth/grafana, health_check]
  pipelines:
    logs:
      receivers: [otlp]
      processors: [filter/drop_404_logs, batch]
      exporters: [otlp_http/grafana]
    metrics:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp_http/grafana]
