Class: CloseYourIt::Scope
- Inherits:
-
Object
- Object
- CloseYourIt::Scope
- Defined in:
- lib/closeyourit/scope.rb
Overview
Contesto per-richiesta (o per-job) isolato per execution-context (Fiber storage): user/tags/extra/contexts/request. Letto da ErrorEvent#to_h sul thread chiamante (sincrono) → il worker di invio non lo vede mai e lo scope non cola tra richieste.
Constant Summary collapse
- STORAGE_KEY =
:__closeyourit_scope
Instance Attribute Summary collapse
-
#breadcrumbs ⇒ Object
readonly
Returns the value of attribute breadcrumbs.
-
#contexts ⇒ Object
readonly
Returns the value of attribute contexts.
-
#extra ⇒ Object
readonly
Returns the value of attribute extra.
-
#request ⇒ Object
Returns the value of attribute request.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
-
.current ⇒ Object
Scope dell’execution-context corrente.
-
.reset! ⇒ Object
Azzera lo scope corrente — chiamato in ‘ensure` da middleware e job (su Puma il thread è riusato: senza reset lo scope colerebbe nella richiesta successiva).
Instance Method Summary collapse
- #add_breadcrumb(breadcrumb) ⇒ Object
- #clear ⇒ Object
-
#initialize ⇒ Scope
constructor
A new instance of Scope.
- #set_context(key, attributes) ⇒ Object
- #set_extra(key, value) ⇒ Object
- #set_tag(key, value) ⇒ Object
- #set_tags(attributes) ⇒ Object
- #set_user(attributes) ⇒ Object
-
#to_event_hash ⇒ Object
Sottoinsieme non vuoto in forma evento Sentry (user/tags/extra/contexts/request), fuso nel payload da ErrorEvent#to_h.
Constructor Details
#initialize ⇒ Scope
Returns a new instance of Scope.
40 41 42 |
# File 'lib/closeyourit/scope.rb', line 40 def initialize clear end |
Instance Attribute Details
#breadcrumbs ⇒ Object (readonly)
Returns the value of attribute breadcrumbs.
38 39 40 |
# File 'lib/closeyourit/scope.rb', line 38 def @breadcrumbs end |
#contexts ⇒ Object (readonly)
Returns the value of attribute contexts.
38 39 40 |
# File 'lib/closeyourit/scope.rb', line 38 def contexts @contexts end |
#extra ⇒ Object (readonly)
Returns the value of attribute extra.
38 39 40 |
# File 'lib/closeyourit/scope.rb', line 38 def extra @extra end |
#request ⇒ Object
Returns the value of attribute request.
37 38 39 |
# File 'lib/closeyourit/scope.rb', line 37 def request @request end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
38 39 40 |
# File 'lib/closeyourit/scope.rb', line 38 def @tags end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
38 39 40 |
# File 'lib/closeyourit/scope.rb', line 38 def user @user end |
Class Method Details
.current ⇒ Object
Scope dell’execution-context corrente. Usa ‘ActiveSupport::IsolatedExecutionState` quando presente (rispetta isolation_level: thread su Puma, fiber su Falcon), altrimenti `Thread.current` (thread-local puro, NON ereditato dai thread figli → niente bleed).
16 17 18 |
# File 'lib/closeyourit/scope.rb', line 16 def current store[STORAGE_KEY] ||= new end |
.reset! ⇒ Object
Azzera lo scope corrente — chiamato in ‘ensure` da middleware e job (su Puma il thread è riusato: senza reset lo scope colerebbe nella richiesta successiva).
22 23 24 |
# File 'lib/closeyourit/scope.rb', line 22 def reset! store[STORAGE_KEY] = nil end |
Instance Method Details
#add_breadcrumb(breadcrumb) ⇒ Object
64 65 66 |
# File 'lib/closeyourit/scope.rb', line 64 def () @breadcrumbs.add() end |
#clear ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/closeyourit/scope.rb', line 68 def clear @user = {} @tags = {} @extra = {} @contexts = {} @request = nil @breadcrumbs = BreadcrumbBuffer.new(CloseYourIt.configuration.) end |
#set_context(key, attributes) ⇒ Object
56 57 58 |
# File 'lib/closeyourit/scope.rb', line 56 def set_context(key, attributes) @contexts[key.to_s] = stringify_keys(attributes) end |
#set_extra(key, value) ⇒ Object
60 61 62 |
# File 'lib/closeyourit/scope.rb', line 60 def set_extra(key, value) @extra[key.to_s] = value end |
#set_tag(key, value) ⇒ Object
48 49 50 |
# File 'lib/closeyourit/scope.rb', line 48 def set_tag(key, value) @tags[key.to_s] = value end |
#set_tags(attributes) ⇒ Object
52 53 54 |
# File 'lib/closeyourit/scope.rb', line 52 def (attributes) attributes.each { |key, value| set_tag(key, value) } end |
#set_user(attributes) ⇒ Object
44 45 46 |
# File 'lib/closeyourit/scope.rb', line 44 def set_user(attributes) @user.merge!(stringify_keys(attributes)) end |
#to_event_hash ⇒ Object
Sottoinsieme non vuoto in forma evento Sentry (user/tags/extra/contexts/request), fuso nel payload da ErrorEvent#to_h.
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/closeyourit/scope.rb', line 79 def to_event_hash { "user" => serialize_user, "tags" => presence(@tags), "extra" => presence(@extra), "contexts" => presence(@contexts), "request" => @request, "breadcrumbs" => }.reject { |_key, value| value.nil? } end |