# Local OTel Collector — the SAME ingestion topology the hosted platform runs
# (OpenTelemetryStack: collector → Loki via OTLP, → Tempo via OTLP gRPC,
# metrics scraped by Prometheus). Locally the k8sattributes processor's job —
# stamping k8s.namespace.name / k8s.deployment.name / k8s.container.name on
# every record — is done at the edges instead:
#   - filelog: derives them from the log path
#     /var/log/mesh-apps/{namespace}/{service}.log (written by
#     `mesh dev --local`, namespace = {tenant}-{env}-{app})
#   - otlp: apps send OTEL_RESOURCE_ATTRIBUTES injected by `mesh dev --local`
# so hub-api's LogQL/TraceQL queries run UNCHANGED against local data.
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318
  filelog:
    include:
      - /var/log/mesh-apps/*/*.log
    start_at: beginning
    include_file_path: true
    operators:
      - type: regex_parser
        parse_from: attributes["log.file.path"]
        regex: '^/var/log/mesh-apps/(?P<mesh_namespace>[^/]+)/(?P<mesh_service>[^/]+)\.log$'
      - type: move
        from: attributes.mesh_namespace
        to: resource["k8s.namespace.name"]
      - type: move
        from: attributes.mesh_service
        to: resource["k8s.deployment.name"]
      - type: copy
        from: resource["k8s.deployment.name"]
        to: resource["k8s.container.name"]

processors:
  batch: {}

exporters:
  # Same exporter shape as the hosted collector: Loki's native OTLP endpoint.
  # Loki promotes k8s.namespace.name / k8s.deployment.name /
  # k8s.container.name to index labels (k8s_namespace_name, …) by default.
  otlphttp/loki:
    endpoint: http://loki:3100/otlp
  otlp/tempo:
    endpoint: tempo:4317
    tls:
      insecure: true
  prometheus:
    endpoint: 0.0.0.0:8889
    resource_to_telemetry_conversion:
      enabled: true

extensions:
  health_check:
    endpoint: 0.0.0.0:13133

service:
  extensions: [health_check]
  pipelines:
    logs:
      receivers: [otlp, filelog]
      processors: [batch]
      exporters: [otlphttp/loki]
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp/tempo]
    metrics:
      receivers: [otlp]
      processors: [batch]
      exporters: [prometheus]
