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.
41 42 43 44 |
# File 'lib/datadog/tracing/event.rb', line 41 def initialize(name) @name = name @subscriptions = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
37 38 39 |
# File 'lib/datadog/tracing/event.rb', line 37 def name @name end |
#subscriptions ⇒ Object (readonly)
Returns the value of attribute subscriptions.
37 38 39 |
# File 'lib/datadog/tracing/event.rb', line 37 def subscriptions @subscriptions end |
Instance Method Details
#publish(*args) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/datadog/tracing/event.rb', line 58 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
46 47 48 49 50 |
# File 'lib/datadog/tracing/event.rb', line 46 def subscribe(&block) raise ArgumentError, 'Must give a block to subscribe!' unless block subscriptions << block end |
#unsubscribe_all! ⇒ Object
52 53 54 55 56 |
# File 'lib/datadog/tracing/event.rb', line 52 def unsubscribe_all! subscriptions.clear true end |