Capture context for Sentry errors during WebSocket connection

Special handling is needed to ensure we have the transaction ID and Rack ENV. Otherwise the error cannot be matched to a transaction in Sentry. This special behavior is needed because of the underlying EventMachine, which executes code in a different thread/context.
This commit is contained in:
Sebastian Serth
2023-04-14 12:50:50 +02:00
parent bd68a9a47b
commit c407d8cb8b

View File

@ -42,6 +42,9 @@ class Runner::Connection
I18n.with_locale(@locale) do
clone_sentry_hub_from_span(sentry_span)
__send__(:"on_#{event_type}", event, sentry_span)
rescue StandardError => e
Sentry.capture_exception(e)
raise e
end
end
end
@ -241,7 +244,7 @@ class Runner::Connection
# and adapted to the Websocket protocol running with EventMachine.
def clone_sentry_hub_from_span(sentry_span)
Thread.current.thread_variable_set(Sentry::THREAD_LOCAL, sentry_span.transaction.hub) if sentry_span
Thread.current.thread_variable_set(Sentry::THREAD_LOCAL, sentry_span.transaction.hub.clone) if sentry_span
end
def sentry_trace_header(sentry_span)