class LogStash::Outputs::Application_insights::Telemetry

Constants

LOGSTASH_TELEMETRY_INSTRUMENTATION_KEY

Attributes

telemetry_channel[R]

Public Class Methods

instance() click to toggle source
# File lib/logstash/outputs/application_insights/telemetry.rb, line 111
def self.instance
  @@instance
end

Private Class Methods

new() click to toggle source
# File lib/logstash/outputs/application_insights/telemetry.rb, line 31
def initialize
  configuration = Config.current
  @enable_telemetry_to_microsoft = configuration[:enable_telemetry_to_microsoft]
  if @enable_telemetry_to_microsoft
    @telemetry_channel = create_async_channel( LOGSTASH_TELEMETRY_INSTRUMENTATION_KEY )
    set_async_channel_properties( @telemetry_channel )
    set_channel_context( @telemetry_channel )
  end
end

Public Instance Methods

create_async_channel( ikey ) click to toggle source
# File lib/logstash/outputs/application_insights/telemetry.rb, line 42
def create_async_channel ( ikey )
  sender = ApplicationInsights::Channel::AsynchronousSender.new
  queue = ApplicationInsights::Channel::AsynchronousQueue.new( sender )
  channel = ApplicationInsights::Channel::TelemetryChannel.new( nil, queue )
  ApplicationInsights::TelemetryClient.new( ikey, channel )
end
flush() click to toggle source
# File lib/logstash/outputs/application_insights/telemetry.rb, line 101
def flush
  if @enable_telemetry_to_microsoft
    @telemetry_channel.flush
  end
end
set_async_channel_properties( tc ) click to toggle source
# File lib/logstash/outputs/application_insights/telemetry.rb, line 49
def set_async_channel_properties ( tc )
  # flush telemetry if we have 10 or more telemetry items in our queue
  tc.channel.queue.max_queue_length = 10
  # send telemetry to the service in batches of 5
  tc.channel.sender.send_buffer_size = 5
  # the background worker thread will be active for 5 seconds before it shuts down. if
  # during this time items are picked up from the queue, the timer is reset.
  tc.channel.sender.send_time = 5
  # the background worker thread will poll the queue every 0.5 seconds for new items
  tc.channel.sender.send_interval = 0.5
end
set_channel_context( tc ) click to toggle source
# File lib/logstash/outputs/application_insights/telemetry.rb, line 61
def set_channel_context ( tc )
  # tc.context.application.id = 'logstash-output-Application-Insights plugin'
  tc.context.application.ver = VERSION
  tc.context.application.build = LOGSTASH_CORE_VERSION
  tc.context.device.id = Socket.gethostname.strip
  # tc.context.device.oem_name = 'Asus'
  # tc.context.device.model = 'X31A'
  tc.context.device.type = Utils.os
  # tc.context.user.id = 'santa@northpole.net'
end
track_event() { || ... } click to toggle source
# File lib/logstash/outputs/application_insights/telemetry.rb, line 72
def track_event
  if @enable_telemetry_to_microsoft
    options = yield
    name = options.delete( :name )
    @telemetry_channel.track_event( name, options )
  end
end
track_metric() { || ... } click to toggle source
# File lib/logstash/outputs/application_insights/telemetry.rb, line 80
def track_metric
  if @enable_telemetry_to_microsoft
    options = yield
    name = options.delete( :name )
    value = options.delete( :value )
    @telemetry_channel.track_metric( name, value, options )
  end
end
track_request() { || ... } click to toggle source
# File lib/logstash/outputs/application_insights/telemetry.rb, line 89
def track_request
  if @enable_telemetry_to_microsoft
    options = yield
    id = options.delete( :id )
    start_time = options.delete( :start_time )
    duration = options.delete( :duration )
    response_code = options.delete( :response_code )
    success = options.delete( :success )
    @telemetry_channel.track_request( id, start_time, duration, response_code, success, options )
  end
end