8000 fix(mlog): give an exported log record with no message a body from its span and error by bryan-minimal · Pull Request #3540 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content

fix(mlog): give an exported log record with no message a body from its span and error - #3540

Merged
bryan-minimal merged 6 commits into
mainfrom
fix/error-logs-carry-a-message
Nov 23, 2026
Merged

bryan-minimal merged 6 commits into
mainfrom
fix/error-logs-carry-a-message

Conversation

@bryan-minimal
@bryan-minimal bryan-minimal commented Nov 18, 2026 •
Copy link
Copy Markdown
Member

What

An exported log record that has an error field and no message now gets a body: <module>::<span name> failed: <error>, or <module>: <error> when there is no span.

Refs #3223

Why

#[tracing::instrument(err)] logs a failure as an event whose only field is error. The OTel bridge exported it with an empty body. A search of log bodies never found these records, and a table of messages showed a blank line for each. In a week of telemetry they were a visible share of the ERROR records.

How

The log export layer wraps the bridge. For an event with an error field and no message field, it notes the module and the span the event came from. A processor that runs first on the logger then writes the body.

What does not change

  • A record that has a message is left as it was.
  • A record with no error field is left as it was.
  • The error attribute is kept.
  • Terminal and file logs are unchanged.
  • Nothing runs when telemetry is off.

The rule applies at any level, not only ERROR.

Testing

  • an_instrumented_failure_gets_a_body_from_its_span_and_error
  • a_message_or_a_missing_error_is_left_alone

Workspace lint, tests and the native end-to-end script pass on this commit.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Error log entries that lack a message now display a readable description based on the error, including the event target and, when available, the relevant span name.
    • Existing messages remain unchanged, and entries without a string error are not modified.

…s span and error

`#[tracing::instrument(err)]` logs a failure as an event whose only field is
`error`, so the OTel bridge exported it with an empty body: a search of log
bodies never found it and a table of messages showed a blank line.

The log export layer now wraps the bridge. For an event with an `error`
field and no `message` field it notes the module and span the event came
from, and a processor that runs first on the logger gives the record the body
`<module>::<span name> failed: <error>`, or `<module>: <error>` with no span.
The rule applies at any level. A record that has a message, or has no
`error` field, is left as it was, and the `error` attribute is kept.
Terminal and file logs are unchanged, and nothing runs when telemetry is off.

Refs #3223

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bryan-minimal
bryan-minimal requested a review from a team as a code owner November 18, 2026 17:02
@coderabbitai
coderabbitai Bot commented Nov 18, 2026 •
Copy link
Copy Markdown
8000
Contributor

Explain Change →

Warning

Review limit reached

  • Run on-demand review

This review includes 3 billable files and costs up to $0.75.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 59 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 9d2aac74-6129-4b10-99e2-63e6398254d8
Commits

Reviewing files that changed from the base of the PR and between 0597669 and e3813cc.

Files selected for processing: 3

  • crates/mlog/src/otel.rs
  • crates/mlog/src/otel/body.rs
  • crates/mlog/tests/otel_requirements.rs

No actionable comments were generated in the recent review.

Walkthrough

The OpenTelemetry logging layer captures context for error events without a message. A log processor fills an empty body with the event target, an eligible span name, and the error. Unit and integration tests cover span selection, body formatting, and records that remain unchanged.

Changes: Error event body generation

Layer / File(s) Summary
Capture error-event context
crates/mlog/src/otel/body.rs, crates/mlog/src/otel.rs
BodyFromError marks events with an error field and no message. It records the event target and an eligible span name, then forwards the event to the OpenTelemetry bridge.
Fill empty log bodies
crates/mlog/src/otel/body.rs, crates/mlog/src/otel.rs, crates/mlog/tests/otel_requirements.rs
FillBody formats marked records that have no body and a string error attribute. The logger provider installs it before other log processors. Tests cover contextual and explicit parents, hidden spans, and unchanged records.

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

Sequence Diagram(s)

sequenceDiagram
  participant TracingEvent
  participant BodyFromError
  participant OpenTelemetryTracingBridge
  participant FillBody
  participant Export
  TracingEvent->>BodyFromError: Provide error event and span context
  BodyFromError->>OpenTelemetryTracingBridge: Forward event and mark eligible context
  OpenTelemetryTracingBridge->>FillBody: Produce log record
  FillBody->>Export: Pass record with filled body
Loading

Suggested reviewers: norrietaylor, mitodrummer

Merge Risk: Minimal · previous review 05976

This change fills empty log bodies for error events with a readable message built from the error and, where available, the span name. Records that already have a message or no error field are unchanged. The change is limited to exported telemetry log text and is well covered by tests, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title follows Conventional Commit form (fix(mlog): ...) and names the main change: exported log records with no message get a body from their span and error. It matches the changeset, which adds B…
Description check Passed The description covers the What, Why, How, and Testing sections, and it explains the behavior and the unchanged cases. It does not use the template's Checklist section, and it does not include a Docs-…
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.
Full details: Title check

Explanation

The title follows Conventional Commit form (fix(mlog): ...) and names the main change: exported log records with no message get a body from their span and error. It matches the changeset, which adds BodyFromError and FillBody to fill empty bodies. The title is 85 characters, slightly long, but it is specific and accurate.

Full details: Description check

Explanation

The description covers the What, Why, How, and Testing sections, and it explains the behavior and the unchanged cases. It does not use the template's Checklist section, and it does not include a Docs-updated checkbox or a BREAKING CHANGE statement. The Testing section lists test names and says lint, tests, and the end-to-end script pass, but it does not paste output as the template asks. It also has no explicit 'Closes' or 'Refs' line beyond 'Refs #3223', which is present. Overall the description is mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit marks an error’s trail,
Then fills the log where words grew pale.
A span may join the target’s name,
While messages stay the same.
The tests hop through each parent’s view,
And leave untouched records too.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: a2eb3b3d-7f38-4e49-8dc9-7428dd2fade7
Commits

Reviewing files that changed from the base of the PR and between 8b0aa05 and 0597669.

Files selected for processing: 2

  • crates/mlog/src/otel/body.rs
  • crates/mlog/tests/otel_requirements.rs
Files skipped from review as they are similar to previous changes: 1

  • crates/mlog/src/otel/body.rs

Included review availability: This review used your included allowance. 1 included review remains after this review. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

@minimal-foundry
minimal-foundry Bot commented Nov 18, 2026 •
Copy link
Copy Markdown
Contributor

Reviewed: no findings; approval withheld, 3 threads unresolved at e3813cc778aa.

APPROVE withheld: 3 unresolved threads — norrietaylor crates/mlog/src/otel/body.rs, norrietaylor crates/mlog/src/otel.rs:1246, norrietaylor crates/mlog/src/otel/body.rs. Resolving the last thread releases the approval on this head.

Resolve the open threads. Resolving the last one releases the approval on this head; no new review is required.

Clobber: none seen.

@minimal-foundry minimal-foundry 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.

minimal-review — approved

Verdict APPROVE — No findings.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

@minimal-foundry minimal-foundry Bot added the review:approved minimal-review approved the current head label Nov 18, 2026
@norrietaylor norrietaylor left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The approach is sound. The thread-local handoff from BodyFromError to FillBody is synchronous on the emitting thread, and Reset clears it even on a panic. Records that have a message, or no error field, are left alone, and FillBody returns false from event_enabled, so no record is created only because of it. I found one issue. The span name comes from the per-layer-filtered context. When an #[instrument(level = "debug", err)] span is filtered out of export (the default filter is info), the body names an enclosing span from the caller, or no span at all. Several functions in the tree hit this path. Details and a fix are inline.


Generated by Claude Code

Comment thread crates/mlog/src/otel/body.rs Outdated
}
put(Some((
metadata.target(),
ctx.event_span(event).map(|s| s.name()),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Medium: the body can name the wrong span when the failing function's span is filtered out of export.

BodyFromError runs inside Filtered<_, ExportFilter<S>, S>, so the ctx it gets carries the export filter's id. Context::event_span on a contextual event calls lookup_current(). For a per-layer-filtered context, that skips spans the filter disabled and returns the nearest enabled ancestor, or None. The err event of #[instrument] is ERROR by default whatever the span's level, so here is the failure path:

  • #[tracing::instrument(level = "debug", skip_all, err(Debug))] in crates/graph/src/loader.rs:45 (also :59, graph/src/wire.rs:248, diagnostics/src/procs.rs:149,180), with the default MINIMAL_OTEL_FILTER=info.
  • The debug span is disabled for the export filter. The ERROR event passes.
  • event_span returns the enclosing INFO span (say materialize from another module). The exported body is graph::loader::materialize failed: <error>. That pairs the loader's module with a caller's span and says the caller failed. With no enabled ancestor, it falls back to graph::loader: <error>, which loses the function name.

The tests don't catch this because exported() builds the stack without the Filtered wrapper that log_layer adds.

Suggested fix: take the span name from the unfiltered current span. For a contextual event, use ctx.current_span().metadata().map(|m| m.name()); Current comes from the subscriber and ignores the per-layer filter. Keep event_span only for an explicit parent:, or drop the name in that case. Then add a test that wraps BodyFromError(bridge) in .with_filter(LevelFilter::INFO) and calls a level = "debug" err function inside an info_span!.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right about the mechanism, thanks. 8b0aa05 takes the name from the subscriber's current span in place of event_span, and names a span only when it has the event's target, which is what #[instrument] gives a function and its own err event. One thing differs from the example: with the default RUST_LOG=info no layer admits debug, so the debug span is never created and the current span really is the caller's; the target check is what stops a caller from another module being named there, and the body then reads <module>: <error>. An explicit parent the filter hides names nothing. One case is left as it was: a debug-level function called from an info span in the same module still gets the caller's name, because nothing records the function's own name then; closing it needs another body format (file and line), which I have kept out of this PR. The tests now run behind .with_filter(LevelFilter::INFO), with and without a layer that admits debug: two new ones fail on the old head, two are controls.

bryan-minimal and others added 2 commits November 19, 2026 08:54
…t filter hides it

`BodyFromError` sits behind the export filter, so the context it is given
looks spans up through that filter. `event_span` on a contextual event skips
a span the filter hides and returns the nearest ancestor it admits. The
`err` event of `#[instrument(level = "debug", err)]` is ERROR and exported
under the default `info` filter while its span is hidden, so the body named
a caller's span ("<module>::<caller> failed"), or no span at all.

A contextual event now takes the subscriber's current span, which per-layer
filters do not touch. An explicit parent is still looked up through the
filter and names nothing when hidden. When the function's span was never
created (no layer admits debug) the current span is a caller's, so a span
whose target differs from the event's is not named: the body is then
"<module>: <error>". `#[instrument]` gives its span and its event the same
target. The tests now build the stack behind a per-layer filter, as
`log_layer` does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A `Filtered` layer is typed by the subscriber it sits on, so one value
could not be stacked on both the plain registry and the registry with the
extra debug layer. Each branch now applies the filter itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@minimal-foundry minimal-foundry Bot 8000 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.

minimal-review — approval withheld

Verdict COMMENT — APPROVE withheld: 1 unresolved thread — norrietaylor crates/mlog/src/otel/body.rs. No findings.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

@minimal-foundry minimal-foundry Bot removed the review:approved minimal-review approved the current head label Nov 19, 2026
@norrietaylor norrietaylor left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Scope matches the title. The diff adds crates/mlog/src/otel/body.rs and three small hunks in crates/mlog/src/otel.rs. No dependency or lockfile moved.

Clobber none. git log on crates/mlog/src/otel.rs shows no recent fix that this diff reverts.

Correctness I read the vendored bridge, SDK logger and tracing-subscriber context sources. The bridge emits on the calling thread, and the SDK runs the processors in order, so FillBody sees PENDING and later processors see the body. SdkLogger::event_enabled uses any, so FillBody returning false does not create or suppress a record. Context::current_span ignores the per-layer filter, and Context::span applies it, as the comment says. #[instrument(err)] records error through record_debug, so the attribute is a string named error. I found no hand-written event in crates/ that has an error field and no message, so the rule reaches only #[instrument(err)] events today. A later hand-written event of that shape inside a span of the same target gets the word failed in its body. The spool and forward processors print the body and do not redact attributes, so the body exposes nothing that the error attribute did not already expose.

The same-module caller case in the existing thread has a reply, and I did not raise it again.

Not checked I did not compile or run the tests. The secret and dependency scanners did not run, because the harness denied compound shell commands. The diff has no credential-shaped string on a manual read. The CLI version in agent.version is not known to me.

Comment thread crates/mlog/src/otel.rs
// First, so every later processor sees the body it fills in.
let mut b = SdkLoggerProvider::builder()
.with_resource(resource)
.with_log_processor(body::FillBody);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

low · No test covers the production wiring of this fix. The tests in otel/body.rs build their own provider and layer by hand in exported_with. Remove .with_log_processor(body::FillBody) here, or the BodyFromError(...) wrap in log_layer, and every test still passes while exported records lose the body again. The two halves work only together, and only init and log_layer join them. crates/mlog/tests/otel_requirements.rs already has installed(), which runs mlog::otel::init and log_layer, and it reads body.stringValue from the spool. Add one case there that calls a failing #[tracing::instrument(err)] function and asserts the spooled body. I did not find another place with this gap: these are the only non-test builder and bridge sites.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right, either half could go and nothing failed. 0597669 adds an_instrumented_failure_is_spooled_with_a_body to otel_requirements.rs: a child process under installed() calls a failing #[tracing::instrument(err)] function, and the parent asserts that exactly one spooled record carries the error and that its body is <target>::fails_to_write failed: disk full. Without the FillBody processor in init, or without the BodyFromError wrap in log_layer, the record is spooled with no body and the assertion fails.

Comment thread crates/mlog/src/otel/body.rs Outdated
//! logger's first processor, then gives the record the body
//! `<target>::<span name> failed: <error>`, or `<target>: <error>` when there
//! is no span or the span is from another target. The span is the one the
//! event was emitted in even when the export filter hides it. The rule
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit · The module doc says the span is the one the event was emitted in even when the export filter hides it. That is true only for a contextual event whose span exists in the registry. An explicit parent that the filter hides names no span, as the comment in on_event and the test an_explicit_parent_is_named_only_when_admitted state. A span from the same target that is the caller's is also named. State the two exceptions here, or shorten the sentence to the contextual case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, the sentence claimed more than the code does. 0597669 states the cases in the module doc: a contextual event names the current span, also one the export filter hides, provided some layer admitted it; when none did, a span the caller entered is named if it has the event's target; an explicit parent is named only when the export filter admits it.

bryan-minimal and others added 2 commits November 21, 2026 21:35
…_layer

The body tests build their own provider and layer, so they pass with either half of the
production wiring removed. This case runs a failing `#[instrument(err)]` function under the
stack `init` and `log_layer` build and asserts the spooled body; it fails without the
`BodyFromError` wrap in `log_layer` or without the `FillBody` processor in `init`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A contextual event names the subscriber's current span, which is the caller's when no layer
created the function's own span; it is named if it has the event's target. An explicit parent
is named only when the export filter admits it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@minimal-foundry minimal-foundry 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.

minimal-review — approval withheld

Verdict COMMENT — APPROVE withheld: 3 unresolved threads — norrietaylor crates/mlog/src/otel/body.rs, norrietaylor crates/mlog/src/otel.rs:1246, norrietaylor crates/mlog/src/otel/body.rs. No findings.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

@bryan-minimal
bryan-minimal added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit 6b2a17d Nov 23, 2026
39 checks passed
@bryan-minimal
bryan-minimal deleted the fix/error-logs-carry-a-message branch November 23, 2026 02:09
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

0