application_insights 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +9 -9
  2. data/LICENSE.txt +7 -18
  3. data/README.md +42 -7
  4. data/Rakefile +6 -1
  5. data/application_insights.gemspec +2 -0
  6. data/lib/application_insights.rb +1 -0
  7. data/lib/application_insights/channel/asynchronous_queue.rb +51 -0
  8. data/lib/application_insights/channel/asynchronous_sender.rb +121 -0
  9. data/lib/application_insights/channel/contracts/application.rb +3 -2
  10. data/lib/application_insights/channel/contracts/data.rb +3 -2
  11. data/lib/application_insights/channel/contracts/data_point.rb +15 -10
  12. data/lib/application_insights/channel/contracts/device.rb +42 -28
  13. data/lib/application_insights/channel/contracts/envelope.rb +39 -27
  14. data/lib/application_insights/channel/contracts/event_data.rb +6 -6
  15. data/lib/application_insights/channel/contracts/exception_data.rb +9 -8
  16. data/lib/application_insights/channel/contracts/exception_details.rb +15 -11
  17. data/lib/application_insights/channel/contracts/internal.rb +6 -4
  18. data/lib/application_insights/channel/contracts/location.rb +3 -2
  19. data/lib/application_insights/channel/contracts/message_data.rb +6 -5
  20. data/lib/application_insights/channel/contracts/metric_data.rb +3 -3
  21. data/lib/application_insights/channel/contracts/operation.rb +12 -8
  22. data/lib/application_insights/channel/contracts/page_view_data.rb +12 -10
  23. data/lib/application_insights/channel/contracts/remote_dependency_data.rb +27 -19
  24. data/lib/application_insights/channel/contracts/request_data.rb +15 -12
  25. data/lib/application_insights/channel/contracts/session.rb +9 -6
  26. data/lib/application_insights/channel/contracts/stack_frame.rb +9 -6
  27. data/lib/application_insights/channel/contracts/user.rb +12 -8
  28. data/lib/application_insights/channel/event.rb +64 -0
  29. data/lib/application_insights/channel/queue_base.rb +24 -10
  30. data/lib/application_insights/channel/sender_base.rb +38 -9
  31. data/lib/application_insights/channel/synchronous_queue.rb +16 -5
  32. data/lib/application_insights/channel/synchronous_sender.rb +4 -2
  33. data/lib/application_insights/channel/telemetry_channel.rb +26 -7
  34. data/lib/application_insights/channel/telemetry_context.rb +29 -10
  35. data/lib/application_insights/telemetry_client.rb +84 -15
  36. data/lib/application_insights/unhandled_exception.rb +48 -0
  37. data/lib/application_insights/version.rb +1 -1
  38. data/test/application_insights/channel/test_asynchronous_queue.rb +68 -0
  39. data/test/application_insights/channel/test_asynchronous_sender.rb +81 -0
  40. data/test/application_insights/channel/test_event.rb +53 -0
  41. data/test/application_insights/channel/test_queue_base.rb +10 -9
  42. data/test/application_insights/channel/test_sender_base.rb +0 -9
  43. data/test/application_insights/test_telemetry_client.rb +5 -0
  44. data/test/application_insights/test_unhandled_exception.rb +42 -0
  45. metadata +44 -3
@@ -17,8 +17,9 @@ module ApplicationInsights
17
17
 
18
18
  # Gets the ip property.
19
19
  def ip
20
- return @values['ai.location.ip'] if @values.key?('ai.location.ip')
21
- @defaults['ai.location.ip']
20
+ @values.fetch('ai.location.ip') {
21
+ @values['ai.location.ip'] = nil
22
+ }
22
23
  end
23
24
 
24
25
  # Sets the ip property.
@@ -42,8 +42,9 @@ module ApplicationInsights
42
42
 
43
43
  # Gets the severity_level property.
44
44
  def severity_level
45
- return @values['severityLevel'] if @values.key?('severityLevel')
46
- @defaults['severityLevel']
45
+ @values.fetch('severityLevel') {
46
+ @values['severityLevel'] = nil
47
+ }
47
48
  end
48
49
 
49
50
  # Sets the severity_level property.
@@ -57,9 +58,9 @@ module ApplicationInsights
57
58
 
58
59
  # Gets the properties property.
59
60
  def properties
60
- return @values['properties'] if @values.key?('properties')
61
- @values['properties'] = {}
62
- @values['properties']
61
+ @values.fetch('properties') {
62
+ @values['properties'] = {}
63
+ }
63
64
  end
64
65
 
65
66
  # Sets the properties property.
@@ -41,9 +41,9 @@ module ApplicationInsights
41
41
 
42
42
  # Gets the properties property.
43
43
  def properties
44
- return @values['properties'] if @values.key?('properties')
45
- @values['properties'] = {}
46
- @values['properties']
44
+ @values.fetch('properties') {
45
+ @values['properties'] = {}
46
+ }
47
47
  end
48
48
 
49
49
  # Sets the properties property.
@@ -20,8 +20,9 @@ module ApplicationInsights
20
20
 
21
21
  # Gets the id property.
22
22
  def id
23
- return @values['ai.operation.id'] if @values.key?('ai.operation.id')
24
- @defaults['ai.operation.id']
23
+ @values.fetch('ai.operation.id') {
24
+ @values['ai.operation.id'] = nil
25
+ }
25
26
  end
26
27
 
27
28
  # Sets the id property.
@@ -35,8 +36,9 @@ module ApplicationInsights
35
36
 
36
37
  # Gets the name property.
37
38
  def name
38
- return @values['ai.operation.name'] if @values.key?('ai.operation.name')
39
- @defaults['ai.operation.name']
39
+ @values.fetch('ai.operation.name') {
40
+ @values['ai.operation.name'] = nil
41
+ }
40
42
  end
41
43
 
42
44
  # Sets the name property.
@@ -50,8 +52,9 @@ module ApplicationInsights
50
52
 
51
53
  # Gets the parent_id property.
52
54
  def parent_id
53
- return @values['ai.operation.parentId'] if @values.key?('ai.operation.parentId')
54
- @defaults['ai.operation.parentId']
55
+ @values.fetch('ai.operation.parentId') {
56
+ @values['ai.operation.parentId'] = nil
57
+ }
55
58
  end
56
59
 
57
60
  # Sets the parent_id property.
@@ -65,8 +68,9 @@ module ApplicationInsights
65
68
 
66
69
  # Gets the root_id property.
67
70
  def root_id
68
- return @values['ai.operation.rootId'] if @values.key?('ai.operation.rootId')
69
- @defaults['ai.operation.rootId']
71
+ @values.fetch('ai.operation.rootId') {
72
+ @values['ai.operation.rootId'] = nil
73
+ }
70
74
  end
71
75
 
72
76
  # Sets the root_id property.
@@ -34,8 +34,9 @@ module ApplicationInsights
34
34
 
35
35
  # Gets the url property.
36
36
  def url
37
- return @values['url'] if @values.key?('url')
38
- @defaults['url']
37
+ @values.fetch('url') {
38
+ @values['url'] = nil
39
+ }
39
40
  end
40
41
 
41
42
  # Sets the url property.
@@ -59,8 +60,9 @@ module ApplicationInsights
59
60
 
60
61
  # Gets the duration property.
61
62
  def duration
62
- return @values['duration'] if @values.key?('duration')
63
- @defaults['duration']
63
+ @values.fetch('duration') {
64
+ @values['duration'] = nil
65
+ }
64
66
  end
65
67
 
66
68
  # Sets the duration property.
@@ -74,9 +76,9 @@ module ApplicationInsights
74
76
 
75
77
  # Gets the properties property.
76
78
  def properties
77
- return @values['properties'] if @values.key?('properties')
78
- @values['properties'] = {}
79
- @values['properties']
79
+ @values.fetch('properties') {
80
+ @values['properties'] = {}
81
+ }
80
82
  end
81
83
 
82
84
  # Sets the properties property.
@@ -90,9 +92,9 @@ module ApplicationInsights
90
92
 
91
93
  # Gets the measurements property.
92
94
  def measurements
93
- return @values['measurements'] if @values.key?('measurements')
94
- @values['measurements'] = {}
95
- @values['measurements']
95
+ @values.fetch('measurements') {
96
+ @values['measurements'] = {}
97
+ }
96
98
  end
97
99
 
98
100
  # Sets the measurements property.
@@ -59,8 +59,9 @@ module ApplicationInsights
59
59
 
60
60
  # Gets the kind property.
61
61
  def kind
62
- return @values['kind'] if @values.key?('kind')
63
- @defaults['kind']
62
+ @values.fetch('kind') {
63
+ @values['kind'] = DataPointType::MEASUREMENT
64
+ }
64
65
  end
65
66
 
66
67
  # Sets the kind property.
@@ -84,8 +85,9 @@ module ApplicationInsights
84
85
 
85
86
  # Gets the count property.
86
87
  def count
87
- return @values['count'] if @values.key?('count')
88
- @defaults['count']
88
+ @values.fetch('count') {
89
+ @values['count'] = nil
90
+ }
89
91
  end
90
92
 
91
93
  # Sets the count property.
@@ -99,8 +101,9 @@ module ApplicationInsights
99
101
 
100
102
  # Gets the min property.
101
103
  def min
102
- return @values['min'] if @values.key?('min')
103
- @defaults['min']
104
+ @values.fetch('min') {
105
+ @values['min'] = nil
106
+ }
104
107
  end
105
108
 
106
109
  # Sets the min property.
@@ -114,8 +117,9 @@ module ApplicationInsights
114
117
 
115
118
  # Gets the max property.
116
119
  def max
117
- return @values['max'] if @values.key?('max')
118
- @defaults['max']
120
+ @values.fetch('max') {
121
+ @values['max'] = nil
122
+ }
119
123
  end
120
124
 
121
125
  # Sets the max property.
@@ -129,8 +133,9 @@ module ApplicationInsights
129
133
 
130
134
  # Gets the std_dev property.
131
135
  def std_dev
132
- return @values['stdDev'] if @values.key?('stdDev')
133
- @defaults['stdDev']
136
+ @values.fetch('stdDev') {
137
+ @values['stdDev'] = nil
138
+ }
134
139
  end
135
140
 
136
141
  # Sets the std_dev property.
@@ -154,8 +159,9 @@ module ApplicationInsights
154
159
 
155
160
  # Gets the success property.
156
161
  def success
157
- return @values['success'] if @values.key?('success')
158
- @defaults['success']
162
+ @values.fetch('success') {
163
+ @values['success'] = true
164
+ }
159
165
  end
160
166
 
161
167
  # Sets the success property.
@@ -169,8 +175,9 @@ module ApplicationInsights
169
175
 
170
176
  # Gets the async property.
171
177
  def async
172
- return @values['async'] if @values.key?('async')
173
- @defaults['async']
178
+ @values.fetch('async') {
179
+ @values['async'] = nil
180
+ }
174
181
  end
175
182
 
176
183
  # Sets the async property.
@@ -184,8 +191,9 @@ module ApplicationInsights
184
191
 
185
192
  # Gets the dependency_source property.
186
193
  def dependency_source
187
- return @values['dependencySource'] if @values.key?('dependencySource')
188
- @defaults['dependencySource']
194
+ @values.fetch('dependencySource') {
195
+ @values['dependencySource'] = DependencySourceType::UNDEFINED
196
+ }
189
197
  end
190
198
 
191
199
  # Sets the dependency_source property.
@@ -199,9 +207,9 @@ module ApplicationInsights
199
207
 
200
208
  # Gets the properties property.
201
209
  def properties
202
- return @values['properties'] if @values.key?('properties')
203
- @values['properties'] = {}
204
- @values['properties']
210
+ @values.fetch('properties') {
211
+ @values['properties'] = {}
212
+ }
205
213
  end
206
214
 
207
215
  # Sets the properties property.
@@ -53,8 +53,9 @@ module ApplicationInsights
53
53
 
54
54
  # Gets the name property.
55
55
  def name
56
- return @values['name'] if @values.key?('name')
57
- @defaults['name']
56
+ @values.fetch('name') {
57
+ @values['name'] = nil
58
+ }
58
59
  end
59
60
 
60
61
  # Sets the name property.
@@ -108,8 +109,9 @@ module ApplicationInsights
108
109
 
109
110
  # Gets the http_method property.
110
111
  def http_method
111
- return @values['httpMethod'] if @values.key?('httpMethod')
112
- @defaults['httpMethod']
112
+ @values.fetch('httpMethod') {
113
+ @values['httpMethod'] = nil
114
+ }
113
115
  end
114
116
 
115
117
  # Sets the http_method property.
@@ -123,8 +125,9 @@ module ApplicationInsights
123
125
 
124
126
  # Gets the url property.
125
127
  def url
126
- return @values['url'] if @values.key?('url')
127
- @defaults['url']
128
+ @values.fetch('url') {
129
+ @values['url'] = nil
130
+ }
128
131
  end
129
132
 
130
133
  # Sets the url property.
@@ -138,9 +141,9 @@ module ApplicationInsights
138
141
 
139
142
  # Gets the properties property.
140
143
  def properties
141
- return @values['properties'] if @values.key?('properties')
142
- @values['properties'] = {}
143
- @values['properties']
144
+ @values.fetch('properties') {
145
+ @values['properties'] = {}
146
+ }
144
147
  end
145
148
 
146
149
  # Sets the properties property.
@@ -154,9 +157,9 @@ module ApplicationInsights
154
157
 
155
158
  # Gets the measurements property.
156
159
  def measurements
157
- return @values['measurements'] if @values.key?('measurements')
158
- @values['measurements'] = {}
159
- @values['measurements']
160
+ @values.fetch('measurements') {
161
+ @values['measurements'] = {}
162
+ }
160
163
  end
161
164
 
162
165
  # Sets the measurements property.
@@ -19,8 +19,9 @@ module ApplicationInsights
19
19
 
20
20
  # Gets the id property.
21
21
  def id
22
- return @values['ai.session.id'] if @values.key?('ai.session.id')
23
- @defaults['ai.session.id']
22
+ @values.fetch('ai.session.id') {
23
+ @values['ai.session.id'] = nil
24
+ }
24
25
  end
25
26
 
26
27
  # Sets the id property.
@@ -34,8 +35,9 @@ module ApplicationInsights
34
35
 
35
36
  # Gets the is_first property.
36
37
  def is_first
37
- return @values['ai.session.isFirst'] if @values.key?('ai.session.isFirst')
38
- @defaults['ai.session.isFirst']
38
+ @values.fetch('ai.session.isFirst') {
39
+ @values['ai.session.isFirst'] = nil
40
+ }
39
41
  end
40
42
 
41
43
  # Sets the is_first property.
@@ -49,8 +51,9 @@ module ApplicationInsights
49
51
 
50
52
  # Gets the is_new property.
51
53
  def is_new
52
- return @values['ai.session.isNew'] if @values.key?('ai.session.isNew')
53
- @defaults['ai.session.isNew']
54
+ @values.fetch('ai.session.isNew') {
55
+ @values['ai.session.isNew'] = nil
56
+ }
54
57
  end
55
58
 
56
59
  # Sets the is_new property.
@@ -43,8 +43,9 @@ module ApplicationInsights
43
43
 
44
44
  # Gets the assembly property.
45
45
  def assembly
46
- return @values['assembly'] if @values.key?('assembly')
47
- @defaults['assembly']
46
+ @values.fetch('assembly') {
47
+ @values['assembly'] = nil
48
+ }
48
49
  end
49
50
 
50
51
  # Sets the assembly property.
@@ -58,8 +59,9 @@ module ApplicationInsights
58
59
 
59
60
  # Gets the file_name property.
60
61
  def file_name
61
- return @values['fileName'] if @values.key?('fileName')
62
- @defaults['fileName']
62
+ @values.fetch('fileName') {
63
+ @values['fileName'] = nil
64
+ }
63
65
  end
64
66
 
65
67
  # Sets the file_name property.
@@ -73,8 +75,9 @@ module ApplicationInsights
73
75
 
74
76
  # Gets the line property.
75
77
  def line
76
- return @values['line'] if @values.key?('line')
77
- @defaults['line']
78
+ @values.fetch('line') {
79
+ @values['line'] = nil
80
+ }
78
81
  end
79
82
 
80
83
  # Sets the line property.
@@ -20,8 +20,9 @@ module ApplicationInsights
20
20
 
21
21
  # Gets the account_acquisition_date property.
22
22
  def account_acquisition_date
23
- return @values['ai.user.accountAcquisitionDate'] if @values.key?('ai.user.accountAcquisitionDate')
24
- @defaults['ai.user.accountAcquisitionDate']
23
+ @values.fetch('ai.user.accountAcquisitionDate') {
24
+ @values['ai.user.accountAcquisitionDate'] = nil
25
+ }
25
26
  end
26
27
 
27
28
  # Sets the account_acquisition_date property.
@@ -35,8 +36,9 @@ module ApplicationInsights
35
36
 
36
37
  # Gets the account_id property.
37
38
  def account_id
38
- return @values['ai.user.accountId'] if @values.key?('ai.user.accountId')
39
- @defaults['ai.user.accountId']
39
+ @values.fetch('ai.user.accountId') {
40
+ @values['ai.user.accountId'] = nil
41
+ }
40
42
  end
41
43
 
42
44
  # Sets the account_id property.
@@ -50,8 +52,9 @@ module ApplicationInsights
50
52
 
51
53
  # Gets the user_agent property.
52
54
  def user_agent
53
- return @values['ai.user.userAgent'] if @values.key?('ai.user.userAgent')
54
- @defaults['ai.user.userAgent']
55
+ @values.fetch('ai.user.userAgent') {
56
+ @values['ai.user.userAgent'] = nil
57
+ }
55
58
  end
56
59
 
57
60
  # Sets the user_agent property.
@@ -65,8 +68,9 @@ module ApplicationInsights
65
68
 
66
69
  # Gets the id property.
67
70
  def id
68
- return @values['ai.user.id'] if @values.key?('ai.user.id')
69
- @defaults['ai.user.id']
71
+ @values.fetch('ai.user.id') {
72
+ @values['ai.user.id'] = nil
73
+ }
70
74
  end
71
75
 
72
76
  # Sets the id property.
@@ -0,0 +1,64 @@
1
+ require_relative 'queue_base'
2
+ require 'thread'
3
+
4
+ module ApplicationInsights
5
+ module Channel
6
+ # An event class that allows simple cross-thread signalling.
7
+ #
8
+ # An object of this type managers an internal flag that can be set to true via the {#set} method and reset via the
9
+ # {#clear} method. Calling the {#wait} method will block until the flag is set to true.
10
+ # @example
11
+ # require 'application_insights'
12
+ # require 'thread'
13
+ # event = ApplicationInsights::Channel::Event.new
14
+ # Thread.new do
15
+ # sleep 1
16
+ # event.set
17
+ # end
18
+ # puts 'Main screen turn on.'
19
+ # result = event.wait
20
+ # puts 'All your base are belong to us.'
21
+ class Event
22
+ # Initializes a new instance of the class.
23
+ def initialize
24
+ @mutex = Mutex.new
25
+ @condition_variable = ConditionVariable.new
26
+ @signal = false
27
+ end
28
+
29
+ # The signal value for this object. Note that the value of this property is not synchronized
30
+ # with respect to {#set} and {#clear} meaning that it could return false positives or negatives.
31
+ # @return [Boolean] the signal value.
32
+ attr_reader :signal
33
+
34
+ # Sets the internal flag to true. Calling this method will also cause all waiting threads to awaken.
35
+ def set
36
+ @mutex.synchronize do
37
+ @signal = true
38
+ @condition_variable.broadcast
39
+ end
40
+ end
41
+
42
+ # Sets the internal flag to false.
43
+ def clear
44
+ @mutex.synchronize do
45
+ @signal = false
46
+ end
47
+ end
48
+
49
+ # Calling this method will block until the internal flag is set to true. If the flag is set to true before calling
50
+ # this method, we will return immediately. If the timeout parameter is specified, the method will unblock after the
51
+ # specified number of seconds.
52
+ # @param [Fixnum] timeout the timeout for the operation in seconds.
53
+ # @return [Boolean] the value of the internal flag on exit.
54
+ def wait(timeout=nil)
55
+ @mutex.synchronize do
56
+ if @signal == false
57
+ @condition_variable.wait @mutex, (timeout == nil) ? nil : timeout
58
+ end
59
+ @signal
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end