Skip to content

Add Custom Events panel to the dashboard - #10

Merged
n0nag0n merged 1 commit into
masterfrom
feat/dashboard-custom-events-panel
Oct 17, 2026
Merged

n0nag0n merged 1 commit into
masterfrom
feat/dashboard-custom-events-panel

Conversation

@ambrose5773

@ambrose5773 ambrose5773 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What / why

Adds a Custom events panel to the default dashboard. It automatically lists every custom event type an app fires through apm.custom (for example docs.markdown_served), with no config. Before this, custom events were only visible inside a single request's details, or by guessing the type into the filter box.

For each type in the selected window, the panel shows:

  • the total count,
  • when it was last seen (UTC event_dt, shown with the same formatTimestamp and timezone picker as the rest of the dashboard),
  • an inline SVG sparkline of counts per bucket.

Types are sorted by count (descending, ties by name), capped at 20. Clicking a type sets the existing custom_event_type filter through the usual captureFilters() / loadData() path, so the URL becomes ?custom_event_type=<type>, just like clicking a route or an error group. When there are no events the panel says "No custom events in this window."

Query notes

  • New customEventSummary() in PresenterAbstract, returned as a new customEvents key from getDashboardData() (adding a return key is allowed per AGENTS.md). Nothing in the public API changes.
  • Both queries join apm_custom_events e to apm_requests r ON r.id = e.request_id and reuse requestConditions('r', ...). That means the time range, custom until, hide bots / is_bot, URL, route, host, user agent, error, event-data and the other request filters all apply exactly as they do on the other panels.
  • The trend uses the existing bucketSql() and intervalSeconds(), bucketed on r.request_dt, and fills empty buckets on the same grid as buildChart(). So the sparkline lines up with the latency chart.
  • There is deliberately no IN (...) list: PdoWrapper rewrites a single IN(?) and splits string params on commas.

Also fixed: LIKE filters on MySQL/MariaDB

requestConditions() used LIKE ? ESCAPE '\'. MySQL reads '\' as an escaped quote, so the url, user_agent, custom_event_type and event-value contains / starts_with / ends_with filters threw a syntax error (1064) on MySQL/MariaDB. That would also break this panel's click-through. They now use ESCAPE '!', with escapeLike() escaping !, % and _. SQLite behaviour is unchanged.

Migration notes

No migration added. The window filter goes through apm_requests.request_dt (indexed by 0006 / 0002), then into apm_custom_events on request_id. That column is indexed on SQLite (idx_apm_custom_events_request_id) and on MySQL (the foreign-key index). (event_type, request_id) is also already indexed. Upgrading only needs a deploy.

Tests

New tests/CustomEventsPanelTest.php covers:

  • empty window,
  • counts, ordering, last_seen, and that the trend sums to the count and is as long as chartData,
  • tie ordering,
  • time-range bounds (old request excluded, custom until),
  • exclude_bots, is_bot=0/1, and the url filter,
  • drill-through via custom_event_type,
  • LIKE wildcards treated literally (bot_only vs botxonly, /a_b vs /axb).

Each test runs on SQLite, and also on MySQL when APM_TEST_MYSQL_DSN, APM_TEST_MYSQL_USER and APM_TEST_MYSQL_PASSWORD are set (the database is wiped first, so use a throwaway schema).

  • PHP 8.4, SQLite: vendor/bin/phpunit --no-coverage → 18 tests, 75 assertions, 6 skipped (the MySQL data sets).
  • PHP 8.4, MariaDB 11.8 (local): 18 tests, 96 assertions, all passing. Run three times because executionOrder="random".
  • The existing 6 tests are unchanged and still pass.
  • PHP 7.4: not run, because no 7.4 binary was available on my machine. The code avoids 8.x-only syntax.
  • phpcs --standard=phpcs.xml: 0 errors or warnings in PresenterAbstract.php and the new test. The repo-wide count is unchanged apart from those files.

Click-through: headless Chrome via Playwright, against a seeded SQLite database served with php -S ... dashboard/index.php. Checked:

  • three types listed, sorted, each with a sparkline and local-format last-seen;
  • clicking search.performed sets ?custom_event_type=search.performed, fills the filter input and filters the stats (18 requests);
  • exclude_bots=1 drops the bot-only type and lowers the counts;
  • a non-matching URL filter shows the empty state;
  • no JS errors.

Screenshot (not attached): a "Custom events" card under Error groups, one row per type showing the name, sparkline, last-seen time and a count badge.

Docs

Paired docs PR: flightphp/docs#54 (EN note in content/v3/en/awesome-plugins/apm.md).

Lists each custom event type in the selected window with count, last seen
and a sparkline, sorted by count. Clicking a type sets the existing
custom_event_type filter. Uses the same request conditions and buckets as
the other panels, so time range, hide-bots and request filters apply.

Also switch LIKE filters to ESCAPE '!' so url, user_agent,
custom_event_type and event value filters work on MySQL/MariaDB.
@n0nag0n
n0nag0n merged commit ffdcb39 into master Oct 17, 2026
@n0nag0n
n0nag0n deleted the feat/dashboard-custom-events-panel branch October 17, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants