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.
-
#trace_id ⇒ Object
Returns the value of attribute trace_id.
-
#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
ensureda 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.
-
#performance_profile ⇒ Object
Profilo di performance per-richiesta (query + HTTP esterne).
- #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.
41 42 43 |
# File 'lib/closeyourit/scope.rb', line 41 def initialize clear end |
Instance Attribute Details
#breadcrumbs ⇒ Object (readonly)
Returns the value of attribute breadcrumbs.
39 40 41 |
# File 'lib/closeyourit/scope.rb', line 39 def @breadcrumbs end |
#contexts ⇒ Object (readonly)
Returns the value of attribute contexts.
39 40 41 |
# File 'lib/closeyourit/scope.rb', line 39 def contexts @contexts end |
#extra ⇒ Object (readonly)
Returns the value of attribute extra.
39 40 41 |
# File 'lib/closeyourit/scope.rb', line 39 def extra @extra end |
#request ⇒ Object
Returns the value of attribute request.
38 39 40 |
# File 'lib/closeyourit/scope.rb', line 38 def request @request end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
39 40 41 |
# File 'lib/closeyourit/scope.rb', line 39 def @tags end |
#trace_id ⇒ Object
Returns the value of attribute trace_id.
38 39 40 |
# File 'lib/closeyourit/scope.rb', line 38 def trace_id @trace_id end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
39 40 41 |
# File 'lib/closeyourit/scope.rb', line 39 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).
17 18 19 |
# File 'lib/closeyourit/scope.rb', line 17 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).
23 24 25 |
# File 'lib/closeyourit/scope.rb', line 23 def reset! store[STORAGE_KEY] = nil end |
Instance Method Details
#add_breadcrumb(breadcrumb) ⇒ Object
65 66 67 |
# File 'lib/closeyourit/scope.rb', line 65 def () @breadcrumbs.add() end |
#clear ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/closeyourit/scope.rb', line 75 def clear @user = {} @tags = {} @extra = {} @contexts = {} @request = nil @trace_id = nil @breadcrumbs = BreadcrumbBuffer.new(CloseYourIt.configuration.) @performance_profile = nil end |
#performance_profile ⇒ Object
Profilo di performance per-richiesta (query + HTTP esterne). Lazy: creato al primo accesso, azzerato da #clear a fine richiesta. Il verdetto lo calcola Subscribers::RequestPerformance.
71 72 73 |
# File 'lib/closeyourit/scope.rb', line 71 def performance_profile @performance_profile ||= Performance::RequestProfile.new end |
#set_context(key, attributes) ⇒ Object
57 58 59 |
# File 'lib/closeyourit/scope.rb', line 57 def set_context(key, attributes) @contexts[key.to_s] = stringify_keys(attributes) end |
#set_extra(key, value) ⇒ Object
61 62 63 |
# File 'lib/closeyourit/scope.rb', line 61 def set_extra(key, value) @extra[key.to_s] = value end |
#set_tag(key, value) ⇒ Object
49 50 51 |
# File 'lib/closeyourit/scope.rb', line 49 def set_tag(key, value) @tags[key.to_s] = value end |
#set_tags(attributes) ⇒ Object
53 54 55 |
# File 'lib/closeyourit/scope.rb', line 53 def (attributes) attributes.each { |key, value| set_tag(key, value) } end |
#set_user(attributes) ⇒ Object
45 46 47 |
# File 'lib/closeyourit/scope.rb', line 45 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. tags/extra/contexts passano dallo Scrubber (denylist ricorsiva per chiave): il backend NON li ri-scruba (Errors::Ingest::Normalize li conserva verbatim), quindi questa è l'unica rete di sicurezza contro le chiavi sensibili lì — R2.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/closeyourit/scope.rb', line 90 def to_event_hash { "user" => serialize_user, "tags" => scrub(presence(@tags)), "extra" => scrub(presence(@extra)), "contexts" => scrub(presence(@contexts)), "request" => @request, "breadcrumbs" => }.reject { |_key, value| value.nil? } end |