Class: Logtide::Scope
- Inherits:
-
Object
- Object
- Logtide::Scope
- Defined in:
- lib/logtide/scope.rb
Overview
Per-request/per-task context merged into every entry captured while active (spec 004 section 4). Cloned per request so concurrent work never shares mutable state.
Instance Attribute Summary collapse
-
#breadcrumbs ⇒ Object
readonly
Returns the value of attribute breadcrumbs.
-
#extra ⇒ Object
readonly
Returns the value of attribute extra.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#span ⇒ Object
readonly
Returns the value of attribute span.
-
#span_id ⇒ Object
readonly
Returns the value of attribute span_id.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #add_breadcrumb(breadcrumb) ⇒ Object
- #add_event_processor(processor) ⇒ Object
- #clear_breadcrumbs ⇒ Object
- #event_processors ⇒ Object
-
#initialize(max_breadcrumbs: 100) ⇒ Scope
constructor
A new instance of Scope.
- #initialize_copy(other) ⇒ Object
- #remove_tag(key) ⇒ Object
- #set_extra(key, value) ⇒ Object
- #set_session_id(session_id) ⇒ Object
- #set_span(span) ⇒ Object
- #set_tag(key, value) ⇒ Object
- #set_trace_context(trace_id, span_id) ⇒ Object
- #set_user(user) ⇒ Object
Constructor Details
#initialize(max_breadcrumbs: 100) ⇒ Scope
Returns a new instance of Scope.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/logtide/scope.rb', line 12 def initialize(max_breadcrumbs: 100) @tags = {} @user = nil @session_id = nil @extra = {} @trace_id = nil @span_id = nil @span = nil @breadcrumbs = BreadcrumbBuffer.new() @event_processors = [] end |
Instance Attribute Details
#breadcrumbs ⇒ Object (readonly)
Returns the value of attribute breadcrumbs.
10 11 12 |
# File 'lib/logtide/scope.rb', line 10 def @breadcrumbs end |
#extra ⇒ Object (readonly)
Returns the value of attribute extra.
10 11 12 |
# File 'lib/logtide/scope.rb', line 10 def extra @extra end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
10 11 12 |
# File 'lib/logtide/scope.rb', line 10 def session_id @session_id end |
#span ⇒ Object (readonly)
Returns the value of attribute span.
10 11 12 |
# File 'lib/logtide/scope.rb', line 10 def span @span end |
#span_id ⇒ Object (readonly)
Returns the value of attribute span_id.
10 11 12 |
# File 'lib/logtide/scope.rb', line 10 def span_id @span_id end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
10 11 12 |
# File 'lib/logtide/scope.rb', line 10 def @tags end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
10 11 12 |
# File 'lib/logtide/scope.rb', line 10 def trace_id @trace_id end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
10 11 12 |
# File 'lib/logtide/scope.rb', line 10 def user @user end |
Instance Method Details
#add_breadcrumb(breadcrumb) ⇒ Object
60 61 62 63 |
# File 'lib/logtide/scope.rb', line 60 def () @breadcrumbs.add() self end |
#add_event_processor(processor) ⇒ Object
70 71 72 73 |
# File 'lib/logtide/scope.rb', line 70 def add_event_processor(processor) @event_processors << processor self end |
#clear_breadcrumbs ⇒ Object
65 66 67 68 |
# File 'lib/logtide/scope.rb', line 65 def @breadcrumbs.clear self end |
#event_processors ⇒ Object
75 76 77 |
# File 'lib/logtide/scope.rb', line 75 def event_processors @event_processors.dup end |
#initialize_copy(other) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/logtide/scope.rb', line 79 def initialize_copy(other) super @tags = other..dup @extra = other.extra.dup @user = other.user&.dup @breadcrumbs = other..dup @event_processors = other.event_processors end |
#remove_tag(key) ⇒ Object
34 35 36 37 |
# File 'lib/logtide/scope.rb', line 34 def remove_tag(key) @tags.delete(key.to_s) self end |
#set_extra(key, value) ⇒ Object
49 50 51 52 |
# File 'lib/logtide/scope.rb', line 49 def set_extra(key, value) @extra[key.to_s] = value self end |
#set_session_id(session_id) ⇒ Object
44 45 46 47 |
# File 'lib/logtide/scope.rb', line 44 def set_session_id(session_id) @session_id = session_id self end |
#set_span(span) ⇒ Object
24 25 26 27 |
# File 'lib/logtide/scope.rb', line 24 def set_span(span) @span = span self end |
#set_tag(key, value) ⇒ Object
29 30 31 32 |
# File 'lib/logtide/scope.rb', line 29 def set_tag(key, value) @tags[key.to_s] = value.to_s self end |
#set_trace_context(trace_id, span_id) ⇒ Object
54 55 56 57 58 |
# File 'lib/logtide/scope.rb', line 54 def set_trace_context(trace_id, span_id) @trace_id = trace_id @span_id = span_id self end |
#set_user(user) ⇒ Object
39 40 41 42 |
# File 'lib/logtide/scope.rb', line 39 def set_user(user) @user = user.nil? ? nil : stringify(user) self end |