# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: OpenTelemetry Collector for VictoriaMetrics
spec:
    description: Vendor-agnostic way to receive, process and export telemetry data.
    icon: https://cdn.zeabur.com/templates/icon/opentelemetry.svg
    tags:
        - monitoring
        - observability
        - collector
    readme: |
        The OpenTelemetry Collector receives [traces](https://opentelemetry.io/docs/concepts/signals/traces/), [metrics](https://opentelemetry.io/docs/concepts/signals/metrics/), and [logs](https://opentelemetry.io/docs/concepts/signals/logs/), processes the telemetry, and exports it to a wide variety of observability backends using its components. For a conceptual overview of the Collector, see [Collector](https://opentelemetry.io/docs/collector/).

        ## Usage

        We have initialize a basic `/etc/otelcol/config.yaml` that has the following defaults:

        - Have an OTLP gRPC receiver on port 4317 and an HTTP receiver on port 4318 for traces and logs.
          - There is no metrics receiver since Prometheus does not enable OTLP remote-write by default. If you prefer the OTLP metrics pattern, [check this guide to enable OpenTelemetry for Prometheus](https://prometheus.io/docs/guides/opentelemetry/), and you can configure the Prometheus receiver in the "/etc/otelcol/config.yaml" file.
        - Export otel-collector metrics in Prometheus format on port 8888. You can scrape the metrics from this port.
        - Export traces to [VictoriaTraces](https://zeabur.com/templates/XUSH4W) and logs to [VictoriaLogs](https://zeabur.com/templates/OXA4QA).
        - The health check endpoint is available at `http://your-domain/health`, where `your-domain` binds to port 13133.
        - Limit the memory usage of the collector to 2GB.
        - Enable the debug exporter to print the traces and logs to the console.

        You should deploy [VictoriaTraces](https://zeabur.com/templates/XUSH4W) and [VictoriaLogs](https://zeabur.com/templates/OXA4QA) in the same project as this service. Configure your service to send traces and logs to this collector.

        To customize the configuration, edit the `/etc/otelcol/config.yaml` file in the [Config Editor](https://zeabur.com/docs/data-management/config-edit). If you need further customization, refer to the [Collector Configuration](https://opentelemetry.io/docs/collector/configuration/) documentation. You can add more receivers like Jaeger, exporters like Prometheus, or processors like `filter`.

        ### Add metrics to your VictoriaMetrics

        Add the following target to your `/etc/victoriametrics/scrape.yaml` file of your [VictoriaMetrics](https://zeabur.com/templates/UBHA7Z) instance:

        ```yaml
        scrape_configs:
          - job_name: 'otel-collector'
            static_configs:
              - targets: ['http://otel-collector:8888/metrics']
        ```
    services:
        - name: otel-collector
          icon: https://cdn.zeabur.com/templates/icon/opentelemetry.svg
          template: PREBUILT
          spec:
            source:
                image: otel/opentelemetry-collector:0.147.0
                runAsUserID: 11211
            ports:
                - id: prometheus
                  port: 8888
                  type: HTTP
                - id: otlpgrpc
                  port: 4317
                  type: HTTP
                - id: otlphttp
                  port: 4318
                  type: HTTP
                - id: healthcheck
                  port: 13133
                  type: HTTP
            configs:
                - path: /etc/otelcol/config.yaml
                  template: "receivers:\n  otlp:\n    protocols:\n      grpc:\n        endpoint: 0.0.0.0:4317\n      http:\n        endpoint: 0.0.0.0:4318\n        \nprocessors:\n  memory_limiter:\n    check_interval: 1s\n    limit_mib: 2048\n\nexporters:\n  otlphttp:\n    traces_endpoint: http://victoriatraces:10428/insert/opentelemetry/v1/traces\n    logs_endpoint: http://victorialogs:9428/insert/opentelemetry/v1/logs\n  debug:\n\nextensions:\n  health_check:\n    endpoint: 0.0.0.0:13133\n\nservice:\n  extensions: [health_check]\n  pipelines:\n    traces:\n      receivers: [otlp]\n      processors: [memory_limiter]\n      exporters: [debug, otlphttp]\n    logs:\n      receivers: [otlp]\n      processors: [memory_limiter]\n      exporters: [debug, otlphttp]\n  telemetry:\n    metrics:\n      readers:\n        - pull:\n            exporter:\n              prometheus:\n                host: '0.0.0.0'\n                port: 8888\n"
                  permission: null
                  envsubst: null
            healthCheck:
                type: HTTP
                port: healthcheck
                http:
                    path: /
