neiam
/vigil
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
Slice 9: logs
08898fc · gmorell · 2026-12-02 03:30
Files changed
modified
ROADMAP.md
+14
−1
@@ -425,7 +425,7 @@ This is new: GlitchTip throws `check_in` items away.
| 425 | 425 | - Tested against a real HTTP server on loopback: down and back each caught on the next check, one alert per change. |
| 426 | 426 | - Not done: the list page queries per monitor (unbatched). |
| 427 | 427 | |
| 428 | −### 9. Logs · medium | |
| 428 | +### 9. Logs · medium · **done** | |
| 429 | 429 | - `log` items arrive from Python as `version: 2` and from Elixir with no version. |
| 430 | 430 | - **Storage:** flattened attributes (service, environment, host, severity) in a partitioned `log_events` table. Logs more than a day off server time are rejected. |
| 431 | 431 | - **UI:** |
@@ -434,6 +434,19 @@ This is new: GlitchTip throws `check_in` items away.
| 434 | 434 | - Search. |
| 435 | 435 | - Jumps to the trace or issue by `trace_id`. |
| 436 | 436 | - **Exit:** sentry-elixir's logger handler streams into the tail. |
| 437 | +- **As built:** | |
| 438 | + - Both SDKs send `{items: [{timestamp, level, body, trace_id, span_id, attributes: {k: {value, type}}}]}`; Python adds `version: 2`. One processor flattens attributes and lifts environment, release, service and host out of the `sentry.*`, `service.*` and `server.*` attributes. | |
| 439 | + - Lines more than a day from the server clock are dropped and counted as a new `:server` outcome (`log_item`, `timestamp`). | |
| 440 | + - `log_events` is partitioned daily (30 days), with a pg_trgm index on the body. | |
| 441 | + - Search syntax: words, `level:warn,error`, `env:`, `service:`, `host:`, `release:`, `trace:`, any `attribute.key:value`, quotes, and `-` to negate. The live tail filters new lines with the same filters. | |
| 442 | + - Page: | |
| 443 | + - a log explorer with level chips and environment/service menus that edit the query in the URL | |
| 444 | + - a per-minute volume chart | |
| 445 | + - rows that expand to all attributes, with "add as filter" | |
| 446 | + - links to the trace and the trace's issue | |
| 447 | + - a live tail with pause and "N new lines", and "load older" by cursor | |
| 448 | + - The trace page lists the trace's logs. | |
| 449 | + - Tested with the real sentry-elixir 14.1 logger handler (`config :sentry, logs: [level: :info]`) and sentry-python 3.0.2, which sends logs by default; `enable_logs` was removed in 3.x. | |
| 437 | 450 | |
| 438 | 451 | ### 10. Release health · small-medium |
| 439 | 452 | - `session` and `sessions` items roll up into per-release, per-environment, per-hour crash-free counts. |
modified
lib/vigil/logs.ex
+6
−2
@@ -82,15 +82,19 @@ defmodule Vigil.Logs do
| 82 | 82 | ~r/(-?)(?:("(?:[^"\\]|\\.)*"|[^\s:"]+):("(?:[^"\\]|\\.)*"|\S+)|("(?:[^"\\]|\\.)*"|\S+))/u |
| 83 | 83 | |> Regex.scan(q) |
| 84 | 84 | |> Enum.flat_map(fn |
| 85 | − [_, neg, key, value] when key != "" -> [term(dequote(key), dequote(value), neg == "-")] | |
| 85 | + [_, neg, key, value] when key != "" -> [term(dequote(key), value, neg == "-")] | |
| 86 | 86 | [_, neg, "", "", word] -> [{:text, dequote(word), neg == "-"}] |
| 87 | 87 | _ -> [] |
| 88 | 88 | end) |
| 89 | 89 | |> Enum.reject(&match?({:text, "", _}, &1)) |
| 90 | 90 | end |
| 91 | 91 | |
| 92 | + # A quoted value is one value; otherwise commas separate alternatives. | |
| 92 | 93 | defp term(key, value, neg?) do |
| 93 | − values = value |> String.split(",", trim: true) |> Enum.map(&String.trim/1) | |
| 94 | + values = | |
| 95 | + if String.starts_with?(value, "\""), | |
| 96 | + do: [dequote(value)], | |
| 97 | + else: value |> String.split(",", trim: true) |> Enum.map(&String.trim/1) | |
| 94 | 98 | |
| 95 | 99 | case Map.fetch(@columns, String.downcase(key)) do |
| 96 | 100 | {:ok, :level} -> {:column, :level, Enum.map(values, &normalize_level/1), neg?} |
modified
lib/vigil_web/live/log_live/index.ex
+1
−1
@@ -681,7 +681,7 @@ defmodule VigilWeb.LogLive.Index do
| 681 | 681 | phx-no-curly-interpolation |
| 682 | 682 | ><code>sentry_sdk.init( |
| 683 | 683 | dsn="…", |
| 684 | − enable_logs=True, | |
| 684 | + # 3.x sends logs by default; on 2.x add enable_logs=True | |
| 685 | 685 | ) |
| 686 | 686 | |
| 687 | 687 | sentry_sdk.logger.info("order {order_id} placed", order_id=42)</code></pre> |
modified
test/vigil/logs_test.exs
+5
−0
@@ -188,4 +188,9 @@ defmodule Vigil.LogsTest do
| 188 | 188 | refute Map.has_key?(issues, other) |
| 189 | 189 | assert Logs.trace_issues(ctx.project.id, []) == %{} |
| 190 | 190 | end |
| 191 | + | |
| 192 | + test "a quoted value with a comma is one value" do | |
| 193 | + assert [{:attr, "note", ["a, b"], false}, {:column, :level, ["warn", "error"], false}] = | |
| 194 | + Logs.parse_query(~s(note:"a, b" level:warn,error)) | |
| 195 | + end | |
| 191 | 196 | end |
Parents: 55bb308