Files
mtusi2026lab6/infra/otel/collector-tail.yaml

123 lines
6.0 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# OpenTelemetry Collector (contrib 0.130.0) — получатель/обработчик/экспортёр, НЕ хранилище.
# API и worker → OTLP/HTTP :4318 (сеть telemetry, наружу не публикуется) → три pipeline:
# traces → Tempo (OTLP/HTTP http://tempo:4318)
# metrics → Prometheus (OTLP receiver http://prometheus:9090/api/v1/otlp)
# logs → Loki (native OTLP http://loki:3100/otlp)
# Защита памяти и поведение при недоступном backend:
# * memory_limiter — первым в каждой pipeline: при росте RAM выше limit-spike Collector отклоняет приём
# (SDK получает 503/429, повторяет и затем отбрасывает — потери считаются на стороне SDK);
# * sending_queue каждого экспортёра — ограниченная очередь в памяти (queue_size батчей); при переполнении
# новые данные отбрасываются (otelcol_exporter_enqueue_failed_*), а не накапливаются бесконечно;
# * retry_on_failure — повтор с экспоненциальной паузой, не дольше max_elapsed_time, затем батч отбрасывается
# (otelcol_exporter_send_failed_*). Telemetry — «best effort»: бизнес-запросы от неё не зависят.
# ВАРИАНТ ТРЕКА 1 «сбалансированный»: SDK отправляет 100% spans, решение о хранении trace принимает
# Collector ПОСЛЕ завершения trace (tail sampling): все ошибки, все медленные, все trace pipeline вложений
# и 10% остальных. Метрики RED считаются в SDK по всем запросам и от sampling не зависят.
# Ограничение: один экземпляр Collector (все spans trace приходят в один процесс); для нескольких —
# loadbalancing exporter по trace_id. Включение: OTEL_COLLECTOR_CONFIG=collector-tail.yaml.
extensions:
health_check:
endpoint: 0.0.0.0:13133 # внутренняя сеть observability; на хост не публикуется
receivers:
otlp:
protocols:
http:
endpoint: 0.0.0.0:4318
max_request_body_size: 8388608 # 8 MiB на запрос экспорта
processors:
memory_limiter:
check_interval: 1s
limit_mib: 200 # контейнер ограничен 256 MiB
spike_limit_mib: 50 # мягкий порог 150 MiB: дальше приём отклоняется
tail_sampling:
decision_wait: 10s # ждать spans trace (worker завершает задание через секунды)
num_traces: 20000 # предел trace в памяти; старые решения вытесняются
expected_new_traces_per_sec: 200
decision_cache:
sampled_cache_size: 20000 # поздние spans (повтор задания) получают то же решение
non_sampled_cache_size: 20000
policies:
- name: errors
type: status_code
status_code: {status_codes: [ERROR]}
- name: slow
type: latency
latency: {threshold_ms: 250}
- name: attachment-pipeline # upload → worker: редкие и дорогие операции храним все
type: string_attribute
string_attribute: {key: messaging.system, values: [nats]}
- name: baseline
type: probabilistic
probabilistic: {sampling_percentage: 10}
batch:
send_batch_size: 1024
send_batch_max_size: 2048
timeout: 2s
# Защита «в глубину»: даже если код по ошибке положит такой атрибут, в хранилища он не уйдёт.
attributes/scrub:
actions:
- pattern: '(?i)^(.*\.)?(password|passwd|token|access_token|session_token|authorization|cookie|secret|api_key)$'
action: delete
- pattern: '(?i)^http\.request\.header\.(authorization|cookie|x-api-key)$'
action: delete
- key: db.query.parameters
action: delete
exporters:
otlphttp/tempo:
endpoint: http://tempo:4318
compression: gzip
timeout: 5s
sending_queue: &queue
enabled: true
num_consumers: 2
queue_size: 200 # батчей (≤ 2048 элементов каждый) — предел RAM очереди
retry_on_failure: &retry
enabled: true
initial_interval: 1s
max_interval: 10s
max_elapsed_time: 120s
otlphttp/loki:
endpoint: http://loki:3100/otlp
compression: gzip
timeout: 5s
sending_queue: *queue
retry_on_failure: *retry
otlphttp/prometheus:
endpoint: http://prometheus:9090/api/v1/otlp
compression: gzip
timeout: 5s
sending_queue: *queue
retry_on_failure: *retry
service:
extensions: [health_check]
telemetry:
logs:
level: info
metrics:
level: detailed # otelcol_* метрики самого Collector: принято/отклонено/отправлено/очереди
readers:
- pull:
exporter:
prometheus:
host: 0.0.0.0
port: 8888 # скрейпит Prometheus (сеть observability)
without_units: true # классические имена: otelcol_exporter_sent_spans_total (без «_{spans}»)
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, attributes/scrub, tail_sampling, batch]
exporters: [otlphttp/tempo]
metrics:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlphttp/prometheus]
logs:
receivers: [otlp]
processors: [memory_limiter, attributes/scrub, batch]
exporters: [otlphttp/loki]