# Common components in the OpenTelemetry data pipelines
extensions:
  health_check:
    endpoint: localhost:13133
    path: /health/check
  file_storage: # keep the checkpoints and queue in Mule dir to survive on AM upgrade (`am` folder is deleted)
    directory: "${OTEL_COLLECTOR_DATA}"

receivers:
  prometheus/telemetry:
    config:
      scrape_configs:
        - job_name: 'otel-collector-telemetry'
          metrics_path: /metrics
          scrape_interval: ${env:OTEL_RECEIVER_PROMETHEUS_INTERVAL:-5m}
          scrape_timeout: 3s
          body_size_limit: 512KB
          static_configs:
            - targets: ['localhost:8888']

processors:
  memory_limiter:
    check_interval: 1s
    limit_mib: 40 # used to set GOMEMLIMIT in install.ps1 and setup.ps1
  batch/lmetric:
    send_batch_size: 10
    send_batch_max_size: 10
    timeout: 10s
  batch/log:
    send_batch_size: 100
    send_batch_max_size: 200
  batch/telemetry:
    send_batch_size: 50
    send_batch_max_size: 100
    timeout: 10s
  resource/telemetry:
    attributes:
      - key: mulesoft.root_org.id
        value: "${master.organization.id}"
        action: insert
      - key: mulesoft.sub_org.id
        value: "${organization.id}"
        action: insert
      - key: mulesoft.env.id
        value: "${environment.id}"
        action: insert
      - key: mulesoft.ingest.namespace
        value: otel_collector
        action: insert
      - key: mulesoft.ingest.group
        value: metric
        action: insert
      - key: mulesoft.mule.runtime
        value: hybrid
        action: insert
      - key: mulesoft.mule.server_id
        value: "${cluster.id}"
        action: insert
      - key: mulesoft.monitoring.metrics.service_identity.service
        value: "otel-collector-agent"
        action: insert
      - key: mulesoft.monitoring.metrics.service_identity.subservice
        value: "hybrid"
        action: insert
      - key: mulesoft.monitoring.metrics.service_identity.scope1 # product or SFDC_SCOPE1
        value: "mule"
        action: insert
      - key: mulesoft.monitoring.metrics.service_identity.scope2 # region or SFDC_SCOPE2
        value: "on-prem"
        action: insert
      - key: mulesoft.monitoring.metrics.service_identity.scope3 # env name set by the AM agent dynamically, or SFDC_SCOPE3
        value: "${ENV_NAME}" # ENV_NAME: [qax|stgx|prod|prod-eu]
        action: insert
  attributes/telemetry:
    actions:
      - key: component
        from_attribute: receiver
        action: upsert
      - key: component
        from_attribute: processor
        action: upsert
      - key: component
        from_attribute: exporter
        action: upsert
      - key: receiver
        action: delete
      - key: processor
        action: delete
      - key: exporter
        action: delete
      - key: service_name
        action: delete
      - key: service_version
        action: delete
      - key: service_instance_id
        action: delete
  filter/telemetry:
    error_mode: ignore
    metrics:
      metric:
        - 'name == "up"'
        - 'IsMatch(name, "^scrape_.*")'

exporters:
  otlphttp/lmetric:
    logs_endpoint: "${OTEL_EXPORTER_OTLP_LMETRICS_PUBCA_ENDPOINT}"
    proxy_url: "${proxy.url}"
    tls:
      cert_file: ${am.config.home}/certs/hsa_client.crt
      key_file: ${am.config.home}/certs/hsa_client.key
      include_system_ca_certs_pool: true
    headers:
      Content-Type: application/x-protobuf
    retry_on_failure:
      initial_interval: 2s
      max_interval: 30s
      max_elapsed_time: 300s
    sending_queue:
      queue_size: 200
    timeout: 5s
  otlphttp/log:
    logs_endpoint: "${OTEL_EXPORTER_OTLP_LOGS_PUBCA_ENDPOINT}"
    proxy_url: "${proxy.url}"
    headers:
      Content-Type: application/x-protobuf
    timeout: 3s
    tls:
      cert_file: ${am.config.home}/certs/hsa_client.crt
      key_file: ${am.config.home}/certs/hsa_client.key
      include_system_ca_certs_pool: true
    sending_queue:
      queue_size: 1000
    retry_on_failure:
      initial_interval: 1s
      max_interval: 30s
      max_elapsed_time: 300s
  otlphttp/telemetry:
    metrics_endpoint: "${OTEL_EXPORTER_OTLP_METRICS_PUBCA_ENDPOINT}"
    proxy_url: "${proxy.url}"
    tls:
      cert_file: ${am.config.home}/certs/hsa_client.crt
      key_file: ${am.config.home}/certs/hsa_client.key
      include_system_ca_certs_pool: true
    headers:
      Content-Type: application/x-protobuf
    sending_queue:
      queue_size: 100
    timeout: 5s

  debug:
    verbosity: normal # basic, normal, detailed

service:
  extensions: [health_check, file_storage]
  telemetry:
    metrics:
      level: normal # basic, normal, detailed
      address: :8888
    logs:
      level: INFO # INFO, DEBUG, WARN, ERROR
      output_paths: ["${am.home}/logs/otel-collector.log"]
      error_output_paths: ["${am.home}/logs/otel-collector.err"]
  pipelines:
    metrics/telemetry:
      receivers: [prometheus/telemetry]
      processors: [memory_limiter, filter/telemetry, attributes/telemetry, resource/telemetry, batch/telemetry]
      exporters: [otlphttp/telemetry, debug]
