# OpenTelemetry Collector Configuration for ggen P2P Marketplace Testing
# This config receives OTLP traces/metrics and exports them to Jaeger, Prometheus, and logging

receivers:
  # OTLP receiver for traces and metrics
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318
        cors:
          allowed_origins:
            - "*"

  # Prometheus receiver for collector self-monitoring
  prometheus:
    config:
      scrape_configs:
        - job_name: 'otel-collector'
          scrape_interval: 10s
          static_configs:
            - targets: ['localhost:8888']

processors:
  # Batch processor to optimize export
  batch:
    timeout: 1s
    send_batch_size: 100

  # Memory limiter to prevent OOM
  memory_limiter:
    check_interval: 1s
    limit_mib: 512
    spike_limit_mib: 128

  # Add resource attributes
  resource:
    attributes:
      - key: service.name
        value: ggen-marketplace-p2p
        action: upsert
      - key: deployment.environment
        value: test
        action: upsert

exporters:
  # Logging exporter for debugging
  logging:
    verbosity: detailed
    sampling_initial: 10
    sampling_thereafter: 100

  # OTLP exporter to Jaeger
  otlp/jaeger:
    endpoint: jaeger:4317
    tls:
      insecure: true

  # Prometheus exporter for metrics
  prometheus:
    endpoint: "0.0.0.0:8889"
    namespace: ggen_marketplace

  # Debug exporter (zpages)
  debug:
    verbosity: detailed

extensions:
  # Health check extension
  health_check:
    endpoint: 0.0.0.0:13133

  # Performance profiler
  pprof:
    endpoint: 0.0.0.0:1777

  # zpages for debugging
  zpages:
    endpoint: 0.0.0.0:55679

service:
  extensions: [health_check, pprof, zpages]

  pipelines:
    # Traces pipeline
    traces:
      receivers: [otlp]
      processors: [memory_limiter, batch, resource]
      exporters: [logging, otlp/jaeger, debug]

    # Metrics pipeline
    metrics:
      receivers: [otlp, prometheus]
      processors: [memory_limiter, batch, resource]
      exporters: [logging, prometheus, debug]

  # Telemetry configuration for the collector itself
  telemetry:
    logs:
      level: info
    metrics:
      level: detailed
      address: 0.0.0.0:8888
