Skip to content

Add Sentry::DebugTransport for testing/debugging #2664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 31, 2025
Merged

Conversation

solnic
Copy link
Collaborator

@solnic solnic commented Jul 28, 2025

Long story short: I think this is something very useful to have. I missed something like this in the past and when I worked on e2e test setup, I figured it will be a good moment to finally add it because it helped with automated e2e testing too.

@solnic solnic force-pushed the add-debug-transport branch 3 times, most recently from 88ede05 to 6a63405 Compare July 30, 2025 13:22
@solnic solnic marked this pull request as ready for review July 30, 2025 13:51
@solnic solnic requested a review from sl0thentr0py July 30, 2025 13:51
cursor[bot]

This comment was marked as outdated.

@solnic solnic force-pushed the add-debug-transport branch from a51b834 to 2c4ff7e Compare July 30, 2025 20:36
cursor[bot]

This comment was marked as outdated.

@solnic solnic force-pushed the add-debug-transport branch from 2c4ff7e to 0735440 Compare July 30, 2025 20:43
@getsentry getsentry deleted a comment from cursor bot Jul 30, 2025
@solnic solnic force-pushed the add-debug-transport branch from 0735440 to 5d4cdb2 Compare July 30, 2025 20:50
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@solnic solnic force-pushed the add-debug-transport branch from 087c021 to 7336f55 Compare July 31, 2025 09:35
cursor[bot]

This comment was marked as outdated.

@solnic solnic force-pushed the add-debug-transport branch 2 times, most recently from 28bb893 to 7992e27 Compare July 31, 2025 09:54
@solnic solnic marked this pull request as draft July 31, 2025 10:16
solnic added 2 commits July 31, 2025 10:34
This is important because that's how actual Transports
behave.

The specs had to be changed because their expectations
were based on behavior specific to DummyTransport.

Reasons for changing spec expectations:

Log spec creates a transaction and we run profiler
for every transaction, but due to sampling decision
profile event is being dropped and we end up with
a client report.

SessionFlush calls capture_envelope which bypasses
send_event, but the test actually does send two
error events, so now that DummyTransport#send_event
calls super, we end up (correctly) with 3 envelopes:
2 from errors, and 1 from session.
@solnic solnic force-pushed the add-debug-transport branch from 7992e27 to 0cec976 Compare July 31, 2025 10:37
@getsentry getsentry deleted a comment from cursor bot Jul 31, 2025
@getsentry getsentry deleted a comment from cursor bot Jul 31, 2025
@solnic solnic force-pushed the add-debug-transport branch from 0cec976 to 2b0d49e Compare July 31, 2025 10:51
@solnic solnic self-assigned this Jul 31, 2025
@solnic solnic marked this pull request as ready for review July 31, 2025 10:51
@getsentry getsentry deleted a comment from codecov bot Jul 31, 2025
@solnic solnic requested a review from sl0thentr0py July 31, 2025 10:51
@solnic
Copy link
Collaborator Author

solnic commented Jul 31, 2025

@sl0thentr0py mind taking another look? I made a couple of extra improvements and refactored DebugTransport into a delegator.

cursor[bot]

This comment was marked as outdated.

@solnic solnic force-pushed the add-debug-transport branch from 2b0d49e to adc27b3 Compare July 31, 2025 11:01
@@ -390,7 +390,8 @@

Sentry.get_current_client.flush

expect(sentry_envelopes.size).to be(2)
# 3 envelopes: log, transaction, and client_report about dropped profile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we actually shouldn't be sending the dropped profile client report here since we don't have profiles_sample_rate enabled, we should fix this separately

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sl0thentr0py yeah it seemed suspicious, I reported an issue about this #2669

if Sentry.initialized?
transport = Sentry.get_current_client&.transport

if transport.is_a?(Sentry::DebugTransport)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we aren't actually using the DebugTransport anywhere in the tests so why is this needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sl0thentr0py another PR will actually use this in a couple of e2e test

@@ -667,11 +667,15 @@ def will_be_sampled_by_sdk

Sentry.session_flusher.flush

expect(sentry_envelopes.count).to eq(1)
envelope = sentry_envelopes.first
expect(sentry_envelopes.count).to eq(3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did these values change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sl0thentr0py because the test actually sends 2 errors and flushes session which sends another event, so total is 3 envelopes, previously dummy transport wouldn't catch 2 other envelopes

@solnic solnic merged commit 6bd141c into master Jul 31, 2025
138 checks passed
@solnic solnic deleted the add-debug-transport branch July 31, 2025 13:44
Copy link

codecov bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 98.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.41%. Comparing base (36920ac) to head (adc27b3).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
sentry-ruby/lib/sentry/dsn.rb 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2664      +/-   ##
==========================================
+ Coverage   97.38%   97.41%   +0.02%     
==========================================
  Files         134      135       +1     
  Lines        5169     5229      +60     
==========================================
+ Hits         5034     5094      +60     
  Misses        135      135              
Components Coverage Δ
sentry-ruby 97.74% <98.33%> (+<0.01%) ⬆️
sentry-rails 96.10% <ø> (+0.14%) ⬆️
sentry-sidekiq 96.57% <ø> (ø)
sentry-resque 94.44% <ø> (ø)
sentry-delayed_job 94.68% <ø> (ø)
sentry-opentelemetry 99.31% <ø> (ø)
Files with missing lines Coverage Δ
sentry-ruby/lib/sentry/configuration.rb 98.36% <100.00%> (+<0.01%) ⬆️
sentry-ruby/lib/sentry/test_helper.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/transport.rb 97.34% <100.00%> (+0.02%) ⬆️
...entry-ruby/lib/sentry/transport/debug_transport.rb 100.00% <100.00%> (ø)
...entry-ruby/lib/sentry/transport/dummy_transport.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/dsn.rb 97.91% <94.44%> (-2.09%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants