๐ŸŽ“
MASTERCLASS๋‚œ์ด๋„: ์ค‘๊ธ‰ โž” ์‹ค์ „โฑ๏ธ ์•ฝ 3์‹œ๊ฐ„๐Ÿš€ 4๋‹จ๊ณ„ ์ปค๋ฆฌํ˜๋Ÿผ

OpenTelemetry & Grafana ํ’€์Šคํƒ ๊ด€์ธก์„ฑ ์‹ค์ „

๋ถ„์‚ฐ ํŠธ๋ ˆ์ด์‹ฑ(Trace/Span), Prometheus ๋ฉ”ํŠธ๋ฆญ, Loki ๊ตฌ์กฐํ™” ๋กœ๊ทธ๋ฅผ OpenTelemetry Collector๋กœ ํ†ตํ•ฉ ์ˆ˜์ง‘ํ•˜๊ณ  Grafana(TempoยทLokiยทPrometheus)์—์„œ Trace-to-Logs ์ƒ๊ด€๋ถ„์„ ๋ฐ ์•Œ๋žŒ๊นŒ์ง€ ์™„์„ฑํ•˜๋Š” ํ•ธ์ฆˆ์˜จ ํŠœํ† ๋ฆฌ์–ผ

--views
#opentelemetry#otel#grafana#prometheus#loki#tempo#tracing#observability#metrics#tutorial์ตœ์ข… ์—…๋ฐ์ดํŠธ: 2026-11-14

๐Ÿ“‹ ๋น ๋ฅธ ๋ช…๋ น์–ดยท์„ค์ • ์กฐํšŒ๊ฐ€ ํ•„์š”ํ•˜์‹ ๊ฐ€์š”?
์‹ค๋ฌด ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ์œ„ํ•œ OpenTelemetry ์น˜ํŠธ์‹œํŠธ ๋ฐ”๋กœ๊ฐ€๊ธฐ โž”

0. ๐ŸŒŸ ์™œ ๋ชจ๋‹ˆํ„ฐ๋ง์„ ๋„˜์–ด โ€˜๊ด€์ธก์„ฑ(Observability)โ€˜์ธ๊ฐ€์š”?

๋‹จ์ˆœ ๋ชจ๋‹ˆํ„ฐ๋ง์ด โ€œ์ง€๊ธˆ CPU๊ฐ€ 90%๋‹คโ€์ฒ˜๋Ÿผ **์ด๋ฏธ ์•„๋Š” ์ง€ํ‘œ(Known Unknowns)**๋ฅผ ๊ฐ์‹œํ•œ๋‹ค๋ฉด, **๊ด€์ธก์„ฑ(Observability)**์€ ๋ถ„์‚ฐ ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค(MSA) ํ™˜๊ฒฝ์—์„œ โ€œ์™œ ํŠน์ • ์‚ฌ์šฉ์ž์˜ ๊ฒฐ์ œ ์š”์ฒญ๋งŒ 3์ดˆ๊ฐ€ ๊ฑธ๋ ธ๋Š”๊ฐ€?โ€๋ผ๋Š” **์˜ˆ์ธกํ•˜์ง€ ๋ชปํ•œ ์›์ธ(Unknown Unknowns)**์„ Traces(์ถ”์ ) + Metrics(๋ฉ”ํŠธ๋ฆญ) + Logs(๋กœ๊ทธ) 3๋Œ€ ์‹ ํ˜ธ(Signals)์˜ ์ƒ๊ด€๊ด€๊ณ„๋กœ ์ฆ‰์‹œ ๋ฐํ˜€๋‚ด๋Š” ๋Šฅ๋ ฅ์ž…๋‹ˆ๋‹ค.

๊ด€์ธก์„ฑ 3๋Œ€ ์ถ•ํ•ต์‹ฌ ์งˆ๋ฌธ์ €์žฅ์†Œ (Grafana LGTM ์Šคํƒ)
Metrics (๋ฉ”ํŠธ๋ฆญ)โ€œ์ „์ฒด ์—๋Ÿฌ์œจ๊ณผ p99 ์ง€์—ฐ์‹œ๊ฐ„์ด ํŠ€๊ณ  ์žˆ๋Š”๊ฐ€?โ€Prometheus v3.16+
Traces (ํŠธ๋ ˆ์ด์Šค)โ€œAPI Gateway โž” Order โž” Payment ์ค‘ ์–ด๋””์„œ ๋ณ‘๋ชฉ์ด ๋‚ฌ๋Š”๊ฐ€?โ€Grafana Tempo v3.1+
Logs (๋กœ๊ทธ)โ€œ๊ทธ ์ˆœ๊ฐ„ ํ•ด๋‹น ์š”์ฒญ์ด ๋ฑ‰์€ ์ •ํ™•ํ•œ ์˜ˆ์™ธ ๋ฉ”์‹œ์ง€๋Š” ๋ฌด์—‡์ธ๊ฐ€?โ€Grafana Loki v3.7+

1. ํ•„์ˆ˜ ์‚ฌ์ „ ์š”๊ฑด & ์‹œ์Šคํ…œ ์š”๊ตฌ์‚ฌ์–‘ (Prerequisites & System Requirements)

๐Ÿ’ป ์‹œ์Šคํ…œ ์„ค์น˜ ๋ฐ ์‹คํ–‰ ์š”๊ตฌ์‚ฌ์–‘ (System Requirements)

ํ•ญ๋ชฉ์ตœ์†Œ ์‚ฌ์–‘ (Minimum)๊ถŒ์žฅ ์‚ฌ์–‘ (Recommended)์ฐธ๊ณ  ๋ฐ ๋น„๊ณ 
์šด์˜์ฒด์ œ (OS)Windows 10/11 (WSL2), macOS 13+, LinuxUbuntu 24.04 LTS / Docker DesktopLGTM ์Šคํƒ + OTel Collector ์ปจํ…Œ์ด๋„ˆ ๊ตฌ๋™
CPU ์•„ํ‚คํ…์ฒ˜2์ฝ”์–ด ์ด์ƒ4์ฝ”์–ด ~ 8์ฝ”์–ด ์ด์ƒPrometheus TSDB, Tempo, Loki, App ๋™์‹œ ์‹คํ–‰
๋ฉ”๋ชจ๋ฆฌ (RAM)์ตœ์†Œ 6 GB ์ด์ƒ16 GB ์ด์ƒDocker Desktop ํ• ๋‹น ๋ฉ”๋ชจ๋ฆฌ ์ตœ์†Œ 6GB ๊ถŒ์žฅ
๋””์Šคํฌ (Storage)15 GB ์ด์ƒ์˜ ์—ฌ์œ  ๊ณต๊ฐ„30 GB+ NVMe SSD์‹œ๊ณ„์—ด ๋ฉ”ํŠธ๋ฆญ ๋ฐ ํŠธ๋ ˆ์ด์Šค ๋ธ”๋ก ์ €์žฅ
๋Ÿฐํƒ€์ž„ / ๋„๊ตฌDocker Engine 26+, Python 3.12+ (๋˜๋Š” Node 22+)Docker Compose v2.30+, curlotel/opentelemetry-collector-contrib:0.165.0 ๊ธฐ์ค€

[!IMPORTANT] ๊ณต์‹ ๋ฒค๋” ์ตœ์‹  ๋ฒ„์ „ ์ •๋ณด (2026๋…„ 11์›” ๊ธฐ์ค€):

  • OpenTelemetry Collector Contrib: v0.165.0
  • Prometheus: v3.16.0 (Native OTLP Ingestion ์ง€์›)
  • Grafana Tempo: v3.1.0 | Grafana Loki: v3.7.0

๐Ÿ”ญ ํ’€์Šคํƒ ๊ด€์ธก์„ฑ ํŒŒ์ดํ”„๋ผ์ธ ๋ฉ˜ํƒˆ ๋ชจ๋ธ (ASCII Diagram)

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚             OpenTelemetry + Grafana LGTM Observability Stack            โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                         โ”‚
โ”‚  [ Service A (Gateway) ] โ”€โ”€(W3C traceparent)โ”€โ”€โ–ถ [ Service B (Order) ]   โ”‚
โ”‚           โ”‚                                              โ”‚              โ”‚
โ”‚           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜              โ”‚
โ”‚                          โ–ผ  OTLP (gRPC :4317 / HTTP :4318)              โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  OpenTelemetry Collector (v0.165.0)                               โ”‚  โ”‚
โ”‚  โ”‚   Receivers(otlp) โ”€โ–ถ Processors(batch, memory_limiter, tail_samp) โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚             โ–ผ                       โ–ผ                      โ–ผ            โ”‚
โ”‚    [ Tempo v3.1 ]          [ Prometheus v3.16 ]     [ Loki v3.7 ]       โ”‚
โ”‚    (๋ถ„์‚ฐ ํŠธ๋ ˆ์ด์Šค)          (RED/USE ๋ฉ”ํŠธ๋ฆญ)        (TraceID ๊ตฌ์กฐํ™” ๋กœ๊ทธ)โ”‚
โ”‚             โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ”‚                                     โ–ผ                                   โ”‚
โ”‚                 [ Grafana ํ†ตํ•ฉ ๋Œ€์‹œ๋ณด๋“œ (:3000) ]                        โ”‚
โ”‚                 โ€ข Exemplar ํด๋ฆญ โž” Trace โž” ๊ด€๋ จ Logs 1ํด๋ฆญ ์ ํ”„!          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2. [1๊ฐ•] Docker Compose๋กœ OTel Collector & LGTM ํ’€์Šคํƒ ๊ตฌ์ถ•

๊ฐ€์žฅ ๋จผ์ € ๋กœ์ปฌ ํ™˜๊ฒฝ์— OpenTelemetry Collector + Tempo + Loki + Prometheus + Grafana ์ „์ฒด ๊ด€์ธก์„ฑ ๋ฐฑ์—”๋“œ๋ฅผ ํ•œ ๋ฒˆ์— ๊ธฐ๋™ํ•ฉ๋‹ˆ๋‹ค.

1๋‹จ๊ณ„: ํ”„๋กœ์ ํŠธ ๋””๋ ‰ํ† ๋ฆฌ ๋ฐ OTel Collector ์„ค์ • ์ž‘์„ฑ

mkdir otel-grafana-lab && cd otel-grafana-lab

otel-collector-config.yaml ํŒŒ์ผ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค:

# otel-collector-config.yaml
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318

processors:
  memory_limiter:
    check_interval: 1s
    limit_mib: 512
  batch:
    timeout: 2s
    send_batch_size: 1024

exporters:
  # 1. Traces -> Grafana Tempo
  otlp/tempo:
    endpoint: tempo:4317
    tls:
      insecure: true

  # 2. Metrics -> Prometheus (OTLP HTTP Receiver ํ™œ์šฉ)
  otlphttp/prometheus:
    endpoint: http://prometheus:9090/api/v1/otlp
    tls:
      insecure: true

  # 3. Logs -> Grafana Loki (๋„ค์ดํ‹ฐ๋ธŒ OTLP ์—”๋“œํฌ์ธํŠธ)
  otlphttp/loki:
    endpoint: http://loki:3100/otlp
    tls:
      insecure: true

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [memory_limiter, batch]
      exporters: [otlp/tempo]
    metrics:
      receivers: [otlp]
      processors: [memory_limiter, batch]
      exporters: [otlphttp/prometheus]
    logs:
      receivers: [otlp]
      processors: [memory_limiter, batch]
      exporters: [otlphttp/loki]

2๋‹จ๊ณ„: prometheus.yaml, tempo.yaml ๋ฐ compose.yaml ์ž‘์„ฑ

# prometheus.yaml
global:
  scrape_interval: 15s

# OTLP ์ˆ˜์‹  ๋ฐ Exemplar ํ™œ์„ฑํ™”
storage:
  tsdb:
    out_of_order_time_window: 30m
# tempo.yaml
server:
  http_listen_port: 3200

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

storage:
  trace:
    backend: local
    local:
      path: /var/tempo/traces
# compose.yaml
services:
  otel-collector:
    image: otel/opentelemetry-collector-contrib:0.165.0
    command: ["--config=/etc/otelcol-contrib/config.yaml"]
    volumes:
      - ./otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml
    ports:
      - "4317:4317" # OTLP gRPC
      - "4318:4318" # OTLP HTTP
    depends_on: [tempo, prometheus, loki]

  tempo:
    image: grafana/tempo:3.1.0
    command: ["-config.file=/etc/tempo.yaml"]
    volumes:
      - ./tempo.yaml:/etc/tempo.yaml
    ports:
      - "3200:3200"

  loki:
    image: grafana/loki:3.7.0
    command: ["-config.file=/etc/loki/local-config.yaml"]
    ports:
      - "3100:3100"

  prometheus:
    image: prom/prometheus:v3.16.0
    command:
      - --config.file=/etc/prometheus/prometheus.yaml
      - --web.enable-otlp-receiver
      - --enable-feature=exemplar-storage
    volumes:
      - ./prometheus.yaml:/etc/prometheus/prometheus.yaml
    ports:
      - "9090:9090"

  grafana:
    image: grafana/grafana:11.4.0
    environment:
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
    ports:
      - "3000:3000"
    depends_on: [tempo, prometheus, loki]
# ์ „์ฒด LGTM + OTel ์Šคํƒ ๊ธฐ๋™
docker compose up -d

# ์ƒํƒœ ํ™•์ธ (๋ชจ๋‘ Up ์ƒํƒœ์—ฌ์•ผ ํ•จ)
docker compose ps

3. [2๊ฐ•] OTel Collector ํŒŒ์ดํ”„๋ผ์ธ & Tail-Based Sampling ์„ค๊ณ„

ํ”„๋กœ๋•์…˜ ํŠธ๋ž˜ํ”ฝ์ด ์ดˆ๋‹น ์ˆ˜๋งŒ ๊ฑด์— ๋‹ฌํ•  ๋•Œ ๋ชจ๋“  ์ •์ƒ(200 OK) ํŠธ๋ ˆ์ด์Šค๋ฅผ ์ €์žฅํ•˜๋ฉด ์Šคํ† ๋ฆฌ์ง€ ๋น„์šฉ์ด ํญ๋ฐœํ•ฉ๋‹ˆ๋‹ค. ์‹ค๋ฌด์—์„œ๋Š” ์—๋Ÿฌ(ERROR)๊ฐ€ ๋ฐœ์ƒํ–ˆ๊ฑฐ๋‚˜ ์ง€์—ฐ์‹œ๊ฐ„์ด 500ms ์ด์ƒ์ธ ๋А๋ฆฐ ์š”์ฒญ๋งŒ 100% ๋ณด์กดํ•˜๊ณ , ์ •์ƒ ์š”์ฒญ์€ 5%๋งŒ ์ƒ˜ํ”Œ๋งํ•˜๋Š” Tail-Based Sampling์„ Collector์— ์ ์šฉํ•ฉ๋‹ˆ๋‹ค.

# otel-collector-config.yaml (processors ์„น์…˜ ํ™•์žฅ ์˜ˆ์‹œ)
processors:
  memory_limiter:
    check_interval: 1s
    limit_mib: 1024

  # ๊ฐœ์ธ์ •๋ณด(PII) ๋งˆ์Šคํ‚น: ์ด๋ฉ”์ผ/ํ† ํฐ ์†์„ฑ ์ œ๊ฑฐ
  attributes/redact:
    actions:
      - key: http.request.header.authorization
        action: delete
      - key: user.email
        action: hash

  # Tail-Based Sampling: ์—๋Ÿฌ ๋ฐ 500ms ์ดˆ๊ณผ ์ง€์—ฐ ํŠธ๋ ˆ์ด์Šค๋Š” 100% ์ˆ˜์ง‘
  tail_sampling:
    decision_wait: 10s
    num_traces: 50000
    policies:
      - name: always-sample-errors
        type: status_code
        status_code: { status_codes: [ERROR] }
      - name: slow-requests
        type: latency
        latency: { threshold_ms: 500 }
      - name: probabilistic-normal
        type: probabilistic
        probabilistic: { sampling_percentage: 5 }

4. [3๊ฐ•] FastAPI ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค ๊ณ„์ธก & W3C ๋ถ„์‚ฐ ํŠธ๋ ˆ์ด์‹ฑ ์ „ํŒŒ

๋‘ ๊ฐœ์˜ ์„œ๋น„์Šค(gateway-service โž” order-service)๊ฐ€ HTTP๋กœ ํ†ต์‹ ํ•  ๋•Œ, OpenTelemetry SDK๊ฐ€ ์ž๋™์œผ๋กœ traceparent HTTP ํ—ค๋”๋ฅผ ์ฃผ์ž…ยท์ถ”์ถœํ•˜์—ฌ ํ•˜๋‚˜์˜ ํ†ตํ•ฉ๋œ Trace ํŠธ๋ฆฌ๋ฅผ ๋งŒ๋“ค์–ด์ค๋‹ˆ๋‹ค.

1๋‹จ๊ณ„: ์˜์กด์„ฑ ์„ค์น˜

pip install fastapi uvicorn httpx \
  opentelemetry-distro opentelemetry-exporter-otlp \
  opentelemetry-instrumentation-fastapi opentelemetry-instrumentation-httpx

2๋‹จ๊ณ„: gateway.py (8000 ํฌํŠธ) & order.py (8001 ํฌํŠธ) ์ž‘์„ฑ

# order.py (ํฌํŠธ 8001)
import logging, random, time
from fastapi import FastAPI, HTTPException
from opentelemetry import trace

app = FastAPI(title="order-service")
tracer = trace.get_tracer(__name__)
logger = logging.getLogger("order")
logging.basicConfig(level=logging.INFO)

@app.post("/orders")
async def create_order(item_id: str = "SKU-100"):
    # ์ปค์Šคํ…€ Span ์ƒ์„ฑ์œผ๋กœ DB/๊ฒฐ์ œ ๊ตฌ๊ฐ„ ์„ธ๋ถ„ํ™”
    with tracer.start_as_current_span("db.insert_order") as span:
        span.set_attribute("order.item_id", item_id)
        delay = random.uniform(0.05, 0.35)
        time.sleep(delay)

        ctx = span.get_span_context()
        trace_id = format(ctx.trace_id, "032x")
        logger.info(f"์ฃผ๋ฌธ ์ฒ˜๋ฆฌ ์™„๋ฃŒ item={item_id} trace_id={trace_id}")

        if random.random() < 0.15:
            span.set_status(trace.StatusCode.ERROR, "์žฌ๊ณ  ๋ถ€์กฑ ์˜ค๋ฅ˜")
            raise HTTPException(status_code=500, detail="Out of stock")

        return {"status": "created", "item_id": item_id, "trace_id": trace_id}
# gateway.py (ํฌํŠธ 8000)
import httpx
from fastapi import FastAPI

app = FastAPI(title="gateway-service")

@app.post("/checkout")
async def checkout(item_id: str = "SKU-100"):
    # httpx ์ž๋™ ๊ณ„์ธก์ด traceparent ํ—ค๋”๋ฅผ order-service๋กœ ์ž๋™ ์ „ํŒŒ
    async with httpx.AsyncClient() as client:
        resp = await client.post(f"http://127.0.0.1:8001/orders?item_id={item_id}")
        return {"gateway_status": resp.status_code, "downstream": resp.json()}

3๋‹จ๊ณ„: ์ฝ”๋“œ ์ˆ˜์ • ์—†์ด opentelemetry-instrument๋กœ ์‹คํ–‰ & ๋ถ€ํ•˜ ํ…Œ์ŠคํŠธ

# ํ„ฐ๋ฏธ๋„ 1: order-service ์‹คํ–‰
OTEL_SERVICE_NAME=order-service \
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 \
OTEL_EXPORTER_OTLP_PROTOCOL=grpc \
OTEL_LOGS_EXPORTER=otlp \
opentelemetry-instrument uvicorn order:app --port 8001

# ํ„ฐ๋ฏธ๋„ 2: gateway-service ์‹คํ–‰
OTEL_SERVICE_NAME=gateway-service \
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 \
OTEL_EXPORTER_OTLP_PROTOCOL=grpc \
OTEL_LOGS_EXPORTER=otlp \
opentelemetry-instrument uvicorn gateway:app --port 8000

# ํ„ฐ๋ฏธ๋„ 3: ํ…Œ์ŠคํŠธ ํŠธ๋ž˜ํ”ฝ 20๊ฑด ๋ฐœ์†ก
for i in {1..20}; do curl -s -X POST "http://localhost:8000/checkout?item_id=SKU-$i"; echo ""; done

5. [4๊ฐ•] Grafana ํ†ตํ•ฉ ์ƒ๊ด€๋ถ„์„ (Trace-to-Logs & RED ๋ฉ”ํŠธ๋ฆญ)

์ด์ œ ๋ธŒ๋ผ์šฐ์ €์—์„œ http://localhost:3000 ์œผ๋กœ ์ ‘์†ํ•˜์—ฌ Grafana ๋ฐ์ดํ„ฐ ์†Œ์Šค๋ฅผ ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

1๋‹จ๊ณ„: Grafana Data Sources 3์ข… ๋“ฑ๋ก

Connections โ†’ Data sources โ†’ Add data source์—์„œ ์•„๋ž˜ 3๊ฐœ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค:

  1. Prometheus: URL http://prometheus:9090
  2. Tempo: URL http://tempo:3200
    • Trace to logs ์„ค์ •: Data source = Loki, Filter by Trace ID ํ™œ์„ฑํ™” (trace_id)
  3. Loki: URL http://loki:3100
    • Derived fields ์„ค์ •: Regex trace_id=(\w+), Internal link = Tempo

2๋‹จ๊ณ„: ์‹ค๋ฌด ํ•ต์‹ฌ PromQL (RED ๋ฉ”ํŠธ๋ฆญ ๋Œ€์‹œ๋ณด๋“œ)

# 1. Rate (์ดˆ๋‹น ์š”์ฒญ ์ˆ˜ RPS)
sum(rate(http_server_duration_milliseconds_count[1m])) by (service_name)

# 2. Errors (5xx ์—๋Ÿฌ์œจ %)
sum(rate(http_server_duration_milliseconds_count{http_status_code=~"5.."}[5m]))
/
sum(rate(http_server_duration_milliseconds_count[5m])) * 100

# 3. Duration (p95 / p99 ์‘๋‹ต ์ง€์—ฐ์‹œ๊ฐ„)
histogram_quantile(0.99, sum(rate(http_server_duration_milliseconds_bucket[5m])) by (le, service_name))

3๋‹จ๊ณ„: 1ํด๋ฆญ ์žฅ์•  ์ถ”์  (Explore)

  1. Explore โ†’ Tempo์—์„œ Service Name = gateway-service, Status = Error๋กœ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค.
  2. ๋นจ๊ฐ„์ƒ‰ ์—๋Ÿฌ Trace๋ฅผ ํด๋ฆญํ•ด gateway-service โž” order-service โž” db.insert_order ์›Œํ„ฐํด(Waterfall)์—์„œ ๋ณ‘๋ชฉ ๊ตฌ๊ฐ„์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
  3. Span ์šฐ์ธก์˜ Logs for this span ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด Loki์—์„œ ํ•ด๋‹น trace_id์˜ ์ •ํ™•ํ•œ ์—๋Ÿฌ ๋กœ๊ทธ๋งŒ ์ฆ‰์‹œ ํ•„ํ„ฐ๋ง๋ฉ๋‹ˆ๋‹ค!

6. ์‹ค๋ฌด ์ฃผ์˜์‚ฌํ•ญ & ํ”„๋กœ๋•์…˜ ์ฒดํฌ๋ฆฌ์ŠคํŠธ

  • ๋ฉ”๋ชจ๋ฆฌ ์ œํ•œ(memory_limiter) ์ตœ์šฐ์„  ๋ฐฐ์น˜: OTel Collector ํŒŒ์ดํ”„๋ผ์ธ์˜ processors ์ฒซ ๋ฒˆ์งธ ์ˆœ์„œ์— ๋ฐ˜๋“œ์‹œ memory_limiter๋ฅผ ๋‘์–ด ํŠธ๋ž˜ํ”ฝ ํญ์ฃผ ์‹œ OOM Kill์„ ๋ฐฉ์ง€ํ•˜์„ธ์š”.
  • ๋ฏผ๊ฐ ์ •๋ณด(PII) ํ•„ํ„ฐ๋ง: HTTP Authorization ํ—ค๋”, ์ฃผ๋ฏผ๋ฒˆํ˜ธ, ์นด๋“œ๋ฒˆํ˜ธ ๋“ฑ์ด Span Attribute๋‚˜ Log์— ํ‰๋ฌธ์œผ๋กœ ๋‚จ์ง€ ์•Š๋„๋ก Collector attributes / redaction ํ”„๋กœ์„ธ์„œ๋กœ ๋งˆ์Šคํ‚นํ•˜์„ธ์š”.
  • ์นด๋””๋„๋ฆฌํ‹ฐ(Cardinality) ํญ๋ฐœ ์ฃผ์˜: Prometheus ๋ฉ”ํŠธ๋ฆญ ๋ผ๋ฒจ(user_id, order_id, UUID ํฌํ•จ URL ๊ฒฝ๋กœ ๋“ฑ)์— ๋ฌดํ•œํžˆ ์ฆ๊ฐ€ํ•˜๋Š” ๊ฐ’์„ ๋„ฃ์œผ๋ฉด TSDB ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๊ณ ๊ฐˆ๋ฉ๋‹ˆ๋‹ค. ๊ณ ์œ  ID๋Š” Trace Attribute๋‚˜ Log์—๋งŒ ๊ธฐ๋กํ•˜์„ธ์š”.
  • ๋น„๋™๊ธฐ ํ(Kafka / RabbitMQ) ์ปจํ…์ŠคํŠธ ์ „ํŒŒ: HTTP๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋ฉ”์‹œ์ง€ ํ๋ฅผ ๊ฑฐ์น˜๋Š” MSA์—์„œ๋„ Producer ๋ฉ”์‹œ์ง€ ํ—ค๋”์— traceparent๋ฅผ ์ฃผ์ž…ํ•˜๊ณ  Consumer์—์„œ ์ถ”์ถœํ•ด์•ผ ์ „์ฒด ๋น„๋™๊ธฐ ํŒŒ์ดํ”„๋ผ์ธ์ด ํ•˜๋‚˜์˜ Trace๋กœ ์ด์–ด์ง‘๋‹ˆ๋‹ค.
๐Ÿ’ฌ

์˜๊ฒฌ ๋ฐ ์งˆ๋ฌธ

0
0 / 1500