Skip to content

Conversation

amkisko
Copy link

@amkisko amkisko commented Oct 16, 2025

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)

Added a new SLUG_HASH_LENGTH constant and updated the slug generation logic to truncate long slugs from the beginning and append a hash for uniqueness. Updated tests to reflect the new slug format.
…tion

Introduced a new MAX_NAME_LENGTH constant set to 128 to enforce length validation for names in the MonitorCheckIns module.
cursor[bot]

This comment was marked as outdated.

Updated the slug length calculation to correctly account for the additional character when generating slugs, ensuring proper truncation and uniqueness in the MonitorCheckIns module.
@amkisko amkisko mentioned this pull request Oct 16, 2025
@sentry_monitor_slug ||= begin
slug = name.gsub("::", "-").downcase
slug[-MAX_SLUG_LENGTH..-1] || slug
slug = name.gsub("::", "-").gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of 'A'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant