$ show getsentry/sentry-ruby
The sentry-ruby repository is the official SDK for Ruby, designed for error tracking, performance monitoring, and distributed tracing. It functions as an instrumentation layer that captures exceptions, transactions, logs, and metrics from Ruby applications and transmits them to the Sentry backend. The architecture follows a Hub/Scope/Client pattern, ensuring thread and fiber isolation for context management across concurrent requests. It supports a wide range of integrations including Rails, Sidekiq, Resque, and OpenTelemetry, making it a central piece of observability infrastructure for the Ruby ecosystem. The SDK manages the full lifecycle of telemetry data, from capture to transport. It implements sophisticated sampling logic to maintain consistent sampling rates across distributed services using deterministic algorithms. The transport layer handles rate limiting, compression, and envelope serialization, ensuring efficient communication with the Sentry server. The codebase is structured as a monorepo with a core gem (sentry-ruby) and modular integrations (sentry-rails, sentry-sidekiq, etc.), allowing for targeted updates and version compatibility testing across multiple Ruby and framework versions. Data flows from the application through the SDK's Scope and Client, where events are processed, sampled, and buffered before being sent via HTTP or Spotlight. The system supports structured logging and metrics collection, adhering to the Sentry Logs Protocol. It includes robust testing infrastructure with matrix testing across Ruby versions (2.7-4.0) and framework versions (Rails 5.2-8.1.3), ensuring stability and compatibility. The SDK is actively maintained with recent commits and issue triage, reflecting its critical role in production environments.
The LLM identified 3 files worth highlighting for reuse:
Implements the core network communication layer for the SDK. It handles HTTP request construction, gzip compression, rate limit parsing (x-sentry-rate-limits), and envelope serialization. This component demonstrates high craftsmanship in managing backpressure and ensuring reliable delivery of telemetry data under varying network conditions.
Manages the context (tags, user, breadcrumbs, attachments) for events. It implements thread-local and Fiber-local storage to prevent cross-request contamination in concurrent environments. The component demonstrates robust state management patterns essential for safe usage in web servers and background job processors.
Implements deterministic sampling logic based on trace_id and sample_rate to ensure consistent sampling rates across distributed services. This non-obvious skill ensures that a trace sampled in one service is consistently sampled in downstream services, a critical requirement for accurate distributed tracing.