# 05 · otel-console-span **演示**:OpenTelemetry SDK 生成父子 span:`handle-request` 内嵌 `load-user`,共享 trace_id,child 的 `parent_id` 指向 parent;child 带一个 `cache_miss` 事件;单行 JSON 导出到内存后断言。 **运行**: ```sh uv run python examples/38-observability-otel/05-otel-console-span/otel_console_span.py ``` **预期输出**(3.12.9 + opentelemetry-sdk 1.45.2;trace_id 每次不同): ```text trace_id: 5cf718aeff5b151f2a7221458f8c6b6f span_names: ['load-user', 'handle-request'] same_trace: True child_parent_matches: True child_event: cache_miss ``` **依赖**:`uv sync --group obs`(opentelemetry-sdk)。 **注意**:`ConsoleSpanExporter` 默认是缩进 JSON 且不自带换行;自定义 formatter 要自己补 `\n` 才能按行解析。span 在 `with` 退出时结束,所以子 span 通常先于父 span 导出。