class AppInsights::Context
Public Class Methods
configure(config = {})
click to toggle source
# File lib/appinsights/context.rb, line 6 def configure(config = {}) if config.fetch('async', false) sender = ApplicationInsights::Channel::AsynchronousSender.new sender.send_interval = config.fetch('async_send_interval_seconds', 60) sender.send_buffer_size = config.fetch('async_send_buffer_size', 100) queue = ApplicationInsights::Channel::AsynchronousQueue.new sender queue.max_queue_length = config.fetch('async_max_queue_length', 500) channel = ApplicationInsights::Channel::TelemetryChannel.new(nil, queue) @client = ApplicationInsights::TelemetryClient.new(nil, channel) end @context = telemetry_client.context contracts.each do |contract| instance = configure_contract(contract.capitalize, config) @context.send :"#{contract}=", instance end @context.instrumentation_key = config['instrumentation_key'] @context.properties = extract_custom_properties config @context end
context()
click to toggle source
# File lib/appinsights/context.rb, line 34 def context @context end
telemetry_client()
click to toggle source
# File lib/appinsights/context.rb, line 30 def telemetry_client @client ||= ApplicationInsights::TelemetryClient.new end
Private Class Methods
configure_contract(contract, config)
click to toggle source
# File lib/appinsights/context.rb, line 40 def configure_contract(contract, config) const = ApplicationInsights::Channel::Contracts.const_get contract const.new config[contract.downcase] rescue NameError nil end
contracts()
click to toggle source
# File lib/appinsights/context.rb, line 53 def contracts %w(user device session location operation application) end
extract_custom_properties(config)
click to toggle source
Custom properties are defined at [ai] level of the config file.
# File lib/appinsights/context.rb, line 49 def extract_custom_properties(config) config.reject { |k, v| k.to_s == 'instrumentation_key' || v.is_a?(Hash) } end