WORKINGPROJECTCHAPTER 15

Project: a production-grade telemetry pipeline

Turn the lab's pass-through Collector into one that protects itself, drops noise, scrubs personal data, keeps every error, and proves all of it with queries that return nothing

180 MINOBSERVABILITYUPDATED 2026-11-02

The brief

The lab’s labs/observability/otel/collector.yaml is a pass-through: OTLP in, a batch processor, three exporters. It has no protection against its own memory running out, keeps every trace, forwards every attribute it receives, and has no way to show you what it refused. By the end of this project it does all of the following, and you can prove each one with a query:

  1. Protects itself. memory_limiter first in every pipeline, batch last.
  2. Knows where it runs. resourcedetection adds the Collector host’s attributes without overwriting what the services set.
  3. Drops noise. A filter processor removes health-check spans and log records before anything else spends work on them.
  4. Scrubs personal data. The card-holder name and anything that looks like an email attribute are deleted; user ids are hashed; email addresses in log bodies are replaced.
  5. Samples on the tail. Keeps every trace with an error, every trace longer than 1 s, and 10% of the rest.
  6. Routes. Traces to Tempo, metrics to Prometheus, logs to Loki, each through its own pipeline.
  7. Has a dead-letter view. Log records that still carry a forbidden attribute after scrubbing are diverted to a debug exporter instead of reaching Loki, so a broken scrub rule shows up in the Collector’s output, not in your log store.

Then you switch on FAULT_LEAK_PII=1, run load, and show with LogQL and TraceQL that no card-holder name or raw user id reaches Loki or Tempo, while every failed checkout still has a trace.

The order of processors is the design

Processors run in the order listed in each pipeline, and each choice of position has a reason you should be able to state.

memory_limiter goes first because it works by refusing data. When memory crosses the soft limit (limit_mib minus spike_limit_mib) it starts returning errors to the receiver, which returns them to the sender, whose exporter retries with backoff. Placed later, it would refuse data the Collector has already decoded and held. The tail sampler is the component that most needs this: it buffers whole traces for decision_wait, and at 50 RPS with 10 s of buffer that is 500 traces of a dozen spans each in memory at all times.

filter comes before scrubbing and sampling so that dropped data costs nothing downstream. It must come before tail_sampling for a sharper reason: a failing health check is an error, and the sampler keeps every error.

Scrubbing comes before sampling and before routing so that no exporter, including debug, ever sees the raw value. The one exception is the dead-letter tripwire, which deliberately checks the result of scrubbing.

tail_sampling needs every span of a trace in the same Collector. With one Collector that is automatic. With several, the upstream documentation’s answer is two tiers: a first tier with the loadbalancing exporter keyed by trace id, and a second tier that samples. That is module O4’s problem; note it in your write-up.

batch goes last so it batches what survived.

Scrubbing: what each tool can do

The attributes processor works on span, log and metric attributes. delete takes a key or a regex pattern over attribute names; hash replaces a value with a hash of it (SHA-1 in the Collector release the lab pins, SHA-256 in newer releases). It does not see log bodies. For bodies you need the transform processor and OTTL: replace_pattern(log.body, "<regex>", "<replacement>").

Hashing is pseudonymisation, not anonymisation. The demo app has 1,000 users; anyone with the hash function can hash all 1,000 ids and read the table backwards. In production you would compute a keyed hash (an HMAC with a secret the observability team holds) so the mapping is stable for joins but not reversible without the key. Write down in your submission what your pipeline does and what it does not protect against.

Three things the Collector cannot fix. It cannot scrub what bypasses it: the services also write JSON to stdout, and docker compose logs payments still shows the card-holder name. It cannot unsend what already went elsewhere. And it cannot remove what it was never told to look for, which is why the proof below includes a synthetic record with fields the app never emits.

The dead-letter view

A dead-letter queue holds what a pipeline could not deliver. Here it holds what the pipeline should not deliver: a routing connector after the scrub checks each log record for the attributes the scrub was meant to remove. Records that still have one go to a pipeline whose only exporter is debug with verbosity: detailed; everything else goes on to Loki. When someone edits the scrub rules and breaks them, the evidence lands in docker compose logs otel-collector and Loki stays clean. The break at the end of the lab does exactly that.

Rubric

Your submission is the final otel/collector.yaml and a short write-up with the output of each proof step. A complete one has:

  • memory_limiter first and batch last in every pipeline, with limit_mib and spike_limit_mib stated and justified for the container.
  • resourcedetection with override: false, and a TraceQL or LogQL line showing the attribute it added.
  • Health-check spans and log records filtered, proven with a synthetic /health span marked as an error that does not reach Tempo while a control span does.
  • card_holder and email-like attributes deleted, user ids hashed in both spans and logs, emails replaced in log bodies.
  • A LogQL query that returned card-holder names before the change and returns nothing over a window after it.
  • A TraceQL query that returned raw integer user ids before the change and returns nothing after it.
  • A synthetic OTLP log record with an email attribute and an email in its body, shown in Loki with both removed.
  • Tail sampling with the three policies; every failed checkout in the window has a trace (count from Prometheus equals count from Tempo, give or take the window edges).
  • The dead-letter path demonstrated by breaking the scrub on purpose.
  • A paragraph on what the pipeline does not protect: stdout logs, unsalted hashes, fields nobody listed, and the log-to-trace links that tail sampling breaks.
LAB Build the pipeline, then prove it LONG · ~180 MIN
YOU NEEDDocker Desktop or Docker Engine with Compose v2the ATLAS repo cloned, working in labs/observabilitycurl, jq and opensslabout 4 GB of RAM freea text editor

1. Turn on the leak and measure it. Start from the lab’s original otel/collector.yaml (git checkout otel/collector.yaml if earlier chapters changed it) and generate personal data on purpose:

cd labs/observability
cat > .env <<'EOF'
OTEL_SDK_DISABLED=false
LOG_FORMAT=json
OTEL_SEMCONV_STABILITY_OPT_IN=http/dup
LOADGEN_RPS=20
FAULT_LEAK_PII=1
FAULT_ERROR_RATE=0.02
FAULT_SLOW_PAYMENTS_PCT=3
EOF
docker compose --profile telemetry up -d --build
sleep 150
curl -sG localhost:3100/loki/api/v1/query \
  --data-urlencode 'query=sum(count_over_time({service_name="payments"} | card_holder!="" [2m]))' | jq -r '.data.result[0].value[1]'
curl -sG localhost:3200/api/search --data-urlencode 'q={ span.user.id > 0 }' --data-urlencode limit=5 \
  | jq -r '.traces[].traceID'
A number in the low thousands: every captured charge in the last two minutes put a name like Ada Lovelace into Loki as structured metadata. Five trace ids whose gateway span carries the raw integer user.id. Open one in Grafana to see it. This is your before.

2. Write probes for what the app never sends. Save as probe.sh:

#!/bin/sh
# usage: ./probe.sh log | ./probe.sh span <path>
now=$(date +%s)000000000
if [ "$1" = log ]; then
  curl -s -o /dev/null -w 'log probe: %{http_code}\n' -X POST localhost:4318/v1/logs -H 'Content-Type: application/json' -d '{
  "resourceLogs":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"pii-probe"}}]},
  "scopeLogs":[{"logRecords":[{"timeUnixNano":"'$now'","severityText":"INFO",
    "body":{"stringValue":"refund sent to ada.lovelace@example.com"},
    "attributes":[{"key":"customer.email","value":{"stringValue":"ada.lovelace@example.com"}},
                  {"key":"card_holder","value":{"stringValue":"Ada Lovelace"}}]}]}]}]}'
else
  tid=$(openssl rand -hex 16); sid=$(openssl rand -hex 8)
  curl -s -o /dev/null -w "span probe $2 trace $tid: %{http_code}\n" -X POST localhost:4318/v1/traces -H 'Content-Type: application/json' -d '{
  "resourceSpans":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"probe"}}]},
  "scopeSpans":[{"spans":[{"traceId":"'$tid'","spanId":"'$sid'","name":"GET '$2'","kind":2,
    "startTimeUnixNano":"'$now'","endTimeUnixNano":"'${now%000000000}001000000'",
    "attributes":[{"key":"url.path","value":{"stringValue":"'$2'"}}],"status":{"code":2}}]}]}]}'
fi
chmod +x probe.sh && ./probe.sh log && ./probe.sh span /health
sleep 20
curl -sG localhost:3100/loki/api/v1/query_range --data-urlencode 'query={service_name="pii-probe"}' \
  --data-urlencode since=5m | jq '.data.result[] | {stream, line: .values[0][1]}'
Both probes return 200. Loki shows the probe record with customer_email and card_holder in its stream labels (structured metadata, dots turned to underscores) and the email in the line. In Tempo, { resource.service.name = "probe" } finds the /health span, marked as an error. Every one of these is a failure of the current pipeline.

3. Build the pipeline. Edit otel/collector.yaml. The keys you need, all checked against the upstream READMEs for the lab’s Collector release (otel/opentelemetry-collector-contrib:0.123.0):

  • memory_limiter: check_interval, limit_mib, spike_limit_mib.
  • resourcedetection: detectors: [env, system], override: false, and system.hostname_sources: [os] so it does not try DNS inside a container.
  • filter: error_mode: ignore, then traces.span and logs.log_record as lists of OTTL conditions; a record matching any condition is dropped. The Python services’ HTTP spans use the older http.target attribute; newer instrumentation uses url.path. Match both.
  • attributes: a list of actions, each with key or pattern, and action: delete or action: hash. Attribute names in the app: card_holder on payments logs, user.id on gateway spans, user on gateway logs.
  • transform: log_statements with replace_pattern(log.body, ...).
  • tail_sampling: decision_wait, num_traces, expected_new_traces_per_sec, and policies of type: status_code (status_codes: [ERROR]), type: latency (threshold_ms) and type: probabilistic (sampling_percentage). A trace is kept if any policy says sample.
  • A routing connector under connectors: with default_pipelines, and a table entry with context: log, a condition and pipelines. A connector is an exporter of one pipeline and a receiver of another.
  • debug exporter with verbosity: detailed.

The git checkout in step 1 removed the CORS block from the frontend chapter; add it back if you want the browser page to keep exporting (the solution includes it). Validate before you restart:

docker run --rm -v "$PWD/otel/collector.yaml:/c.yaml:ro" otel/opentelemetry-collector-contrib:0.123.0 validate --config=/c.yaml \
  && docker compose --profile telemetry restart otel-collector
sleep 5; docker compose logs --since 1m otel-collector | grep -iE 'error|everything is ready'
T0=$(date +%s)
validate prints nothing and exits 0, then the Collector logs Everything is ready. Begin running and processing data. with no errors. If validate fails, it names the component and key. T0 marks the moment after which every query below must come back clean. The solution at the end of this page is one correct config; try without it first.

4. Prove the scrub. Wait two and a half minutes so every window starts after T0, then send the probes again:

sleep 150
./probe.sh log && ./probe.sh span /health && ./probe.sh span /checkout
sleep 20
curl -sG localhost:3100/loki/api/v1/query \
  --data-urlencode 'query=sum(count_over_time({service_name="payments"} | card_holder!="" [2m]))' | jq -c '.data.result'
curl -sG localhost:3100/loki/api/v1/query_range --data-urlencode 'query={service_name="pii-probe"}' \
  --data-urlencode "start=${T0}000000000" | jq '.data.result[] | {stream, line: .values[0][1]}'
curl -sG localhost:3200/api/search --data-urlencode 'q={ span.user.id > 0 }' \
  --data-urlencode "start=$T0" --data-urlencode "end=$(date +%s)" | jq '.traces | length'
curl -sG localhost:3200/api/search --data-urlencode 'q={ resource.service.name = "gateway" && span.user.id != nil }' \
  --data-urlencode "start=$T0" --data-urlencode "end=$(date +%s)" --data-urlencode limit=1 | jq -r '.traces[0].traceID'
The first query returns []: no payments line since the change has a card holder. The probe record is in Loki with the line refund sent to <email> and neither customer_email nor card_holder among its labels. The integer user.id search returns 0. The last search returns a trace id; open it and the gateway span’s user.id is now a 40-character hex string. In Tempo, { resource.service.name = "probe" } from T0 finds the /checkout probe and not the /health one, though both were errors: the filter ran before the sampler could keep it.

5. Prove errors are always kept. Let load run for five more minutes after step 4, then compare the gateway’s own count of failed checkouts with the traces Tempo holds:

sleep 300
curl -sG localhost:9090/api/v1/query \
  --data-urlencode 'query=sum(increase(http_requests_total{job="gateway",route="/checkout",status="502"}[5m]))' | jq -r '.data.result[0].value[1]'
curl -sG localhost:3200/api/search \
  --data-urlencode 'q={ resource.service.name = "gateway" && kind = server && status = error }' \
  --data-urlencode "start=$(( $(date +%s) - 300 ))" --data-urlencode "end=$(date +%s)" --data-urlencode limit=1000 | jq '.traces | length'
curl -sG localhost:9090/api/v1/query \
  --data-urlencode 'query=sum by (policy, sampled) (increase({__name__=~"otelcol_processor_tail_sampling_count_traces_sampled(_total)?"}[5m]))' \
  | jq -r '.data.result[] | "\(.metric.policy) sampled=\(.metric.sampled) \(.value[1])"'
The first two numbers agree to within a few: about 2% of 6,000 checkouts, so around 120. increase() extrapolates at the window edges, so an exact match would be luck. The sampler’s own metric shows the errors policy voting to sample about 2% of traces, slow about 3%, and baseline about 10%; a trace can match more than one, so the kept total is a little under the sum. Now search Loki for a healthy checkout’s trace_id and click through to Tempo: nine times in ten the trace is not there. Logs are not sampled; traces are. Write that down.
Comment out both scrub rules that remove card_holder (the key rule and the pattern rule), validate and restart. Within seconds docker compose logs -f otel-collector | grep -A3 card_holder shows full log records with names in them, printed by the debug/deadletter exporter, while the Loki query from step 4 stays at []: the tripwire routed every leaking record away from Loki. That is the dead-letter path doing its job, and it is also a leak into the Collector’s own logs, which is why a real deployment ships the dead-letter pipeline to a short-retention, access-controlled store and alerts on its rate. Restore the rules. Then run docker compose logs payments | grep -c card_holder: the names are still in the container’s stdout, which no Collector config can reach. When you are done, delete the three FAULT_ lines and LOADGEN_RPS from .env and run docker compose --profile telemetry up -d; keep your pipeline, it is the module’s deliverable.

Solution

One correct otel/collector.yaml
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318
        cors:
          allowed_origins: ["http://localhost:8080"]

processors:
  # First in every pipeline. The container has no memory limit set in compose;
  # 400 MiB hard / 300 MiB soft is ample at 20 to 50 RPS with a 10 s tail buffer.
  memory_limiter:
    check_interval: 1s
    limit_mib: 400
    spike_limit_mib: 100

  resourcedetection:
    detectors: [env, system]
    timeout: 2s
    override: false
    system:
      hostname_sources: [os]

  filter/health:
    error_mode: ignore
    traces:
      span:
        - 'attributes["http.target"] == "/health"'
        - 'attributes["url.path"] == "/health"'
        - 'attributes["http.route"] == "/health"'
    logs:
      log_record:
        - 'attributes["route"] == "/health"'

  attributes/scrub:
    actions:
      - key: card_holder
        action: delete
      - pattern: '(?i).*(e-?mail|card_?holder|full_?name).*'
        action: delete
      - key: user.id
        action: hash
      - key: user
        action: hash

  transform/scrub-body:
    error_mode: ignore
    log_statements:
      - replace_pattern(log.body, "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}", "<email>")

  tail_sampling:
    decision_wait: 10s
    num_traces: 20000
    expected_new_traces_per_sec: 100
    policies:
      - name: errors
        type: status_code
        status_code: { status_codes: [ERROR] }
      - name: slow
        type: latency
        latency: { threshold_ms: 1000 }
      - name: baseline
        type: probabilistic
        probabilistic: { sampling_percentage: 10 }

  batch:
    timeout: 2s
    send_batch_size: 512

connectors:
  # Tripwire after the scrub: anything still carrying a forbidden attribute
  # goes to the debug exporter instead of Loki.
  routing/pii-tripwire:
    default_pipelines: [logs/loki]
    error_mode: ignore
    table:
      - context: log
        condition: attributes["card_holder"] != nil or attributes["customer.email"] != nil
        pipelines: [logs/deadletter]

exporters:
  prometheus:
    endpoint: 0.0.0.0:8889
    resource_to_telemetry_conversion:
      enabled: true
  otlphttp/loki:
    endpoint: http://loki:3100/otlp
    tls:
      insecure: true
  otlp/tempo:
    endpoint: tempo:4317
    tls:
      insecure: true
  debug/deadletter:
    verbosity: detailed

service:
  telemetry:
    metrics:
      level: normal
      readers:
        - pull:
            exporter:
              prometheus:
                host: 0.0.0.0
                port: 8888
  pipelines:
    traces:
      receivers: [otlp]
      processors: [memory_limiter, resourcedetection, filter/health, attributes/scrub, tail_sampling, batch]
      exporters: [otlp/tempo]
    metrics:
      receivers: [otlp]
      processors: [memory_limiter, resourcedetection, batch]
      exporters: [prometheus]
    logs/in:
      receivers: [otlp]
      processors: [memory_limiter, resourcedetection, filter/health, attributes/scrub, transform/scrub-body]
      exporters: [routing/pii-tripwire]
    logs/loki:
      receivers: [routing/pii-tripwire]
      processors: [batch]
      exporters: [otlphttp/loki]
    logs/deadletter:
      receivers: [routing/pii-tripwire]
      exporters: [debug/deadletter]

Notes on choices a reviewer will ask about. The filter matches three attribute names because instrumentation versions disagree on which one carries the path. The pattern delete would also catch card_holder; the explicit key rule is there so the intent survives someone editing the regex. The resourcedetection processor adds host.name (the Collector container’s id) to every signal, which becomes a host_name label on Prometheus metrics through resource_to_telemetry_conversion; with one Collector that is one value, with a fleet it is one per Collector, which is what you want. Newer Collector releases rename the filter’s traces.span and logs.log_record keys to trace_conditions and log_conditions, and the attributes processor’s hash changed from SHA-1 to SHA-256; check the README for your version before you copy this.

All companies and people in these examples are fictional. Any resemblance to a real business or person is unintended.

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.
NEXT: SLIs, SLOs and error budgets →