sentry-ruby
sentry-ruby copied to clipboard
feat(monitor_check_ins): improve cron monitor slug readability with better formatting and hashing
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
HappyWorkerWithCronbecomehappyworkerwithcron(no word separation) - Very long class names like
VeryLongOuterModule::VeryVeryVeryVeryLongInnerModule::Jobare blindly truncated without leaving any trace to parent class
Solution
- Better slug formatting: Convert CamelCase to snake_case with proper word separation using regex patterns similar to Rails
parameterizeandunderscoremethods - 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
- Matching Sentry Cron monitor slug and job class name is not in the scope of this PR
- Fixing Sentry Cron monitor names is not in the scope of this PR
Changes
- Enhanced
sentry_monitor_slugmethod 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_LENGTHandSLUG_HASH_LENGTHfor better maintainability
Examples
HappyWorkerWithCron→happy_worker_with_cron(was:happyworkerwithcron)VeryLongOuterModule::VeryVeryVeryVeryLongInnerModule::Job→675905e0c9_very_very_very_long_inner_module-job(was:ongoutermodule-veryveryveryverylonginnermodule-job)
fixes: RUBY-15 fixes: #2594
Latest mainstream merged