"매 structured event 의 production runtime 의 X-ray". Application logging 은 매 incident 의 forensic record + 매 system behavior 의 narrative. 2026 best practice: structured JSON logs + OpenTelemetry semantic conventions + sampling at scale + cardinality discipline. Plain text logs 는 매 deprecated; loggers 는 매 trace context 와 correlation.
매 핵심
매 3 pillars (observability)
Logs: discrete events, high cardinality, narrative.
import{trace}from"@opentelemetry/api";importpinofrom"pino";constbaseLogger=pino();exportfunctiongetLogger() {constspan=trace.getActiveSpan();constctx=span?.spanContext();returnbaseLogger.child({trace_id: ctx?.traceId,span_id: ctx?.spanId,});}// Usage
getLogger().error({err},"payment failed");// Now searchable by trace_id across services.
// Head sampling: decide at request entry
functionshouldLog(req: Request):boolean{if(req.url.startsWith("/health"))returnfalse;// drop healthchecks
if(req.headers["x-debug"])returntrue;// force on
returnMath.random()<0.01;// 1% sample for /api/*
}// Tail sampling (in OTel collector): keep all errors + slow + 1% baseline
constaudit=pino({level:"info",base:{stream:"audit"},// separate transport → tamper-evident store (S3 + object lock)
});audit.info({actor: user.id,action:"user.delete",target: targetId,ip: req.ip,outcome:"success",},"audit");
언제: log schema design, sampling strategy, log-to-trace correlation, redaction policy review.
언제 X: 매 metric/trace 만 필요한 경우 (logs 의 cost > value), 매 single-developer side project (basic console.log 충분).
❌ 안티패턴
String interpolation logs: log.info("user " + id + " did " + action) — 매 unparseable, 매 search 불가. 매 structured fields 사용.
PII leak: 매 redaction 부재 → 매 GDPR breach.
Unbounded cardinality: 매 user_email 을 indexed field 로 → 매 storage explosion.
Logging in tight loop: 매 hot path 의 매 iter 마다 log → 매 IO bottleneck.
Catch and silent log: } catch (e) { logger.error(e); } 에서 매 context 부재 — orderId/userId 같이 add.
Plain text in 2026: 매 grep-only logs — search/correlation 매 painful.
No trace correlation: 매 service 마다 isolated logs — 매 incident 시 매 cross-service narrative 의 manual 재구성.
🧪 검증 / 중복
Verified (OpenTelemetry Logs spec, Google SRE Book Ch.6, Pino/structlog official docs).