Skip to content

Capture exceptions in Action Cable connections and channels#1251

Closed
agrobbin wants to merge 1 commit intogetsentry:4-2from
agrobbin:rails-action-cable-support
Closed

Capture exceptions in Action Cable connections and channels#1251
agrobbin wants to merge 1 commit intogetsentry:4-2from
agrobbin:rails-action-cable-support

Conversation

@agrobbin
Copy link
Copy Markdown
Contributor

@agrobbin agrobbin commented Jan 30, 2021

Hi @st0012! I mentioned this in #470 (comment) (and #470 (comment)), and now that 4.x is reasonably stable, thought it worth getting this PR out there.

There are 5 types of hooks that Action Cable provides:

  • Connection#connect
  • Connection#disconnect
  • Channel#subscribed
  • Channel#unsubscribed
  • Channel actions

Now, any exceptions raised within those hooks are captured by Sentry, and reported as ActionCable/[...] transactions. Additional context is included depending on the hook the exception was raised within.

A note/quirk: the Rack env that's included in the scope is from the Connection, and therefore has a URL of the cable mount_path (usually /cable) as well as the headers from that initial connection request.

Additionally, there is not currently a really clean way to hook in and set user_context. I don't know if that is a blocker for this integration, but wanted to make sure it was noted.

Closes #470.

There are 5 types of hooks that Action Cable provides:

* `Connection#connect`
* `Connection#disconnect`
* `Channel#subscribed`
* `Channel#unsubscribed`
* `Channel` actions

Now, any exceptions raised within those hooks are captured by Sentry, and reported as `ActionCable/[...]` transactions. Additional context is included depending on the hook the exception was raised within.

A note/quirk: the Rack env that's included in the scope is from the `Connection`, and therefore has a URL of the cable `mount_path` (usually `/cable`) as well as the headers from that initial connection request.

Additionally, there is not currently a really clean way to hook in and set `user_context`. I don't know if that is a blocker for this integration, but wanted to make sure it was noted.
@agrobbin agrobbin force-pushed the rails-action-cable-support branch from 7a29165 to 2313db6 Compare January 30, 2021 03:10
@agrobbin
Copy link
Copy Markdown
Contributor Author

Hmm weird, I'm not sure why CI isn't able to load action_cable/connection/test_case, it runs as expected locally.

@agrobbin
Copy link
Copy Markdown
Contributor Author

Ah, mystery solved! Turns out, Rails didn't introduce its Action Cable test helpers until 6.0. I'm not sure what the preference here would be, as I am pretty sure the Action Cable integration itself would still work in 5.2, there's just not a great way to test against both versions.

Let me know what you'd like to do about that @st0012!

@st0012
Copy link
Copy Markdown
Contributor

st0012 commented Jan 31, 2021

@agrobbin thanks for the PR 👍

regarding the testing helper, can you take the necessary part of it to a helper file in sentry-rails, and only require it when testing against Rails 5?

also, can you help me setup actioncable in the Rails 6 example app (/examples/rails-6.0) we use? the ideal situation is that I can trigger events just by visiting an url. there could be 4 different paths to cover the 4 types of callbacks we support.

finally, I'll change the PR's base to 4-2 branch because it's a new feature and will be introduced in v4.2.0.

@st0012 st0012 changed the base branch from master to 4-2 January 31, 2021 03:13
@st0012 st0012 closed this Feb 3, 2021
@st0012 st0012 deleted the branch getsentry:4-2 February 3, 2021 16:47
@st0012
Copy link
Copy Markdown
Contributor

st0012 commented Feb 3, 2021

@agrobbin sorry that this was automatically closed due to I merged the 4-2 branch 🤦. can you reopen it and change the base to master again? thx

@st0012 st0012 modified the milestones: 4.2.0, 4.3.0 Feb 3, 2021
@agrobbin
Copy link
Copy Markdown
Contributor Author

Re-opened as #1295.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ActionCable probably doesn't work

2 participants