agente de servidor
Ruby & Rails
La única instalación sin paso dos. El railtie añade el middleware, se suscribe a sql.active_record y envuelve las acciones de los controladores al arrancar — no hay ningún inicializador que escribir.
- paquete
sixtyen RubyGems- funciona sobre
- Ruby 2.7 o posterior. Rails 6.1+ se instala solo; para el resto basta con Rack.
- código
- sixty-sh/sixty-ruby
Cómo instalarlo
Rails installs itself — the railtie adds the middleware, subscribes to sql.active_record and wraps controllers on boot. Postgres, MySQL and MongoDB, with query plans on Postgres.
La instalación está escrita como un prompt para el agente de código que ya tienes abierto, no como una lista de tareas para ti. Es deliberado: nombra lo que tiene que ser cierto cuando la instalación esté terminada en vez de qué archivos editar, porque dónde va el código depende del framework y ponerlo en el sitio equivocado falla en silencio. Un agente puede leer tu repositorio y deducirlo; un párrafo en una página de documentación no.
El mismo texto es lo que devuelve install_sixty a través de el servidor MCP y lo que el colector sirve en /v1/setup?kind=ruby. Hay una sola copia.
la instalación de Ruby & Rails, completa
Install the sixty agent in this Ruby application so its controllers, service
objects and database queries report to sixty.
1. Add the gem to the main group of the Gemfile — not to :development and not
to :test. It runs in production; that is the entire point. It has no
dependencies of its own, so nothing else in the lockfile moves.
gem 'sixty'
Then bundle install.
2. Rails needs no further wiring. The railtie adds the middleware, subscribes
to sql.active_record and wraps controller actions on boot. Do NOT write an
initializer that calls Sixty.init — in a Rails app that is a second boot
path for the same thing.
If this is Sinatra, Hanami, a bare Rack app or a non-web process, then and
only then do it by hand: require 'sixty' and call Sixty.init at startup,
and add "use Sixty::Instrument::Rack" to config.ru.
3. Measure the layer between the controller and the database. This is the step
the install exists for: without it the feed has routes and SQL and nothing
in between, and an N+1 can be seen but not attributed to the object that
causes it. In a Rails app that object is a query object, a service object,
a serializer or a job — rarely the controller.
class OrdersQuery
include Sixty::Instrumented
end
Every public instance method of that class becomes an operation, with its
queries and rows attributed to it. Private methods and plain accessors are
skipped. Add it to the few classes that do real work per request — not to
models, and not to anything called in a tight loop.
For a class you do not own: Sixty.instrument(Stripe::Charge, :create)
For a block: Sixty.trace('nightly-reconciliation') { ... }
4. Set these environment variables wherever the application is deployed:
SIXTY_API_KEY = a secret key starting sixty_sk_ — ask me for it. Do not
invent one, and do not commit it.
SIXTY_SERVICE = my-app
SIXTY_ENDPOINT = https://ingest.sixty.sh
The release identifier is picked up automatically on Vercel, Render,
Railway, Fly, Heroku and GitHub Actions. If this deploys some other way,
set SIXTY_RELEASE to the commit SHA — without one, every measurement lands
in a single nameless bucket and no comparison can ever be made.
Constraints — correctness requirements, not style preferences:
- Do NOT change any application behaviour. This is instrumentation only: no
refactors, no reordering of business logic, no "while I was in here" fixes.
- Do NOT include Sixty::Instrumented in ActiveRecord models or in anything
called per row. A span costs a few microseconds, which is nothing next to a
request and everything next to a loop over a result set.
- Do NOT add any analytics, user id, session id, or cookie to what is
reported. The agent is deliberately anonymous and must stay that way.
- Leave the database configuration alone. pg, mysql2, trilogy and mongo are
all instrumented already; if this application reaches its database some
other way, tell me rather than wiring something up.
If this runs under Puma with workers, or under Sidekiq, note how many
processes it runs: each reports independently and the collector merges them,
which is correct, but it is worth knowing when you read the numbers.
When you are done, tell me which files you changed, so I can confirm data is
arriving.Necesita una clave secreta — empieza por sixty_sk_ y se queda en el servidor. Genera una en la página de Ajustes cuando hayas iniciado sesión.
Qué mide
| señal | unidad | qué significa |
|---|---|---|
rows | rows per call | this query returns more rows than it used to |
fanout | queries per call | this operation now issues more database calls per invocation — an N+1 |
latency | ms per call | this operation takes longer end to end than it used to |
self_latency | ms per call | the time spent in this function itself got longer — its children did not |
payload | bytes per call | the serialized result of this operation got bigger |
errors | error rate | a larger fraction of calls are throwing |
runaway | calls per minute | this operation is being called far more often than anything triggers it |
repeated_query | times per request | the identical query runs several times within one request |
overfetch | rows per call | far more rows are fetched than the code appears to use |
unbounded | rows per call | this query has no upper bound on what it can return |
recursion | levels deep | this operation calls itself, deeper than it should |
new_error | occurrences | an error that did not occur in the previous release |
missing_tenancy | — | This reads a table of per-person data without saying whose rows it wants. Unless your database is filtering it for you, everyone gets everyone else's. |
collapse | — | This is handing back roughly half the data it used to, or less. If that was not deliberate, something is filtering out rows that somebody expects to see. |
vanished | — | It was being used steadily until this release and has not been used once since. Usually the link, button, or redirect that led here stopped working. |
traffic_drop | — | This is still being used, but a fraction as often, and its share of your traffic fell too — so it is not just a quiet period. |
round_trips | round trips per read | one read now waits on the database many times instead of once |
plan | — | the database chose a different plan for this query |
Dónde se engancha
- Rails — Automático. Los controladores pasan a ser operaciones, nombradas por controlador#acción.
- Rack — use Sixty::Instrument::Rack en config.ru, para Sinatra, Hanami o una aplicación pelada.
- Tus propias clases — include Sixty::Instrumented — cada método público de instancia pasa a ser una operación. Los métodos privados y los accesores se dejan en paz.
- Cualquier otra cosa — Sixty.instrument(Stripe::Charge, :create), o Sixty.trace("job") { }.
Bases de datos
- pg — Filas, forma de la sentencia y planes de consulta vía EXPLAIN.
- mysql2 / trilogy — Leído con las reglas de comillas de MySQL, no las de Postgres — una cadena entre comillas dobles es un literal en una y un identificador en la otra.
- mongo — Que es lo que usa Mongoid. La forma del comando como identidad.
Qué hace solo este
- Nada que escribir — Rails tiene un gancho de arranque documentado y un bus de eventos que ya anuncia cada consulta, así que la gema no necesita ni inicializador ni envoltorio.
- Planes de consulta en Postgres — El mismo EXPLAIN que el agente de Node, cacheado por sentencia.
Qué no puede hacer
- Los planes de consulta son solo de Postgres. MySQL no tiene EXPLAIN de plan genérico, y MongoDB no tiene sentencia que explicar.
- La CPU y la espera no se separan.
- Bajo Puma con workers, o Sidekiq, cada proceso reporta por separado y el colector los fusiona.
Configuración
Todos los agentes leen las mismas cuatro variables, y DRIFT_* sigue respondiendo allí donde lo hace SIXTY_* — el producto se renombró y ese nombre no es nuestro para retirarlo de los despliegues de otra gente.
SIXTY_API_KEY | Sin ella el agente se queda inerte y lo dice. Nunca adivina, nunca reintenta contra un endpoint desconocido, y nunca lanza una excepción. |
|---|---|
SIXTY_SERVICE | Cómo llamar a este servicio. Por defecto, el nombre del proyecto donde sea legible. |
SIXTY_RELEASE | La que más importa. Se recoge automáticamente en Vercel, Render, Railway, Fly, Heroku y GitHub Actions; en cualquier otro sitio, ponla al SHA del commit. Sin ella cada medición cae en un único cubo sin nombre y no se puede hacer ninguna comparación. |
SIXTY_ENDPOINT | Dónde reportar. Por defecto http://localhost:4319, que es correcto en un portátil y erróneo en cuanto la aplicación se sirve a alguien más. |
El resto — intervalo de envío, tasa de muestreo, qué instrumentar — está en el propio README del paquete, que es donde puede seguir siendo cierto según cambia el agente.