Skip to content

Lesson 2 of 9 · 24m

Collection Agents and Structured Events

Filebeat, Vector, Fluent Bit, and OpenTelemetry collectors — what belongs at the edge, and why structure beats regex archaeology.

The collector is the first place you control cost and quality. Once unstructured text reaches the cluster, every downstream system pays to interpret it. The day-one advice is simple: emit structured logs from applications when you can, and use collectors to normalize — not to invent — meaning.

Pick the agent for the constraint

Filebeat is boring and reliable for files and Elasticsearch-oriented pipelines. Fluent Bit is small and strong in Kubernetes. Vector is fast, scriptable, and pleasant when routing gets complicated. The OpenTelemetry Collector is the right long-term center of gravity if you want logs, metrics, and traces sharing resource metadata.

A minimal Filebeat input:

filebeat.inputs:
  - type: filestream
    id: app-json
    paths:
      - /var/log/myapp/*.log
    parsers:
      - ndjson:
          target: ""
          add_error_key: true
output.elasticsearch:
  hosts: ["https://es1.internal:9200"]
  index: "logs-myapp-%{+yyyy.MM.dd}"

Structure at the source

Prefer this:

{"ts":"2026-11-29T22:10:04.312Z","level":"warn","service":"checkout","trace_id":"4f1c9a","msg":"payment retry","attempt":3,"latency_ms":842}

Over this:

2026-11-29 22:10:04 WARN checkout payment retry attempt=3 latency=842ms

The second can be parsed. The first does not need to be. That difference matters at 30,000 events per second, when a bad grok pattern can consume more CPU than the application itself.

Enrichment is cheap; extraction is expensive

Good edge enrichment: host, container, pod, namespace, environment, service version. Risky extraction: user IDs pulled from URLs, request bodies, tokens, and anything high-cardinality. In Vector terms, a tiny remap transform that stamps environment = "prod" and log_schema = "app.v1" is enough in many shops.

Field notes

  • Never parse twice. If the application emits JSON, do not regex it again downstream.
  • Multiline stack traces need explicit join rules; otherwise one exception becomes eighty events.
  • Protect the pipeline from huge lines. A 4 MB log line is usually a bug report, not an event.
  • Use the agent's disk queue or persistent queue where available. Memory-only buffering turns a restart into data loss.

Was this lesson helpful?

Sign in to rate