Upgrade to Pro — share decks privately, control downloads, hide ads and more …

公式サンプルが コンパイルできない 〜tracing::info! のエラーから Rust の...

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →
Avatar for Retasusan Retasusan
September 27, 2026

公式サンプルが コンパイルできない 〜tracing::info! のエラーから Rust のマクロを読む〜

Avatar for Retasusan

Retasusan

September 27, 2026

More Decks by Retasusan

Other Decks in Technology

Transcript

  1. そもそもtracing traitって何者? tracing is a framework for instrumenting Rust programs

    to collect structured, event-based diagnostic information. tracingは、構造化されたイベントベースの診断情報を収集するために、 Rustプログラムを計測す るためのフレームワークです。 docs.rs/tracingより docs.rs/tracing:https://docs.rs/tracing/latest/tracing/
  2. そもそもtracing traitって何者? tracing is a framework for instrumenting Rust programs

    to collect structured, event-based diagnostic information. tracingは、構造化されたイベントベースの診断情報を収集するために、 Rustプログラムを計測す るためのフレームワークです。 docs.rs/tracingより わかったような分からないような? docs.rs/tracing:https://docs.rs/tracing/latest/tracing/
  3. 問題の⼊⼒は roll.value ここでの `.` `roll.value` は フィールド名。 右辺は記録する値。 error: local

    ambiguity when calling macro `info` `local ambiguity`: この `.` をどの部分が読むか決められない。 OpenTelemetry Rust Getting Started
  4. info! の定義の要点だけ抜く (name: $name:expr, $($k:ident).+ $($field:tt)*) $name:expr $($k:ident).+ $($field:tt)* Event

    名の値 roll と value を ピリオドでつなぐ 残りのトークン。 ピリオドも含められる 同じピリオドを左側の区切りにも、右側の⼊⼒にもできる。 出典: docs.rs/tracing/latest/src/tracing/macros.rs.html
  5. ピリオドで2通りに分かれる roll . value = random_number 解釈 A: k =

    roll.value / field =「= random_number, ...」 解釈 B: k = roll / field =「. value = random_number, ...」 候補A: 名前を続ける 候補B: 残りを始める roll.value のピリオドを 名前の区切りとして読む roll で名前を終え、 ピリオドから残りを読む Rust は次の `value` を⾒て選び直さない → local ambiguity Rust Reference: macro_rules! は局所的な曖昧さを先読みで解消しない
  6. issue を投げた 報告した内容 1. `cargo run` での再現⼿順 2. コンパイラのエラー 3.

    波括弧を使う修正案 github.com/open-telemetry/opentelemetry.io/issues/11823