Class: ApplicationInsights::Channel::TelemetryChannel
- Inherits:
-
Object
- Object
- ApplicationInsights::Channel::TelemetryChannel
- Defined in:
- lib/application_insights/channel/telemetry_channel.rb
Overview
The telemetry channel is responsible for constructing a Contracts::Envelope object from the passed in data and specified telemetry context.
Instance Attribute Summary collapse
-
#context ⇒ TelemetryContext
readonly
The context associated with this channel.
-
#queue ⇒ QueueBase
readonly
The queue associated with this channel.
Instance Method Summary collapse
-
#flush ⇒ Object
Flushes the enqueued data by calling QueueBase#flush.
-
#initialize(context = nil, queue = nil) ⇒ TelemetryChannel
constructor
Initializes a new instance of the class.
-
#sender ⇒ SenderBase
The sender associated with this channel.
-
#write(data, context = nil, time = nil) ⇒ Object
Enqueues the passed in data to the #queue.
Constructor Details
#initialize(context = nil, queue = nil) ⇒ TelemetryChannel
Initializes a new instance of the class.
29 30 31 32 |
# File 'lib/application_insights/channel/telemetry_channel.rb', line 29 def initialize(context=nil, queue=nil) @context = context || TelemetryContext.new @queue = queue || SynchronousQueue.new(SynchronousSender.new) end |
Instance Attribute Details
#context ⇒ TelemetryContext (readonly)
The context associated with this channel. All Contracts::Envelope objects created by this channel will use this value if it’s present or if none is specified as part of the #write call.
39 40 41 |
# File 'lib/application_insights/channel/telemetry_channel.rb', line 39 def context @context end |
#queue ⇒ QueueBase (readonly)
The queue associated with this channel. All Contracts::Envelope objects created by this channel will be pushed to this queue.
44 45 46 |
# File 'lib/application_insights/channel/telemetry_channel.rb', line 44 def queue @queue end |
Instance Method Details
#flush ⇒ Object
Flushes the enqueued data by calling QueueBase#flush.
54 55 56 |
# File 'lib/application_insights/channel/telemetry_channel.rb', line 54 def flush @queue.flush end |
#sender ⇒ SenderBase
The sender associated with this channel. This instance will be used to transmit telemetry to the service.
49 50 51 |
# File 'lib/application_insights/channel/telemetry_channel.rb', line 49 def sender @queue.sender end |
#write(data, context = nil, time = nil) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/application_insights/channel/telemetry_channel.rb', line 66 def write(data, context=nil, time=nil) local_context = context || @context raise ArgumentError, 'Context was required but not provided' unless local_context if time && time.is_a?(String) local_time = time elsif time && time.is_a?(Time) local_time = time.iso8601(7) else local_time = Time.now.iso8601(7) end data_type = data.class.name.gsub(/^.*::/, '') set_properties data, local_context data_attributes = { :base_type => data_type, :base_data => data } envelope_attributes = { :name => 'Microsoft.ApplicationInsights.' + data_type[0..-5], :time => local_time, :i_key => local_context.instrumentation_key, :tags => (local_context), :data => Contracts::Data.new(data_attributes) } envelope = Contracts::Envelope.new envelope_attributes @queue.push(envelope) end |