Class: LogStash::Outputs::Application_insights::Telemetry

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/application_insights/telemetry.rb

Constant Summary collapse

LOGSTASH_TELEMETRY_INSTRUMENTATION_KEY =
"52fe6bb7-5528-4b4e-b2cc-12ef128633b4"
@@instance =
Telemetry.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTelemetry

Returns a new instance of Telemetry.



31
32
33
34
35
36
37
38
39
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 31

def initialize
  configuration = Config.current
  @disable_telemetry = configuration[:disable_telemetry]
  unless @disable_telemetry
    @telemetry_channel = create_async_channel( LOGSTASH_TELEMETRY_INSTRUMENTATION_KEY )
    set_async_channel_properties( @telemetry_channel )
    set_channel_context( @telemetry_channel )
  end
end

Instance Attribute Details

#telemetry_channelObject (readonly)

Returns the value of attribute telemetry_channel.



25
26
27
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 25

def telemetry_channel
  @telemetry_channel
end

Class Method Details

.instanceObject



92
93
94
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 92

def self.instance
  @@instance
end

Instance Method Details

#create_async_channel(ikey) ⇒ Object



42
43
44
45
46
47
# 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

#flushObject



84
85
86
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 84

def flush
  @telemetry_channel.flush
end

#set_async_channel_properties(tc) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# 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) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# 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 = '[email protected]'

end

#track_event(name, options = {}) ⇒ Object



72
73
74
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 72

def track_event ( name, options={} )
   @telemetry_channel.track_event( name, options ) unless @disable_telemetry
end

#track_metric(name, value, options = {}) ⇒ Object



76
77
78
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 76

def track_metric ( name, value, options={} )
   @telemetry_channel.track_metric( name, value, options ) unless @disable_telemetry
end

#track_request(id, start_time, duration, response_code, success, options = {}) ⇒ Object



80
81
82
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 80

def track_request (id, start_time, duration, response_code, success, options = {} )
  @telemetry_channel.track_request( id, start_time, duration, response_code, success, options ) unless @disable_telemetry
end