165 lines
5.2 KiB
Markdown
165 lines
5.2 KiB
Markdown
---
|
|
id: wiki-2026-0508-스택-트레이스-stack-trace
|
|
title: 스택 트레이스 (Stack Trace)
|
|
category: 10_Wiki/Topics
|
|
status: verified
|
|
canonical_id: self
|
|
aliases: [Stack Trace, Call Stack, Backtrace, 콜스택]
|
|
duplicate_of: none
|
|
source_trust_level: A
|
|
confidence_score: 0.9
|
|
verification_status: applied
|
|
tags: [debugging, observability, error-handling, runtime]
|
|
raw_sources: []
|
|
last_reinforced: 2026-05-10
|
|
github_commit: pending
|
|
tech_stack:
|
|
language: Python/Go/JS
|
|
framework: Sentry/OpenTelemetry
|
|
---
|
|
|
|
# 스택 트레이스 (Stack Trace)
|
|
|
|
## 매 한 줄
|
|
> **"매 error 의 발생 시점 의 call chain 의 snapshot."**. 매 runtime 의 active frame 의 list — function name · file · line · 매 local variable (optional). 2026 modern observability 는 매 stack trace 의 distributed trace · source map · symbolication · 매 LLM-assisted root cause 의 통합.
|
|
|
|
## 매 핵심
|
|
|
|
### 매 구성 요소
|
|
- **Frame**: 매 each function call 의 record (caller info).
|
|
- **Top of stack**: 매 error 의 throw 한 가장 안쪽 frame.
|
|
- **Bottom**: 매 program entry (main, event loop).
|
|
- **Symbolication**: 매 minified/compiled binary 의 readable name 의 resolve.
|
|
|
|
### 매 종류
|
|
- **Native**: 매 Go panic, C++ SIGSEGV — debug symbols 의 필요.
|
|
- **Managed**: JVM, .NET, Python — runtime 의 자동 capture.
|
|
- **Async**: 매 promise/coroutine — 매 await chain 의 reconstruct (Python 3.11+ exception groups, V8 async stack).
|
|
- **Distributed**: 매 trace_id + span 의 across-service stack.
|
|
|
|
### 매 응용
|
|
1. 매 production error 의 root cause 의 빠르게 locate.
|
|
2. 매 performance profiling — 매 sample-based stack 의 hot path 의 reveal.
|
|
3. 매 security forensics — 매 exploit 의 entry point 의 identify.
|
|
|
|
## 💻 패턴
|
|
|
|
### Python — full traceback with locals
|
|
```python
|
|
import traceback, sys
|
|
|
|
try:
|
|
risky_op()
|
|
except Exception:
|
|
tb = traceback.TracebackException.from_exception(
|
|
sys.exc_info()[1], capture_locals=True
|
|
)
|
|
print("".join(tb.format()))
|
|
```
|
|
|
|
### Go — runtime stack
|
|
```go
|
|
import "runtime/debug"
|
|
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
log.Printf("panic: %v\n%s", r, debug.Stack())
|
|
}
|
|
}()
|
|
```
|
|
|
|
### Node.js — async stack 의 enable
|
|
```js
|
|
// Node 22+ 매 default
|
|
Error.stackTraceLimit = 50;
|
|
process.on("unhandledRejection", (reason) => {
|
|
console.error(reason instanceof Error ? reason.stack : reason);
|
|
});
|
|
```
|
|
|
|
### Source map symbolication (browser)
|
|
```js
|
|
import { SourceMapConsumer } from "source-map";
|
|
const raw = await fetch("app.js.map").then(r => r.json());
|
|
await SourceMapConsumer.with(raw, null, consumer => {
|
|
const orig = consumer.originalPositionFor({ line: 42, column: 13 });
|
|
console.log(orig); // { source: "src/app.tsx", line: 117, name: "handleClick" }
|
|
});
|
|
```
|
|
|
|
### Sentry SDK with breadcrumbs
|
|
```python
|
|
import sentry_sdk
|
|
sentry_sdk.init(dsn="https://...", traces_sample_rate=0.1)
|
|
|
|
sentry_sdk.add_breadcrumb(category="auth", message="user login", level="info")
|
|
# 매 exception 의 자동 capture + breadcrumb chain
|
|
```
|
|
|
|
### OpenTelemetry — stack 의 distributed trace 의 attach
|
|
```python
|
|
from opentelemetry import trace
|
|
span = trace.get_current_span()
|
|
span.record_exception(exc, attributes={"stack": traceback.format_exc()})
|
|
```
|
|
|
|
### Java — Throwable.getStackTrace
|
|
```java
|
|
try { ... } catch (Exception e) {
|
|
for (StackTraceElement el : e.getStackTrace()) {
|
|
log.error("{}.{} ({}:{})",
|
|
el.getClassName(), el.getMethodName(),
|
|
el.getFileName(), el.getLineNumber());
|
|
}
|
|
}
|
|
```
|
|
|
|
### LLM-assisted analysis (Claude Opus 4.7)
|
|
```python
|
|
prompt = f"""Stack trace:
|
|
{stack}
|
|
|
|
Recent commits:
|
|
{git_log}
|
|
|
|
매 root cause + 매 fix candidate 의 propose."""
|
|
```
|
|
|
|
## 매 결정 기준
|
|
| 상황 | Approach |
|
|
|---|---|
|
|
| Production unhandled error | Sentry/Datadog 매 자동 capture |
|
|
| Local dev | Native debugger (gdb, dlv, pdb) |
|
|
| Async/promise chain | Runtime async stack 의 enable |
|
|
| Minified prod JS | Source map upload + symbolication |
|
|
| Distributed call | OTel trace + span exception |
|
|
|
|
**기본값**: 매 OTel + Sentry 의 combine — 매 single trace 에서 매 service-crossing stack 의 see.
|
|
|
|
## 🔗 Graph
|
|
- 부모: [[Debugging]] · [[Observability]]
|
|
- 변형: [[Async_Stack_Trace]] · [[Distributed_Tracing]]
|
|
- 응용: [[Error_Monitoring]] · [[Crash_Reporting]] · [[Profiling]]
|
|
- Adjacent: [[Source_Maps]] · [[Symbolication]] · [[Logging]]
|
|
|
|
## 🤖 LLM 활용
|
|
**언제**: 매 long stack trace 의 summarize, 매 framework noise 의 filter, 매 likely culprit frame 의 highlight.
|
|
**언제 X**: 매 sensitive PII 의 local variable 의 포함 — sanitize first.
|
|
|
|
## ❌ 안티패턴
|
|
- **Swallow exception**: `except: pass` — 매 stack 의 lose.
|
|
- **Re-raise wrong**: 매 `raise e` (Python) 매 traceback 의 truncate — `raise` bare 의 use.
|
|
- **No source map**: 매 prod minified — stack 의 unreadable.
|
|
- **Stack 의 user 의 expose**: 매 5xx response 에 raw stack 의 dump — info leak.
|
|
- **Limit too low**: `Error.stackTraceLimit = 10` 매 root frame 의 cut off.
|
|
|
|
## 🧪 검증 / 중복
|
|
- Verified (Python docs traceback module, V8 async stack RFC, Sentry symbolication guide 2026).
|
|
- 신뢰도 A.
|
|
|
|
## 🕓 Changelog
|
|
| 날짜 | 변경 |
|
|
|---|---|
|
|
| 2026-05-08 | Phase 1 |
|
|
| 2026-05-10 | Manual cleanup — async stacks, symbolication, OTel integration |
|