Skip to content

feat(instrument): per-instance log messages via message = dynamic#3705

Merged
chet merged 1 commit into
NVIDIA:mainfrom
chet:instrument-dynamic-message
Jul 19, 2026
Merged

feat(instrument): per-instance log messages via message = dynamic#3705
chet merged 1 commit into
NVIDIA:mainfrom
chet:instrument-dynamic-message

Conversation

@chet

@chet chet commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Event's log message has been a single static string. message = dynamic lets an event pick its message per instance: declare it instead of a literal message, implement the new DynamicMessage trait, and the derive routes Event::message() through it, typically a match on a #[label] enum. Level and message stay independent axes.

That lets an event that today keeps a separate tracing:: line per outcome (purely to preserve per-variant wording) fold that line into the emit(), so the metric and its message are one declaration.

  • DynamicMessage trait plus the message = dynamic value; a message that is neither a string literal nor dynamic is a compile error.
  • The check-metric-docs gate learns the ident form, so a metric-backed event can use message = dynamic without tripping the catalogue parser.

Guide docs are in a separate PR (#3707).

Part of the instrumentation-coherency initiative (#3169). Enables the folded metric+log form for outcome-enum events like the /metrics scrape-failure meta-metric (#3546, contributor PR #3686).

@chet
chet requested review from a team and polarweasel as code owners July 18, 2026 07:43
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The event derive macro now supports static, dynamic, and absent messages. A public DynamicMessage trait supplies per-instance text, while metric documentation parsing accepts message = dynamic and tests cover runtime selection, validation, and collection.

Changes

Dynamic event messages

Layer / File(s) Summary
Message specification and generated dispatch
crates/instrument-macros/src/lib.rs
The derive macro represents absent, static, and dynamic messages, validates invalid forms, and generates Event::message() accordingly.
Runtime trait and event behavior
crates/instrument/src/lib.rs
A public DynamicMessage trait is added, with tests verifying per-instance message selection independently from dynamic log-level selection.
Metric attribute collection
crates/xtask/src/metric_docs.rs
Metric parsing accepts string literals and dynamic, with coverage confirming dynamic-message events are collected using their metric name.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant EventDeclaration as Event declaration
  participant EventDerive as Event derive macro
  participant GeneratedEvent as Generated Event
  participant DynamicMessage as DynamicMessage implementation
  EventDeclaration->>EventDerive: declare message = dynamic
  EventDerive->>GeneratedEvent: generate Event::message()
  GeneratedEvent->>DynamicMessage: call message()
  DynamicMessage-->>GeneratedEvent: return per-instance message
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately captures the main change: per-instance log messages via message = dynamic.
Description check ✅ Passed The description is clearly related to the implemented dynamic message API, derive behavior, and metric-docs parsing changes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@chet

chet commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review

@github-actions

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

@chet, I’ll perform a complete review of the pull request, including the dynamic-message API, derive behavior, documentation, and metric-doc validation changes.

✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
crates/instrument/src/lib.rs (1)

574-596: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use one table for outcome-to-message and outcome-to-level expectations.

The test maps the same input enum to two outputs; table-driven cases keep variant coverage and expectations together.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/instrument/src/lib.rs` around lines 574 - 596, Refactor
dynamic_message_selects_wording_per_variant to use one table-driven set of cases
containing each Outcome variant, its expected message, and its expected LogAt
value. Iterate over the table and perform both Event::message and Event::log_at
assertions per case, keeping coverage and expectations together.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/xtask/src/metric_docs.rs`:
- Around line 255-264: Update the message attribute parsing branch in the metric
documentation gate to accept string literals or only the identifier dynamic;
reject any other identifier with a parse error, matching the validation in the
instrument macro implementation. Add a negative parser test covering message =
bogus.

---

Nitpick comments:
In `@crates/instrument/src/lib.rs`:
- Around line 574-596: Refactor dynamic_message_selects_wording_per_variant to
use one table-driven set of cases containing each Outcome variant, its expected
message, and its expected LogAt value. Iterate over the table and perform both
Event::message and Event::log_at assertions per case, keeping coverage and
expectations together.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 095f6cf0-a1ef-4b0a-87b3-171228140314

📥 Commits

Reviewing files that changed from the base of the PR and between d538254 and f9b53d5.

📒 Files selected for processing (4)
  • crates/instrument-macros/src/lib.rs
  • crates/instrument/src/lib.rs
  • crates/xtask/src/metric_docs.rs
  • docs/observability/instrumentation.md

Comment thread crates/xtask/src/metric_docs.rs
An `Event`'s log `message` has been a single static string, even when the event's outcome is a `#[label]` enum whose variants deserve distinct wording. The new `message = dynamic` knob lifts that: declare it in place of a literal `message`, implement the new `DynamicMessage` trait, and the derive routes `Event::message()` through it so each instance picks its own `&'static str` -- typically by matching on a label enum. Level and message are independent axes: an event can pair a dynamic level with a static message, a static level with dynamic wording, or both.

This closes a gap for events that keep a separate `tracing::` line per outcome purely to preserve per-variant wording. With `message = dynamic` that line folds into the `emit()`, keeping the metric and its message a single declaration.

- Adds the `DynamicMessage` trait and the `message = dynamic` value; the derive routes `Event::message()` to the impl, and otherwise emits the static string (or an empty default). A `message` that is neither a string literal nor `dynamic` is a compile error.
- Teaches the `check-metric-docs` gate the ident form, so a metric-backed event can declare `message = dynamic` without tripping the catalogue parser.

Tests: `DynamicMessage` routing selects per-variant wording independently of the level; the derive rejects a non-string, non-`dynamic` `message`; the docs gate collects a `message = dynamic` counter.
Signed-off-by: Chet Nichols III <chetn@nvidia.com>
@chet
chet merged commit 253274d into NVIDIA:main Jul 19, 2026
62 checks passed
@chet
chet deleted the instrument-dynamic-message branch July 20, 2026 19:19
chet added a commit to chet/bare-metal-manager-core that referenced this pull request Jul 23, 2026
…n guide

Add a `message = dynamic` entry to the instrumentation guide, next to the existing `log = dynamic` section: declare it, implement `DynamicMessage`, and the derive routes `Event::message()` through it. Includes the guidance to prefer a static `message` plus a label where the label already names the case, and to use `message = dynamic` only where the wording says something the label does not.

Documents the framework capability added in NVIDIA#3705; kept as its own PR so the code and docs can land on independent timelines.

Signed-off-by: Chet Nichols III <chetn@nvidia.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.

2 participants