Class: ApplicationInsights::TelemetryClient
- Inherits:
-
Object
- Object
- ApplicationInsights::TelemetryClient
- Defined in:
- lib/application_insights/telemetry_client.rb
Overview
The telemetry client used for sending all types of telemetry.
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Gets the channel associated with this telemetry client.
-
#context ⇒ Object
readonly
Gets the context associated with this telemetry client.
Instance Method Summary collapse
-
#flush ⇒ Object
Flushes the current queue.
-
#initialize(telemetry_channel = nil) ⇒ TelemetryClient
constructor
Initializes a new instance of the TelemetryClient class.
-
#track_event(name, options = {}) ⇒ Object
Send an EventTelemetry object for display in Diagnostic Search and aggregation in Metrics Explorer.
-
#track_exception(exception, options = {}) ⇒ Object
Send an ExceptionTelemetry object for display in Diagnostic Search.
-
#track_metric(name, value, options = {}) ⇒ Object
Send a MetricTelemetry object for aggregation in Metric Explorer.
-
#track_page_view(name, url, options = {}) ⇒ Object
Send information about the page viewed in the application.
-
#track_trace(name, options = {}) ⇒ Object
Send a trace message for display in Diagnostic Search.
Constructor Details
#initialize(telemetry_channel = nil) ⇒ TelemetryClient
Initializes a new instance of the TelemetryClient class.
16 17 18 19 |
# File 'lib/application_insights/telemetry_client.rb', line 16 def initialize(telemetry_channel = nil) @context = Channel::TelemetryContext.new @channel = telemetry_channel || Channel::TelemetryChannel.new end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Gets the channel associated with this telemetry client.
25 26 27 |
# File 'lib/application_insights/telemetry_client.rb', line 25 def channel @channel end |
#context ⇒ Object (readonly)
Gets the context associated with this telemetry client.
22 23 24 |
# File 'lib/application_insights/telemetry_client.rb', line 22 def context @context end |
Instance Method Details
#flush ⇒ Object
Flushes the current queue.
107 108 109 |
# File 'lib/application_insights/telemetry_client.rb', line 107 def flush self.channel.flush end |
#track_event(name, options = {}) ⇒ Object
Send an EventTelemetry object for display in Diagnostic Search and aggregation in Metrics Explorer.
65 66 67 68 69 70 71 72 73 |
# File 'lib/application_insights/telemetry_client.rb', line 65 def track_event(name, ={}) data_attributes = { :name => name || 'Null', :properties => .fetch(:properties) { {} }, :measurements => .fetch(:measurements) { {} } } data = Channel::Contracts::EventData.new data_attributes self.channel.write(data, self.context) end |
#track_exception(exception, options = {}) ⇒ Object
Send an ExceptionTelemetry object for display in Diagnostic Search.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/application_insights/telemetry_client.rb', line 41 def track_exception(exception, ={}) if exception.is_a? Exception details_attributes = { :id => 1, :outer_id => 0, :type_name => exception.class, :message => exception., :has_full_stack => true, :stack => exception.backtrace.join("\n") } details = Channel::Contracts::ExceptionDetails.new details_attributes data_attributes = { :handled_at => 'UserCode', :exceptions => [ details ], :properties => .fetch(:properties) { {} }, :measurements => .fetch(:measurements) { {} } } data = Channel::Contracts::ExceptionData.new data_attributes self.channel.write(data, self.context) end end |
#track_metric(name, value, options = {}) ⇒ Object
Send a MetricTelemetry object for aggregation in Metric Explorer.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/application_insights/telemetry_client.rb', line 76 def track_metric(name, value, ={}) data_point_attributes = { :name => name || 'Null', :value => value || 0, :kind => .fetch(:type) { Channel::Contracts::DataPointType::AGGREGATION }, :count => [:count], :min => [:min], :max => [:max], :std_dev => [:std_dev] } data_point = Channel::Contracts::DataPoint.new data_point_attributes data_attributes = { :metrics => [ data_point ], :properties => .fetch(:measurements) { {} } } data = Channel::Contracts::MetricData.new data_attributes self.channel.write(data, self.context) end |
#track_page_view(name, url, options = {}) ⇒ Object
Send information about the page viewed in the application.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/application_insights/telemetry_client.rb', line 28 def track_page_view(name, url, ={}) data_attributes = { :name => name || 'Null', :url => url, :duration => [:duration], :properties => .fetch(:properties) { {} }, :measurements => .fetch(:measurements) { {} } } data = Channel::Contracts::PageViewData.new data_attributes self.channel.write(data, self.context) end |
#track_trace(name, options = {}) ⇒ Object
Send a trace message for display in Diagnostic Search.
97 98 99 100 101 102 103 104 |
# File 'lib/application_insights/telemetry_client.rb', line 97 def track_trace(name, ={}) data_attributes = { :message => name || 'Null', :properties => .fetch(:measurements) { {} } } data = Channel::Contracts::MessageData.new data_attributes self.channel.write(data, self.context) end |