feat(tests): integration with Oban and Broadway#1056
Draft
solnic wants to merge 5 commits into
Draft
Conversation
Closes the gap that left buffered events (logs and metrics) emitted from processes registered via Sentry.Test.allow_sentry_reports/2 silently dropped instead of routed to the test's collector under async tests. Changes ------- * build_collecting_callback/0 becomes build_collecting_callback/1, capturing owner_pid at install time. The closure looks up owner_pid's metadata directly via NimbleOwnership.get_owned/3 rather than walking [self() | $callers] to find the owner. This pins ownership lookups to the right test instead of relying on whichever scope happens to be reachable from the calling pid. * find_collector/0 is removed (no other callers). * A small caller_allowed_for?/1 helper preserves the prior safety check by confirming the calling pid (or its $callers) is in owner_pid's allow chain. * Adds a worker→processor routing index in Sentry.Test.Registry (@processor_routing_table) with tag/lookup/drop helpers. The lookup short-circuits to nil when the table is not started so the production call path stays a single :ets.whereis/1. * Sentry.Test.allow_sentry_reports/2 writes to the routing table using the owner pid's :sentry_telemetry_processor — no metadata format change required on the NimbleOwnership side. * Sentry.TelemetryProcessor.processor_name/0 falls back to the routing table when the calling pid has no :sentry_telemetry_processor in its dictionary, so allowed workers' buffered events land in the owning test's per-test processor whose scheduler pid is in the test's allow chain. * setup_collector/1's on_exit/1 cleans up routing rows pointing at this test's processor. Async-safe under all known scenarios ------------------------------------ * async: false + buffered events from allowed pid — works. * async: true + per-test Oban/Broadway + allowed pids — each test has its own processor; routing is keyed by worker pid so two tests cannot disagree about where a given worker's events land. * async: true + shared global Oban + allowed pids — different worker pids → different routing entries → independent per-test processors. * Process spawned without allow_sentry_reports/2 — unchanged; uses the global processor. Adds two regression tests covering Sentry.Metrics.count/3 and Logger.warning/1 emitted from an allowed pid. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Introduces the mechanism that future commits will use to install per-test telemetry handlers for popular libraries (Oban, Broadway). This commit ships only the infrastructure: option parsing, a unique per-test handler ID, automatic detach on test exit, and a generic __handle_allowance_event__/4 handler that calls allow_sentry_reports/2 in response to the configured event. The internal allowance_handlers/1 dispatch is empty — any atom passed under :allowance currently raises a clear ArgumentError naming the unsupported entry. Oban and Broadway clauses land in follow-up commits. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Installs telemetry handlers that capture the test pid at Oban job insert time and route the worker's captured events back to that test on job start. The pairing makes auto-allowance safe under async: true even when multiple tests share an Oban supervisor, because every job is uniquely tied to the test that scheduled it (rather than to whichever telemetry handler happened to fire first). The tag store lives in Sentry.Test.Registry as a public ETS table (:sentry_test_oban_job_tags) alongside the existing scope-allow table. Tags are dropped on :stop/:exception and defensively on test exit so jobs that crash before completion don't leave stale entries behind. Handlers guard on `is_integer(job.id)` so synthetic jobs from inline mode or ad-hoc telemetry simulations (no persisted id) are skipped silently. The :inline / :manual Oban testing modes run jobs in the test pid anyway, so this auto-allowance is a no-op for them — it only adds capability for the production-like worker case from issue #1052. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds Broadway to the :allowance dispatch. The handler subscribes to
[:broadway, :processor, :start] and [:broadway, :batch_processor, :start],
reads the first :sentry_test_owner found in metadata.messages[*].metadata,
and calls allow_sentry_reports/2 for that test pid.
This follows the same shape Broadway documents for Ecto sandbox
testing (metadata: %{ecto_sandbox: self()}) — no wrapper around
Broadway.test_message/3, no hidden state, and async-safe by design
because each message carries its origin test pid. Messages without
:sentry_test_owner are silently skipped.
Integration coverage adds a minimal Broadway pipeline
(PhoenixApp.TestBroadway) and a 3-test broadway_test.exs in
phoenix_app proving: (1) tagged + allowance captures, (2) untagged +
allowance does not, (3) tagged + no allowance does not. async: true
on the describe block to validate cross-test isolation through a
shared pipeline.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
8d4ffae to
6fa9f76
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Streamlines test setup for popular
ObanandBroadwaylibs, so that we can have tests like this: