# basecamp/marginalia

Attach comments to ActiveRecord's SQL queries

Repository: https://github.com/basecamp/marginalia
Canonical: https://ross.abutalabs.com/products/marginalia
Language: Ruby
License: MIT
License Family: permissive
Last push: 2026-08-24T20:05:09+00:00

## Health v2 (maintenance only)
Score: 77/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 99, release rhythm 35, longevity 100
- inputs: {"age_days": 5288, "days_push": 9, "days_rel": null, "gap_med": null, "n_releases_24m": 0}
- flags: no_releases
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 1768, forks 148 (observed 2026-08-28T04:05:33.703358+00:00)

## What it is
A Ruby gem that appends contextual comments (application, controller, action) to ActiveRecord SQL queries. It helps trace slow queries back to the code that generated them, and its functionality is built into Rails 7+ as QueryLogs.

## Use cases
- trace slow sql queries back to rails controller actions
- annotate activerecord queries with application context
- find which endpoints generate slow database queries
- search database logs for queries by controller
- integrate query comments with pt-query-digest

## When to choose
- you run a Rails 5.2-6.1 app and need query provenance in logs or slow query analysis
- you want to identify controller/action hotspots using tools like pt-query-digest

## When to avoid
- you are on Rails 7 or newer, where query logging is built in via ActiveRecord::QueryLogs
- you do not use ActiveRecord or a supported adapter (mysql2, pg, sqlite3)

## Facets
- artifact type: library
- maturity: maintenance
- function: logging, monitoring, middleware
- domain: databases, developer-tools, web-development, performance
- platform: ruby
- tags: activerecord, rails, sql-comments, query-tracing, database-debugging, web-server

## Member repositories
- basecamp/marginalia (main) score 77

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:05:33.703358+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T03:26:08.852303+00:00, confidence not recorded.
  - readme: https://github.com/basecamp/marginalia (fetched 2026-08-28T04:05:33.703358+00:00, sha 69285f88ac79)
- Data as of 2026-08-30T08:39:29.467469+00:00.
