r/devops • • 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:

  1. Pull error logs from Loki
  2. Group them by a fingerprint of the normalized message (IDs, numbers and quoted values replaced by placeholders), so one bug = one group
  3. Take the trace_id that OTel puts on the log and fetch the trace from Tempo
  4. Condense the OTLP JSON into a short summary: spans in order, failed spans marked, exception messages, only the useful attributes
  5. Open one issue per group with count, first/last seen and that trace summary
  6. 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.

14 Upvotes

19 comments sorted by

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.

1

u/CelebrationShot6145 9d ago

Thanks, this is really useful. Both “no” answers change my design: I’ll show how many occurrences actually had a trace, and keep the values the normalization replaces (e.g. the list of distinct user IDs) so the grouping doesn’t hide context. And your trust ladder is a good frame: suggest-only, never remediate, and only consider more once the first-fix rate is high.

1

u/MongooseWonderful198 9d ago

In that coverage count, separate “log has a trace ID” from “we retrieved the trace.” OTel assigns IDs even to non-recording spans, so the ID alone doesn’t mean Tempo has the trace. Keep “not found” and “lookup failed” visible in the summary, so neither gets read as “no failing spans.”

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

1

u/CelebrationShot6145 9d ago

fair point on grouping, I’ll stop treating it as the core. one thing I’m unsure about: if the fingerprint includes the failing span, the same bug with and without a trace_id would split into two groups, and not every log has one. so I’m leaning towards service + normalized message as the base and top frame only when the log has a stack. does that match what you’ve seen, or do you key on something else?

also curious about the trace summary: besides failed spans and the exception, what else would you want in it when you’re on call? slowest span? the DB statement?

1

u/Starks1293 9d ago

yea that matches, key on what every log has. one catch tho, adding the frame only when theres a stack can still split, the same error with a stack and without one land in two groups. id keep the frame out of the key and store it on the group instead, then split a group later only if one message turns out to hide two different frames

for the summary, on call id want the first span that failed (not the last one, the cascade after it is mostly noise), total duration vs what it normally takes, the slowest span, and the db statement or http call of the failing span with the values stripped. plus the version or deploy the service was on, that one answers half the questions by itself

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.

1

u/CelebrationShot6145 9d ago

I have the same pain point. My main client has a dedicated machine for ingestion, which is obviously better than running the systems and ingestion on the same machine. But the systems are growing every day.

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

1

u/CelebrationShot6145 9d ago

I really like the suggestion to show which spans and logs the agent used to propose a fix, since it makes reviewing much easier

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.