I am helping a team with Java applications to make the most of Grafana+Loki with OpenTelemetry.
Reviewing a sea of error logs it could be useful to highlight which ERRORs have an exception attached, since they typically carry critical information about an event. Unless the log message specifically says “I caught an exception” (redundant), it takes some work to figure that out in the UI.
I recently came across OTel’s Trace spec for Exceptions which appears to work for logs, so when an exception is logged it’ll have the attributes exception.message, exception.stacktrace, and exception.type (or rather exception_message, etc as Loki labels).
Log details could also surface exception details right under the log line?
Blue sky: going the extra mile, stacktraces can be quite long and could maybe use some specific rendering, if there’s some common formatting across languages.
Grafana 12.4 and later: OpenTelemetry log lines are detected automatically (for example by fields such as severity_number), and the exception type and message are shown inline on the log line. This was released as experimental.
Grafana 12.3 and later: the logs panel has a field selector where you can choose which fields to display. Select your exception fields (for example exception_type and exception_message, using the names shown in your log details).
To see only errors that carry an exception, add a filter to your query:
I’m not aware of a dedicated icon or stack trace rendering in Grafana today. If you’d like it, please open a feature request on the Grafana GitHub repo.
Thanks and thanks for pointing these features out!
That experimental feature in 12.4.0 release notes rings a bell, it appears to still be experimental behind flag otelLogsFormatting as of 13.2.3. This blog post has a little demo of the feature – not showcasing exceptions but looking handy!
Great timing – love the improvements already done and tracked in that epic, really need to get traces for our team at some point. Many thanks!
The proposed error/exception display is neat. One early thought was that it could identify long lists of frames in the stack and collapse them (Java stacktraces in particular can get very long) but the Python example is a good reminder stacktrace formats are language-specific.
If you mean otelLogsFormatting, would you like some feedback here? I got it enabled in 13.2.3 and noticed some things, though I’d take about a week to see how our team interacts with it. A couple early notes:
For the default fields, having thread_name first is an interesting choice. Nearly useless for our apps – I kinda wish this was configurable to put scope_name first.
The “Log Attributes” are neat inline but messy in the log details visually, and don’t really work with the search filters in said details.
One early thought was that it could identify long lists of frames in the stack and collapse them (Java stacktraces in particular can get very long) but the Python example is a good reminder stacktrace formats are language-specific.
Definitely noted.
If you mean otelLogsFormatting, would you like some feedback here?
Absolutely!
For the default fields, having thread_name first is an interesting choice. Nearly useless for our apps – I kinda wish this was configurable to put scope_name first.
You probably get always the same value for thread_name, right? Any other detail about this, or scope_name, would be very helpful to know.
The “Log Attributes” are neat inline but messy in the log details visually, and don’t really work with the search filters in said details.
100% agree. We planned to stop displaying it, as it got there as a side effect.
Thank you again, this is indeed very useful for us.
Threads: not a single name; our main use case is a webserver with a pool of request-serving threads with a prefix and randomly-numbered names like pool245765246-8507934. There are sometimes more useful names (e.g. worker for XYZ job) but which random thread happened to process something rarely has relevance, especially when distributed among many instances.
For scope.name the OTel SDK grabs the Java Logger name, usually the package/class ≈ which system/feature generated the log.
Knowing a log comes from e.g. com.company.appName.SMTPHandler is quite useful, even before looking at the message.
I guess showing either field is an attempt at categorizing where a log comes from.
Though when viewing OTel logs from multiple applications, one could want service.name to be shown first. Or service.namespace… I’m not sure what would be a good universal default for OTel logs.
Though if I was pressed, I've got an idea…
I’d want an OTel semantics expert to chime in.
To identify the log origin when looking at logs from everywhere, maybe it could show all these by default:
But if the query is filtering by any of those fields (service, or scope, or exception), then the UI doesn’t show them inline?
.
Not displaying it in the details at all?
It’s kinda useful to surface these “non-infrastructure fields” above the others, if the details UI would split them instead of duplicating them in a different panel. Though it’s probably a lot more UI work
I guess showing either field is an attempt at categorizing where a log comes from.
Correct.
I’m not sure what would be a good universal default for OTel logs
No, so we try to focus on the common denominator, and then let people customize the experience. Which, by the way, if you use Logs Drilldown, in the plugin settings you can set your default displayed fields per service/set of labels.
if the details UI would split them instead of duplicating them in a different panel.