apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: opentelemetry-collector
  namespace: opentelemetry-collector
spec:
  install:
    disableWait: true
  upgrade:
    disableWait: true
  dependsOn:
    - name: prometheus-stack
      namespace: prometheus-stack
    - name: openobserve
      namespace: openobserve
  interval: 5m
  timeout: 30m
  values:
    imagePullSecrets:
      - name: regcred
    podAnnotations:
      vault.hashicorp.com/agent-init-first: "true"
      vault.hashicorp.com/agent-inject: "true"
      vault.hashicorp.com/agent-pre-populate-only: "true"
      vault.hashicorp.com/auth-path: auth/kubernetes
      vault.hashicorp.com/role: openobserve
      vault.hashicorp.com/agent-inject-secret-openobserve-basic-auth: secrets/data/vault/apps/openobserve
      vault.hashicorp.com/agent-inject-template-openobserve-basic-auth: |-
        {{ "{{- with secret \"secrets/data/vault/apps/openobserve\" -}}" }}
        Basic {{ "{{ index .Data.data \"OPENOBSERVE_BASIC_AUTH\" }}" }}
        {{ "{{- end -}}" }}
    mode: daemonset
    fullnameOverride: otel-collector
    tolerations:
      - operator: Exists
    rollout:
      rollingUpdate:
        maxUnavailable: 4
    presets:
      logsCollection:
        enabled: true
        includeCollectorLogs: false
      kubernetesAttributes:
        enabled: true
    config:
      receivers:
        filelog:
          include:
            - /var/log/pods/*/*/*.log
          exclude:
            - /var/log/pods/opentelemetry-collector_*/*/*.log
          start_at: end
          operators:
            - type: container
        otlp:
          protocols:
            grpc:
              endpoint: ${env:MY_POD_IP}:4317
            http:
              endpoint: ${env:MY_POD_IP}:4318
      processors:
        batch: {}
        k8sattributes: {}
      exporters:
        otlp:
          endpoint: http://openobserve-web.openobserve.svc.cluster.local:5080
          tls:
            insecure: true
        otlphttp/openobserve:
          endpoint: http://openobserve-web.openobserve.svc.cluster.local:5080/api/default
          headers:
            Authorization: ${file:/vault/secrets/openobserve-basic-auth}
          tls:
            insecure: true
      service:
        pipelines:
          logs:
            receivers:
              - filelog
            processors:
              - k8sattributes
              - batch
            exporters:
              - otlphttp/openobserve
          traces:
            receivers:
              - otlp
            processors:
              - k8sattributes
              - batch
            exporters:
              - otlphttp/openobserve
