Spring › Observability

Building a homelab observability pipeline with OTel Collector

Build an OpenTelemetry Collector pipeline in a homelab with Tempo, Loki, Prometheus remote write, and bearer token auth behind Nginx Proxy Manager.

Building a homelab observability pipeline with OTel Collector

Routing traces, metrics, and logs through a single OpenTelemetry Collector endpoint (otel.namju.kim) decouples your applications from storage backends and lets you tune sampling without redeploying code.

Environment: OpenTelemetry Collector Contrib 0.144.0, Grafana Tempo 2.9.1, Grafana Loki 3.6.3, existing homelab Prometheus 2.54.1 and Grafana 11.2, and Nginx Proxy Manager with a *.namju.kim wildcard certificate.

Background

In our production setup at work, applications never talk directly to observability backends—every signal goes through an OpenTelemetry Collector first. At first glance, that looks like an extra hop to maintain. In practice, it pays for itself the first time you swap a storage backend or adjust a sampling policy without touching or redeploying a single service.

I wanted that same architecture in my homelab. I was already collecting homelab system metrics with Prometheus and Node Exporter and visualizing them in Grafana. The goal here was to add a trace store (Tempo) and a log store (Loki), then unify all telemetry ingestion behind a single authenticated Collector endpoint.

flowchart TD
    A["Spring Boot app\n(OTLP/HTTP)"] -->|"HTTPS + Bearer"| B["Nginx Proxy Manager\notel.namju.kim"]
    B --> C["OTel Collector\n:4318"]
    C -->|"traces"| D["Tempo"]
    C -->|"logs"| E["Loki"]
    C -->|"metrics remote write"| F["Prometheus → Grafana"]

Pipeline design and trade-offs

The Collector organizes telemetry into signal-specific pipelines following a receivers → processors → exporters flow. Internally, each receiver converts incoming payloads into the Collector’s pdata representation, passes them sequentially through the processor chain, and fans them out to the configured exporters. Because each exporter maintains its own sending_queue and retry loop, a temporary Tempo outage won’t block log or metric delivery to Loki and Prometheus.

Processor order matters. memory_limiter must always sit first so it can apply backpressure and reject incoming batches before the Collector hits an OOM kill. tail_sampling needs to see complete traces before deciding what to keep, so it runs ahead of batch, and batch sits last to pack outgoing payloads efficiently.

DecisionOptions consideredHomelab choice and reasoning
Public protocolgRPC 4317 vs. HTTP 4318Expose HTTP only; avoids extra HTTP/2 gRPC proxy tuning in NPM
AuthenticationNPM Access List vs. Collector bearertokenauthValidate inside the Collector; app SDKs only send a standard header and token rotation is simple
Metric ingestionprometheusremotewrite vs. Prometheus native OTLPRemote write; works on existing Prometheus 2.54.1 with a single CLI flag
Log ingestionLoki native OTLP (/otlp) vs. custom exporterNative OTLP via otlphttp; stores trace_id directly as structured metadata
Sampling strategyApp head sampling vs. Collector tail samplingSend 100% from apps; keep error and slow traces at the Collector

When not to use it. If you’re running one small service feeding a single backend, shipping directly from the SDK is simpler and saves memory. Tail sampling also comes with an architectural constraint: every span belonging to a trace must land on the same Collector instance. If you ever scale the Collector horizontally across multiple replicas, you’ll need a trace-ID-aware load-balancing layer in front of it. This single-instance config only makes sense for a homelab or low-volume environment.

Step 1: Collector configuration

The bearertokenauth extension ships with the Contrib distribution. Configuring it as a server authenticator enforces an Authorization: Bearer <token> header on the public HTTP receiver, with the secret injected strictly from an environment variable.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# ~/homelab-otel/collector/config.yaml
extensions:
  health_check:
    endpoint: 0.0.0.0:13133
  bearertokenauth/server:
    scheme: Bearer
    tokens:
      - ${env:OTEL_AUTH_TOKEN}

receivers:
  otlp/public:                 # Exposed behind NPM; bearer auth required
    protocols:
      http:
        endpoint: 0.0.0.0:4318
        auth:
          authenticator: bearertokenauth/server
  otlp/internal:               # Internal Docker network only
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317

processors:
  memory_limiter:
    check_interval: 1s
    limit_percentage: 80
    spike_limit_percentage: 20
  tail_sampling:
    decision_wait: 10s
    num_traces: 20000
    policies:
      - name: keep-errors
        type: status_code
        status_code: { status_codes: [ERROR] }
      - name: keep-slow
        type: latency
        latency: { threshold_ms: 1000 }
      - name: baseline
        type: probabilistic
        probabilistic: { sampling_percentage: 20 }
  batch:
    send_batch_size: 1024
    timeout: 5s

exporters:
  otlp/tempo:
    endpoint: tempo:4317
    tls:
      insecure: true
  otlphttp/loki:
    endpoint: http://loki:3100/otlp
  prometheusremotewrite:
    endpoint: http://monitoring-prometheus:9090/api/v1/write
    tls:
      insecure: true

service:
  extensions: [health_check, bearertokenauth/server]
  pipelines:
    traces:
      receivers: [otlp/public, otlp/internal]
      processors: [memory_limiter, tail_sampling, batch]
      exporters: [otlp/tempo]
    metrics:
      receivers: [otlp/public, otlp/internal]
      processors: [memory_limiter, batch]
      exporters: [prometheusremotewrite]
    logs:
      receivers: [otlp/public, otlp/internal]
      processors: [memory_limiter, batch]
      exporters: [otlphttp/loki]

Separating otlp/public and otlp/internal lets services running on the same Docker host stream over gRPC without TLS overhead while external workloads go through HTTPS and bearer-token validation.

Step 2: Tempo, Loki, and Compose setup

For Tempo, a minimal local-disk backend is enough for a homelab. Starting in Tempo 2.7, the OTLP receiver binds to localhost by default, so you must explicitly bind 0.0.0.0:4317 or the Collector container won’t be able to reach it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# ~/homelab-otel/tempo/tempo.yaml
server:
  http_listen_port: 3200

distributor:
  receivers:
    otlp:
      protocols:
        grpc:
          endpoint: 0.0.0.0:4317

storage:
  trace:
    backend: local
    wal:
      path: /var/tempo/wal
    local:
      path: /var/tempo/blocks

compactor:
  compaction:
    block_retention: 168h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# ~/homelab-otel/docker-compose.yml
services:
  otel-collector:
    image: otel/opentelemetry-collector-contrib:0.144.0
    container_name: otel-collector
    restart: unless-stopped
    command: ["--config=/etc/otelcol-contrib/config.yaml"]
    environment:
      OTEL_AUTH_TOKEN: ${OTEL_AUTH_TOKEN}
    volumes:
      - ./collector/config.yaml:/etc/otelcol-contrib/config.yaml:ro
    networks: [npm-network, monitoring-net]
    depends_on: [tempo, loki]

  tempo:
    image: grafana/tempo:2.9.1
    container_name: monitoring-tempo
    restart: unless-stopped
    command: ["-config.file=/etc/tempo.yaml"]
    volumes:
      - ./tempo/tempo.yaml:/etc/tempo.yaml:ro
      - tempo_data:/var/tempo
    networks:
      monitoring-net:
        aliases: [tempo]

  loki:
    image: grafana/loki:3.6.3
    container_name: monitoring-loki
    restart: unless-stopped
    command: ["-config.file=/etc/loki/local-config.yaml"]
    volumes:
      - loki_data:/loki
    networks:
      monitoring-net:
        aliases: [loki]

volumes:
  tempo_data:
  loki_data:

networks:
  npm-network:
    external: true
  monitoring-net:
    name: homelab_monitoring_net
    external: true

Next, enable the remote write receiver on the existing Prometheus container and provision Tempo and Loki in Grafana with bidirectional trace-to-log linking. That way, inspecting a slow span in Tempo lets you jump straight to the matching logs in Loki—and vice versa.

1
2
# Add to prometheus.command in the existing monitoring stack
      - "--web.enable-remote-write-receiver"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# grafana/provisioning/datasources/tracing.yml
apiVersion: 1
datasources:
  - name: Tempo
    uid: tempo
    type: tempo
    url: http://tempo:3200
    jsonData:
      tracesToLogsV2:
        datasourceUid: loki
        filterByTraceID: true
  - name: Loki
    uid: loki
    type: loki
    url: http://loki:3100
    jsonData:
      derivedFields:
        - name: TraceID
          matcherType: label
          matcherRegex: trace_id
          datasourceUid: tempo
          url: "$${__value.raw}"

Step 3: Reverse proxy and verification

Because the Collector joins the npm-network I created in my Cloudflare DDNS and Nginx Proxy Manager wildcard SSL setup, the proxy host forwards directly to the container name:

  • Domain Names: otel.namju.kim
  • Forward: http / otel-collector / 4318
  • SSL: *.namju.kim wildcard certificate, Force SSL, HTTP/2 enabled
  • Access List: None (authentication is handled by the Collector)

Bring the stack up and test both unauthenticated and authenticated requests to verify the bearer token check:

1
2
3
4
5
6
7
8
cd ~/homelab-otel && docker compose up -d
# Without a token, the Collector should return 401
curl -s -o /dev/null -w "%{http_code}\n" -X POST https://otel.namju.kim/v1/traces \
  -H "Content-Type: application/json" -d '{"resourceSpans":[]}'
# With a valid bearer token, it should return 200
curl -s -o /dev/null -w "%{http_code}\n" -X POST https://otel.namju.kim/v1/traces \
  -H "Authorization: Bearer ${OTEL_AUTH_TOKEN}" \
  -H "Content-Type: application/json" -d '{"resourceSpans":[]}'
1
2
401
200

Production caveats and checklist

Turning on resource_to_telemetry_conversion in prometheusremotewrite converts every OpenTelemetry resource attribute—such as process.command_args and host.name attached by the Java Agent—into Prometheus metric labels, causing active time series to explode. Leave it off (the default): the service name still maps to the job label, and you can join other resource attributes from target_info when needed.

Tail sampling only works if applications send 100% of traces (probability: 1.0). If an app already head-samples at 10%, the Collector can’t rescue error traces that were dropped before leaving the service. Because the Collector buffers traces in memory for decision_wait (num_traces × average spans per trace), always pair memory_limiter with an explicit Docker container memory limit.

With the Collector acting as a single front door, application configs shrink to an endpoint URL and a bearer token, while storage backends and sampling rules stay under homelab control. Before sending real traffic, run through this checklist:

  • Only OTLP/HTTP (4318) is exposed publicly; gRPC (4317) stays on the internal Docker network
  • The bearertokenauth token comes from an environment variable and is never committed to Git
  • Processors run in order: memory_limiter → tail_sampling → batch
  • Prometheus has --web.enable-remote-write-receiver enabled and resource_to_telemetry_conversion disabled
  • Grafana’s Tempo and Loki data sources link back and forth cleanly by trace_id
This post is licensed under CC BY 4.0 by the author.