Skip to content

Crons: default monitor slugs from class names should use underscore word breaks #3215

Open

Description

@amkisko

Summary

Default cron monitor slugs derived from Ruby class names should insert word breaks with underscores (Rails-style underscore), instead of lowercasing CamelCase into a single token. Long names should truncate in a stable, unique way.

For transition, support both formats via an explicit slug format selection (one active format per process). Do not dual-emit check-ins to both slugs.

Implementation PR: #2750

Motivation

Sentry::Cron::MonitorCheckIns.sentry_monitor_slug currently does:

name.gsub("::", "-").downcase

So HappyWorkerWithCron becomes happyworkerwithcron. That is hard to read in the Sentry Crons UI and differs from how Ruby/Rails usually turn constant names into identifiers.

Blind right-truncation on the 50-character limit also drops the distinctive prefix of deep namespaces.

This matters for Sidekiq scheduler jobs and any host that relies on the default slug. After #3200, Good Job cron keys often already look like snake_case keys; class-derived slugs still need the word-break fix.

A hard cutover breaks existing monitors that keyed off the mashed default. Format selection lets hosts keep legacy slugs until they migrate, then switch once.

Specification

  • Convert CamelCase / nested constants to a slug with underscore word breaks (same intent as ActiveSupport underscore), keeping :: -> - (or an equivalent separator already used by the SDK).
  • Cap length at the existing monitor slug max (50).
  • When truncation is required, keep uniqueness (hash of the dropped portion + readable tail), rather than only slicing the end.
  • Explicit sentry_monitor_check_ins(slug: ...) remains unchanged and always wins over format selection.
  • Add a slug format selection for default (derived) slugs only, for example under cron config:
    • :legacy (or :mashed) - current gsub("::", "-").downcase behavior
    • :underscore - new word-break behavior
  • Default for the new option: prefer :legacy for one release (or until the next major) so existing monitors keep working; document switching to :underscore. Alternatively default to :underscore with a clear changelog + migration note; choose one in review.
  • One format active per process. Do not send check-ins for both legacy and underscore slugs for the same job (avoids double monitor volume; see also check-in volume concerns).
  • Truncation/hashing rules apply to :underscore. :legacy keeps today's truncation unless a separate change says otherwise.

Guide-level

Class :legacy :underscore
HappyWorkerWithCron happyworkerwithcron happy_worker_with_cron
Sentry.init do |config|
  # keep existing mashed defaults during transition
  config.cron.monitor_slug_format = :legacy

  # after monitors are recreated or slug: is set explicitly
  # config.cron.monitor_slug_format = :underscore
end

Hosts that need a fixed value keep setting slug: explicitly (format selection ignored for that job).

Drawbacks / alternatives

  • Adopt with format selection: small config surface; hosts choose cutover time; one monitor slug per job.
  • Dual-emit both slugs: rejected. Doubles check-in volume and splits success/failure across two monitors.
  • Hard cutover only + slug: escape hatch: workable but forces every default-slug host to act immediately.

Prior art

Unresolved questions

  • Default for monitor_slug_format: :legacy for a transition release, or :underscore immediately with changelog?
  • Exact option name and home: config.cron.monitor_slug_format vs something shorter?
  • Should Sentry::Cron::Slug.from and sentry_monitor_slug share one helper after feat(jobs): support for good job cron check-ins #3200, or only change the mixin path in this issue's PR?
  • Is Sidekiq-only impact in current specs acceptable as the documented break surface when default becomes :underscore?

References

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions