r/devops • u/CelebrationShot6145 • 9d ago
Discussion Is anyone grouping error logs by trace instead of by message? Looking for opinions on an idea
Not selling anything and no link here, I’m just looking for opinions before I go further.
First question: does Sentry, Datadog or a Grafana alert already cover this well enough that I’m reinventing the wheel? If so, tell me what it does better and I’ll stop.
The problem: in my setup, an error shows up as thousands of log lines that are really a handful of distinct bugs. Finding the cause means grouping them, then opening the trace for one occurrence and reading a very large OTLP JSON.
The idea:
- Pull error logs from Loki
- Group them by a fingerprint of the normalized message (IDs, numbers and quoted values replaced by placeholders), so one bug = one group
- Take the
trace_idthat OTel puts on the log and fetch the trace from Tempo - Condense the OTLP JSON into a short summary: spans in order, failed spans marked, exception messages, only the useful attributes
- Open one issue per group with count, first/last seen and that trace summary
- Later: have an agent read the group and trace summary and suggest a fix
It’s early and only partly built. Not done yet: avoiding duplicate issues across runs, redacting sensitive data, and the fix agent.
Other things I’d like to know:
- Do your logs reliably carry
trace_id/span_id? The whole approach depends on it. - Is grouping by normalized message good enough, or would you group by exception type, stack or failing span?
- If an agent suggested fixes from a trace summary, what would you need to see before trusting it?
Happy to share the repo if anyone is curious.
3
u/gabeech 9d ago
> Do your logs reliably carry trace_id/span_id
No.
For various reasons from cost management, to untraced sections of code, to pre-otel implementation code that hasn’t been updated yet. There ante many reason that outside of our critical path logs are not garunteed to have span/trace ids.
> Is grouping by normalized message good enough
No .
I’ve been on enough goose chases due to the normalization stripping critical data or context, I only find them useful as an initial indicator.
> If an agent suggested fixes from a trace summary, what would you need to see before trusting it?
Define trust? Trust it enough to have that be the first thing I look at? Not much that’s a pretty low bar.
Trust it enough to self remediate in dev? High 1st time fix rate, low oops that didn’t work let me try something else rate.
Trust it to remediate in prod? lol no.
2
u/Starks1293 9d ago
honest answer, the grouping half mostly exists already. sentry and datadog error tracking both group by a fingerprint and link the trace for an occurrence, and if ur already on loki, grafana's logs drilldown has a patterns view that does the normalize and group thing for you out of the box. so i wouldnt build that bit
the part that is genuinely useful is the condensed trace. nobody wants to read raw OTLP json, and a short "spans in order, failed ones marked, the exception, the 5 attributes that matter" is exactly what u want to hand an agent or a tired on call person
two tips if u keep going. dont fingerprint on message alone, add service and the top stack frame or the failing span name, otherwise one bug with variable text splits and two different bugs with the same text merge. and for the duplicate issues, make the fingerprint the issue key and update count and last seen on the existing one instead of opening a new one each run
2
u/taco__hunter 9d ago
I've been working on log tracing like this but my clients don't have unlimited resources and often single on-prem server deployment for everything all on one machine. The ingestion pressure and channels to limit competition for resources on a shared box has been the absolute hardest part of this. The traces get big and this pressure just grows. It has been much easier to build this out when I started with that constraint and then working up to full tracing. Just wanted to share this approach and insight. Also, DuckDB used as a place to store back pressure and to survive shutdowns has been crazy useful. I can run DuckDB as standalone or on the API/API Gateway directly which has been my main answer to the back pressure.
2
u/NoDevelopment206 9d ago
i would group by exception type plus the top stack frame or failing span name instead of the message text, those stay stable even when the wording changes. message fingerprints are fine as a fallback for logs with no trace. for the fix suggestions i would want it to show which spans and log lines it based the guess on, so i can check it in a minute instead of trusting it
2
u/AleDev99 9d ago
one thing I'd sort out before the agent part is redaction, because the condensed trace summary is exactly the thing that ends up pasted into an issue tracker more people can read than your logs. span attributes are where the nasty stuff lives: db.statement with literal values, http.url with tokens in the query string, auth headers if someone turned on header capture. I'd do an allowlist of attributes per span kind and drop everything else, rather than trying to regex secrets out.
second is sampling. if Tempo only keeps a slice of traces, plenty of groups will have log lines whose trace was never stored, so pick the representative trace from the ones you can actually fetch and show something like "3 of 1,200 events had a retrievable trace" so people know how thin the evidence is.
for trusting a suggested fix I'd want a failing test that reproduces the error from the trace, then the diff that makes it pass. without the repro it's a guess with nice formatting.
1
u/Muted_Jellyfish_6784 8d ago
Sentry already fingerprints errors by normalized message and stack, and Datadog and Grafana have log pattern grouping, so plain grouping is covered. Where they get weaker is linking a fingerprint group to the trace and the upstream span that actually caused it, especially when the error surfaces in a different service than the one that failed. If your tool shows the root span per group, that is the part worth building.
A good test is whether two groups that share a root cause collapse into one. We run a decision intelligence platform that joins error groups to deploys and the tickets they created, so a spike reads as one bad release rather than six unrelated alerts
1
u/tanyadev4827 8d ago
Most tools fingerprint on message text, so one root cause shows up as five separate groups when the string varies slightly. Anchoring on a trace instead lets you see which span was unhealthy, not just which string fired. Worth knowing whether Tempo's query API makes that join fast enough before you build much around it.