sentry-ruby icon indicating copy to clipboard operation
sentry-ruby copied to clipboard

feat(monitor_check_ins): improve cron monitor slug readability with better formatting and hashing

Open amkisko opened this issue 2 months ago • 1 comments

Description

This PR improves the readability of cron monitor slugs in the Sentry web UI by implementing better name formatting and intelligent truncation with hashing for long class names.

Attention: this PR introduces breaking change as slugs will be a bit different than before. According to rspec cases it affects only sentry-sidekiq.

Problem

Currently, cron monitor slugs generated from Ruby class names are hard to read in the Sentry web UI:

  • CamelCase class names like HappyWorkerWithCron become happyworkerwithcron (no word separation)
  • Very long class names like VeryLongOuterModule::VeryVeryVeryVeryLongInnerModule::Job are blindly truncated without leaving any trace to parent class

Solution

  1. Better slug formatting: Convert CamelCase to snake_case with proper word separation using regex patterns similar to Rails parameterize and underscore methods
  2. Truncation with hashing: For slugs exceeding 50 characters, implement a hash-based truncation strategy inspired by ActiveRecord migration index naming:
    • Generate a 10-character SHA256 hash of the truncated portion
    • Prepend the hash to the remaining slug portion
    • This preserves part of the class name while maintaining uniqueness
  3. Matching Sentry Cron monitor slug and job class name is not in the scope of this PR
  4. Fixing Sentry Cron monitor names is not in the scope of this PR

Changes

  • Enhanced sentry_monitor_slug method with better CamelCase to snake_case conversion
  • Added truncation logic with SHA256 hashing for long slugs
  • Updated test expectations to reflect the new formatting behavior
  • Added constants for MAX_NAME_LENGTH and SLUG_HASH_LENGTH for better maintainability

Examples

  • HappyWorkerWithCronhappy_worker_with_cron (was: happyworkerwithcron)
  • VeryLongOuterModule::VeryVeryVeryVeryLongInnerModule::Job675905e0c9_very_very_very_long_inner_module-job (was: ongoutermodule-veryveryveryverylonginnermodule-job)

fixes: RUBY-15 fixes: #2594

amkisko avatar Oct 16 '25 09:10 amkisko

Latest mainstream merged

amkisko avatar Dec 04 '25 10:12 amkisko