feat: add span_id and service_name to monitoring logs#5633
Open
Incheonkirin wants to merge 1 commit into
Open
Conversation
The monitoring data already includes `trace_id` but not `span_id` or the service name, so log records cannot be correlated to a specific span or service within a trace — users had to add these manually via `mon.log(...)`. Add `span_id` and `service_name` as preserved columns in both the default (file) monitor and the OTLP monitor, populated from the existing `trace_context` (mirroring how `trace_id` is already handled). Both values are crash-safe: `span_id` falls back to 0 when no span is active, exactly like the existing `trace_id` column. Closes bentoml#4367 Signed-off-by: Mingi Jeong <incheonkirin@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Monitoring records already include
trace_id, but notspan_idor the service name. This makes it impossible to correlate a monitoring log line to a specific span (or service) within a distributed trace without manually callingmon.log(...)in user code. Closes #4367.Changes
Add
span_idandservice_nameas preserved columns in both monitor backends, populated from the existingtrace_context— exactly howtrace_idis already handled:DefaultMonitor(monitoring/default.py) — file/JSON logsOTLPMonitor(monitoring/otlp.py) — OTLP exportBefore:
{"trace_id": "...", "request_id": "...", "timestamp": "...", "...": "..."}After:
{"trace_id": "...", "span_id": "...", "service_name": "...", "request_id": "...", "timestamp": "...", "...": "..."}Notes
span_idfalls back to0when no span is active, identical to the existingtrace_idbehavior;service_nameisNonewhen unset (same pattern asrequest_id).