Skip to content

Add span attributes and per-PostProcessor spans to markdown tracing - #8

Open
raydive wants to merge 1 commit into
masterfrom
fix/markdown-tracing-span-attributes
Open

Add span attributes and per-PostProcessor spans to markdown tracing#8
raydive wants to merge 1 commit into
masterfrom
fix/markdown-tracing-span-attributes

Conversation

@raydive

@raydive raydive commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

概要

beta / prod のトレース分析で判明した「span はあるが詳細が分からない」問題に対応し、markdown 計装に span 属性と PostProcessor 単位の子 span を追加します。

背景(トレース分析結果)

  • prod の parse テールは post_process が支配的(p95 1.73s / p99 18.3s / max 431s)。特に WikiConvertJob のトレースでは 1,153 回の parse 合計 82 分のうち 80% が post_process だが、どの PostProcessor が原因か現状の span では特定できない
  • inlines のテール(p99 587ms / max 28.3s)が入力サイズ起因かどうかも、入力サイズの記録がなく確認できない

変更内容

  • markdown.parsemarkdown.input.length 属性を追加(String / BasedSequence オーバーロード。Reader はサイズ不明のため対象外)
  • markdown.rendermarkdown.node.type / markdown.input.length / markdown.output.length(出力が CharSequence の場合のみ)属性を追加
  • PostProcessor ごとの子 span markdown.parse.post_processor を追加し、markdown.post_processor.class 属性に実装クラスの FQCN を記録(global スコープ・ノードスコープの両方)

実装メモ

  • Span.current() / GlobalOpenTelemetry は opentelemetry-api 由来で、既に opentelemetry-instrumentation-annotations の推移的依存として入っているため新規依存なし
  • agent / SDK 未接続時はいずれも no-op(span はダミー、属性設定も無害)
  • PostProcessor span は例外時に ERROR ステータスを設定して再 throw(既存の例外伝播を変えない)

検証

  • 全モジュール mvn test 成功(挙動不変)
  • opentelemetry-javaagent 2.16.0 + logging exporter のローカル実行で、属性(markdown.input.length=85markdown.node.type=Documentmarkdown.output.length=160)と markdown.parse.post_processor 子 span(markdown.post_processor.class=...AttributesNodePostProcessor)が正しい親子関係で出力されることを確認

Generated with Claude Code

Beta trace analysis showed that post_process dominates typical parse
time (p50: 8.1ms of 9.0ms) while the inlines phase dominates the tail
(p99: 303ms), but the existing spans carried no detail to explain
either. Enrich the instrumentation:

- markdown.parse: markdown.input.length attribute, to correlate tail
  latency with input size
- markdown.render: markdown.node.type, markdown.input.length, and
  markdown.output.length (when the output is a CharSequence)
- markdown.parse.post_processor: new child span per PostProcessor
  with a markdown.post_processor.class attribute, so the cost of
  post processing is attributable to individual processors

Span.current() and GlobalOpenTelemetry come from opentelemetry-api,
already a transitive compile dependency via
opentelemetry-instrumentation-annotations; both are no-ops when no
agent or SDK is wired.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant