Class: Tinymon::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/tinymon/scope.rb

Overview

Process-wide user/tags/breadcrumbs that ride along with every event.

Constant Summary collapse

MAX_BREADCRUMBS =
50

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScope

Returns a new instance of Scope.



10
11
12
13
14
15
# File 'lib/tinymon/scope.rb', line 10

def initialize
  @mutex = Mutex.new
  @user = {}
  @tags = {}
  @breadcrumbs = []
end

Instance Attribute Details

Returns the value of attribute breadcrumbs.



8
9
10
# File 'lib/tinymon/scope.rb', line 8

def breadcrumbs
  @breadcrumbs
end

#tagsObject (readonly)

Returns the value of attribute tags.



8
9
10
# File 'lib/tinymon/scope.rb', line 8

def tags
  @tags
end

#userObject (readonly)

Returns the value of attribute user.



8
9
10
# File 'lib/tinymon/scope.rb', line 8

def user
  @user
end

Instance Method Details

#add_breadcrumb(crumb) ⇒ Object



25
26
27
28
29
30
# File 'lib/tinymon/scope.rb', line 25

def add_breadcrumb(crumb)
  @mutex.synchronize do
    @breadcrumbs.push(crumb)
    @breadcrumbs.shift if @breadcrumbs.length > MAX_BREADCRUMBS
  end
end

#set_tag(key, value) ⇒ Object



21
22
23
# File 'lib/tinymon/scope.rb', line 21

def set_tag(key, value)
  @mutex.synchronize { @tags[key.to_s] = value }
end

#set_user(user) ⇒ Object



17
18
19
# File 'lib/tinymon/scope.rb', line 17

def set_user(user)
  @mutex.synchronize { @user = user.dup }
end

#snapshotObject



32
33
34
35
36
37
38
39
40
# File 'lib/tinymon/scope.rb', line 32

def snapshot
  @mutex.synchronize do
    {
      user: @user.dup,
      tags: @tags.dup,
      breadcrumbs: @breadcrumbs.dup,
    }
  end
end