Module: Errsight::Sidekiq

Defined in:
lib/errsight/sidekiq.rb

Overview

Sidekiq integration. Three pieces:

1. ClientMiddleware — runs on enqueue, snapshots the current scope
   (user/tags/breadcrumbs) into the job payload so the worker side can
   restore it when the job runs.
2. ServerMiddleware — runs around `perform`, rehydrates the snapshot,
   reports any exception with structured Sidekiq context, and re-raises
   so Sidekiq's retry/death machinery still fires.
3. error_handlers entry — Sidekiq's safety net for exceptions raised
   *outside* the middleware chain (fetch errors, middleware itself
   raising). Dedup-aware so middleware-captured exceptions aren't
   reported twice.

We do NOT enqueue Errsight’s HTTP delivery as Sidekiq jobs. Delivery stays on the SDK’s own background flush thread so error reporting still works when the customer’s Sidekiq is broken (Redis down, workers stuck).

Defined Under Namespace

Classes: ClientMiddleware, ServerMiddleware

Constant Summary collapse

MAX_PROPAGATED_BREADCRUMBS =

Cap propagated breadcrumbs so we don’t bloat job payloads in Redis. A job carrying 50 crumbs × 200 bytes × 1M jobs/day = 10 GB/day, which is not a cost we should silently impose on the customer’s Redis bill.

20
MAX_ARG_BYTES =

Hard cap on per-arg serialized size. Jobs occasionally carry large payloads (file blobs, base64 images) and we’d rather drop them than blow past the API’s 512KB ingestion limit.

4_096

Class Method Summary collapse

Class Method Details

.configure_integration!Object

Idempotent. Safe to call multiple times: the @configured flag and chain.exists? guards prevent double-registration if the host requires us once via Bundler and once via the Railtie.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/errsight/sidekiq.rb', line 33

def configure_integration!
  return unless defined?(::Sidekiq)
  return if @configured
  @configured = true

  ::Sidekiq.configure_server do |config|
    config.server_middleware do |chain|
      # Prepend so we wrap *all* other server middleware — exceptions
      # raised by other middleware are caught here too.
      chain.prepend(ServerMiddleware) unless chain.exists?(ServerMiddleware)
    end
    config.client_middleware do |chain|
      chain.add(ClientMiddleware) unless chain.exists?(ClientMiddleware)
    end
    register_error_handler(config)
  end

  ::Sidekiq.configure_client do |config|
    config.client_middleware do |chain|
      chain.add(ClientMiddleware) unless chain.exists?(ClientMiddleware)
    end
  end
end