Class: Datadog::Tracing::Event
- Inherits:
-
Object
- Object
- Datadog::Tracing::Event
- Defined in:
- lib/datadog/tracing/event.rb
Overview
A simple pub-sub event model for components to exchange messages through.
Direct Known Subclasses
SpanOperation::Events::AfterFinish, SpanOperation::Events::AfterStop, SpanOperation::Events::BeforeStart, TraceOperation::Events::SpanBeforeStart, TraceOperation::Events::SpanFinished, TraceOperation::Events::TraceFinished, Tracer::TraceCompleted, Workers::TraceWriter::FlushCompleted, Writer::Events::AfterSend
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#subscriptions ⇒ Object
readonly
Returns the value of attribute subscriptions.
Instance Method Summary collapse
-
#initialize(name) ⇒ Event
constructor
A new instance of Event.
- #publish(*args) ⇒ Object
- #subscribe(&block) ⇒ Object
- #unsubscribe_all! ⇒ Object
Constructor Details
#initialize(name) ⇒ Event
Returns a new instance of Event.
43 44 45 46 |
# File 'lib/datadog/tracing/event.rb', line 43 def initialize(name) @name = name @subscriptions = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
39 40 41 |
# File 'lib/datadog/tracing/event.rb', line 39 def name @name end |
#subscriptions ⇒ Object (readonly)
Returns the value of attribute subscriptions.
39 40 41 |
# File 'lib/datadog/tracing/event.rb', line 39 def subscriptions @subscriptions end |
Instance Method Details
#publish(*args) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/datadog/tracing/event.rb', line 60 def publish(*args) subscriptions.each do |block| begin block.call(*args) rescue StandardError => e Datadog.logger.debug do "Error while handling '#{name}' event with '#{block}': #{e.class.name} #{e.} " \ "at #{Array(e.backtrace).first}" end end end true end |
#subscribe(&block) ⇒ Object
48 49 50 51 52 |
# File 'lib/datadog/tracing/event.rb', line 48 def subscribe(&block) raise ArgumentError, 'Must give a block to subscribe!' unless block subscriptions << block end |
#unsubscribe_all! ⇒ Object
54 55 56 57 58 |
# File 'lib/datadog/tracing/event.rb', line 54 def unsubscribe_all! subscriptions.clear true end |