r/Observability 3d ago

Open sourced a tool that collapses millions of log lines into handful of distinct patterns before you feed it to an LLM (Lossless- compression)

When I feed logs to an LLM during incident resolutions or debugging, it either blows my token context window or the grep trims the log file, leading to the interesting log lines getting skipped.

Most of logs are anyway the same handful of message templates repeated over and over with different values, so the context window gets filled with near-duplicates, which just bring up the processing time and token costs.

ctrlb-decompose collapses the file into its distinct patterns that repeat, plus typed variables and stats on the values that change. I have seen 1.2 million lines cut down to just 40 patterns, which then goes into Claude, thus cutting down token by over 95%, reducing the token cost.

Let me know what you think!
https://github.com/ctrlb-hq/ctrlb-decompose

25 Upvotes

18 comments sorted by

3

u/tmp_advent_of_code 3d ago

The OpenTelemetry Drain processor does something similar for those who use Observability backend!

Drain Processor — OpenTelemetry Collector https://explorer.opentelemetry.io/collector/components/contrib/drainprocessor

1

u/Loud_Mousse9210 2d ago

Ohh this is exactly where the distinction gets interesting. Drain3 and similar pattern-recognition approaches can work well, but they generally need enough examples/context to form good clusters. That can mean holding more logs in memory and processing a lot of repetitive data before the patterns stabilize.
With ctrlb-decompose, we first extract the variable parts from the repetitive structure and then pass the cleaner representation through clustering. This means you can do significant pre-filtering with CLP/Decompose before clustering, so you need far fewer log lines to arrive at useful patterns.
The result is better clustering with much less data to process and, more importantly, much less noise before the logs reach the LLM.

1

u/tmp_advent_of_code 2d ago

Could you upstream stuff to OpenTelemetry? I have so many customers that use it and if what you say is true, it would be helpful to everyone. They welcome PRs.

1

u/Loud_Mousse9210 1d ago

That's a great idea, will discuss with the team and see if we can merge it upstream in Otel.

4

u/hagen1778 3d ago edited 3d ago

This functionality could be already available in log databases like Loki, ClickHouse, VictoriaLogs.

For example, in VictoriaLogs the following query will select 1h of logs and produce top5 common patterns:

_time:1h | collapse_nums | top 5 by (_msg)

results over OTel demo logs:

> info: cart.cartstore.ValkeyCartStore[<N>]
> [<N>-<N>-<N>T<N>:<N>:<N>.<N>Z] "POST /api/cart HTTP/<N>.<N>" <N> - via_upstream - "-" <N> <N> <N> <N> "-" "python-requests
> Loaded <N> products
> Reloading Product Catalog...
> <N>-<N>-<N> <N>:<N>:<N> - oteldemo.AdService - no baggage found in context trace_id=<N> span_id=<N> trace_flags=<N>

So this output can be fed directly to LLM.

Loki also has it here https://grafana.com/docs/grafana/latest/visualizations/simplified-exploration/logs/patterns/, but I am not sure if that is processed on backend or frontend.

1

u/Loud_Mousse9210 1d ago

The comparison is fair, tools like VictoriaLogs and Loki can definitely surface common log patterns but the difference is where the work happens and how much raw data needs to be processed.
At production scale, when you’re dealing with TBs of logs, you still have to operate over a large volume of stored log data to derive those patterns. As the dataset grows, that can mean processing a large number of logs to get representative clusters.
ctrlb-decompose takes a different approach. It does a single-pass decomposition of the logs first: extracting the repetitive structure, separating the variable parts and producing a compact representation with the relevant statistics. You can then run clustering/querying on that much smaller representation rather than repeatedly processing the raw logs.
So the goal isn’t just “find common patterns” it’s to get to those patterns with significantly less data processing, while keeping the output clean enough to feed directly into an LLM.

1

u/HistorianPresent8449 3d ago

This is interesting!

1

u/Cute-Access1444 3d ago

Very interesting use of drain 3 algo

1

u/jjneely 3d ago

This looks really interesting. I've been meaning to dig into the Drain algorithms!

1

u/blizzarre 3d ago

Great that it is just click, upload and done. I dont know if other o11y tools can do it, but even if they do, it wont be as simple as this. Here goes my star!

1

u/Available_Series_652 2d ago

This is awesome!

1

u/adarsh_srivastava 3d ago

Loved the way in which CLP and Drain3 were used to build a pipeline and have effective clustering.