Skip to content

feat(rails): support for solid queue#2942

Draft
solnic wants to merge 13 commits into2933-active-job-tracing-specsfrom
2587-support-solid-queue
Draft

feat(rails): support for solid queue#2942
solnic wants to merge 13 commits into2933-active-job-tracing-specsfrom
2587-support-solid-queue

Conversation

@solnic
Copy link
Copy Markdown
Collaborator

@solnic solnic commented Apr 28, 2026

TBD

Closes #2587

@solnic solnic linked an issue Apr 28, 2026 that may be closed by this pull request
@solnic solnic force-pushed the 2587-support-solid-queue branch from ba6dae4 to 0531f06 Compare April 30, 2026 13:23
solnic and others added 13 commits May 7, 2026 12:31
Sets messaging.message.id, messaging.destination.name,
messaging.message.retry.count, and messaging.message.receive.latency
on the consumer transaction, mirroring sentry-sidekiq's middleware.

Adds an opt-in shared example that adapters can include to verify
the data fields are populated correctly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Wraps ActiveJob enqueue with a `queue.publish` child span when an
active parent transaction exists, mirroring sentry-sidekiq's client
middleware. Uses the public `around_enqueue` callback so no new
ActiveJob monkey-patching is introduced.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Mirrors the OpenTelemetry pattern (the only documented way to add
metadata to an ActiveJob payload — Rails has no public extension hook
for serialize/deserialize): prepends the existing ActiveJobExtensions
module with serialize/deserialize overrides that inject and recover
sentry-trace and baggage headers under a namespaced "_sentry" key,
wrapped in rescue blocks so a Sentry bug never breaks job execution.

Threads the deserialized headers into SentryReporter.record, which now
uses Sentry.continue_trace when present so the consumer transaction
shares the producer's trace_id and chains under the producer
queue.publish span.

Guards the around_enqueue producer-span registration against duplicate
registration (each Test::Application.define re-runs the railtie and
without idempotency this stacks dozens of nested queue.publish spans).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…er spec

The producer-span change makes ActiveStorage's internally-enqueued
AnalyzeJob emit an extra queue.publish span on the request transaction,
which the previous index-based span lookups did not anticipate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…load

When config.send_default_pii is true, the producer-side serialize
override now copies a whitelisted set of user fields (id, email,
username) into the _sentry payload block. The consumer-side
deserialize stashes them and SentryReporter.record applies them to the
new scope so that the consumer transaction (and any error event
captured during perform) carries the originating user without leaking
ip_address, segment, or other fields back into the queue.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Calls Sentry.clone_hub_to_current_thread before opening the consumer
scope when perform_now runs on a non-main thread (mirrors the
sentry-sidekiq server middleware). This ensures that worker-side state
captured during job execution lives on a thread-local hub clone and
cannot leak back into the main process hub.

Adds a behaviour-driven shared example: two concurrent jobs in
separate worker threads do not cross-pollute each other's tags, and
the calling thread's scope is unchanged after both complete.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…_tracing meta

Replaces the five individual it_behaves_like opt-ins in
test_adapter_spec.rb with one composite shared example so future AJ
adapter specs can opt in with a single line.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…data spec

Rails 6.x's ActiveSupport::Testing::TimeHelpers#travel does not accept
the with_usec: option, so it truncates Time.now to whole seconds and
the measured latency can land up to ~999ms below the travel delta. Use
a 1100ms tolerance on Rails < 7.0 and the original 50ms tolerance on
7.0+ where with_usec: true is available.

Verified against Rails 6.1, 7.1, and 8.1 via ./bin/test --version.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Opts the SolidQueue adapter spec into the distributed_tracing meta so
all five tracing examples (producer span, trace propagation, messaging
span data, user propagation, worker hub isolation) run against
:solid_queue alongside the existing :test adapter coverage.

Two SolidQueue-specific harness adjustments were needed to make this
work on the SQLite-backed test setup:

- drain only wraps in travel_to when the caller passes an explicit
  `at:`. Without this, the inner travel_to(Time.current) collides with
  the outer travel block in messaging_span_data.rb's latency assertion.

- worker_hub_isolation.rb now spawns its threads through a `worker_thread`
  harness hook (default = `Thread.new`). The :solid_queue spec overrides
  this hook to allocate an isolated SQLite shard per spawned thread via
  `connects_to(shards: ...)` + `connected_to(shard:)`. Each worker
  thread reads/writes its own SolidQueue tables, eliminating the
  SQLite3::BusyException that two concurrent perform_later/drain
  pipelines on the shared test DB would otherwise raise. The contract
  the spec enforces — concurrent jobs in different threads do not
  cross-pollute Sentry scope — holds the same way it does on :test.

Verified GREEN on Rails 6.1 (SQ skipped, :test adapter only),
7.1, and 8.1 via ./bin/test --version.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@solnic solnic force-pushed the 2587-support-solid-queue branch from 396f231 to 22e181a Compare May 7, 2026 13:58
@solnic solnic changed the base branch from master to 2933-active-job-tracing-specs May 7, 2026 13:58
@solnic solnic force-pushed the 2933-active-job-tracing-specs branch from c116ccd to cafb0e5 Compare May 8, 2026 08:40
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.

Support Solid Queue

1 participant