# OpenTelemetry Collector config for the local-dev stack.
#
# v1 scope (per ADR-0012):
#   - Accept OTLP from the BFF and the SPA on gRPC (4317) and HTTP
#     (4318). The default OTEL_EXPORTER_OTLP_ENDPOINT in dev points
#     here.
#   - Batch + log everything to stdout via the `debug` exporter — the
#     dev sees what their app emits without standing up a backend.
#   - When the `observability` Compose profile is active, additionally
#     forward to Jaeger (`jaeger:4317` on the internal Compose
#     network). When the profile is inactive, the OTLP→Jaeger export
#     fails at warn level but does not impact the debug pipeline.
#
# Production replaces the debug exporter with the proper backend
# (chosen in the future on-prem infrastructure ADR — likely Tempo +
# Loki + Mimir, or an OpenTelemetry-friendly all-in-one).

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318
        # CORS for the SPA-side OTLP/HTTP exporter (per ADR-0012,
        # phase 2). The browser's pre-flight needs both the origin
        # and the W3C trace headers in the allow-list — without it,
        # the OTLP POST is blocked client-side and SPA spans never
        # reach the Collector.
        cors:
          allowed_origins:
            - http://localhost:4200
          allowed_headers:
            - content-type
            - traceparent
            - tracestate

processors:
  batch:
    # Small batches in dev so the developer sees output quickly.
    timeout: 5s
    send_batch_size: 100

exporters:
  debug:
    verbosity: detailed
  otlp/jaeger:
    endpoint: jaeger:4317
    tls:
      insecure: true
    sending_queue:
      enabled: true
      # When jaeger isn't running (profile off), retries fall back
      # to a small queue rather than blocking the pipeline.
      queue_size: 100
    retry_on_failure:
      enabled: true
      initial_interval: 5s
      max_interval: 30s

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [debug, otlp/jaeger]
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [debug]
    metrics:
      receivers: [otlp]
      processors: [batch]
      exporters: [debug]
  telemetry:
    logs:
      level: info
