Skip to content

Commit

Permalink
Simplify session updates on exception
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Feb 11, 2022
1 parent 1b8268a commit 55a5c1e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions sentry-ruby/lib/sentry/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def capture_event(event, scope, hint = {})
return
end

scope.session&.update_from_event(event)

if async_block = configuration.async
dispatch_async_event(async_block, event, hint)
elsif configuration.background_worker_threads != 0 && hint.fetch(:background, true)
Expand Down
23 changes: 16 additions & 7 deletions sentry-ruby/lib/sentry/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,31 @@
module Sentry
class Session
# TODO-neel docs, types
attr_accessor :started
attr_accessor :status
attr_accessor :errors
attr_reader :started
attr_reader :status

# only :ok, :exited and :errored used currently
VALID_STATES = %i(ok exited crashed abnormal errored)

def initialize
@started = Sentry.utc_now
@status = :ok
@errors = 0
end

# TODO-neel add :crashed after adding handled
def update_from_event(event)
return unless event
return unless event.is_a?(Event) && event.exception
@status = :errored
end

def close
@status = :exited if @status == :ok
end

def close(status: :exited)
@status = status
# truncate seconds from the timestamp since we only care about
# minute level granularity for aggregation
def started_bucket
Time.utc(started.year, started.month, started.day, started.hour, started.min)
end

def deep_dup
Expand Down

0 comments on commit 55a5c1e

Please sign in to comment.