application_insights 0.5.3 → 0.5.4
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.
- checksums.yaml +6 -14
- data/.travis.yml +21 -9
- data/CONTRIBUTING.md +30 -0
- data/Gemfile +4 -4
- data/LICENSE.txt +11 -11
- data/README.md +13 -14
- data/Rakefile +14 -14
- data/application_insights.gemspec +28 -29
- data/lib/application_insights.rb +9 -9
- data/lib/application_insights/channel/asynchronous_queue.rb +58 -51
- data/lib/application_insights/channel/asynchronous_sender.rb +132 -123
- data/lib/application_insights/channel/contracts/application.rb +14 -53
- data/lib/application_insights/channel/contracts/cloud.rb +14 -0
- data/lib/application_insights/channel/contracts/data.rb +14 -48
- data/lib/application_insights/channel/contracts/data_point.rb +24 -130
- data/lib/application_insights/channel/contracts/data_point_type.rb +7 -16
- data/lib/application_insights/channel/contracts/dependency_kind.rb +9 -19
- data/lib/application_insights/channel/contracts/dependency_source_type.rb +9 -19
- data/lib/application_insights/channel/contracts/device.rb +28 -257
- data/lib/application_insights/channel/contracts/envelope.rb +40 -266
- data/lib/application_insights/channel/contracts/event_data.rb +28 -77
- data/lib/application_insights/channel/contracts/exception_data.rb +37 -140
- data/lib/application_insights/channel/contracts/exception_details.rb +28 -129
- data/lib/application_insights/channel/contracts/internal.rb +14 -53
- data/lib/application_insights/channel/contracts/json_serializable.rb +59 -59
- data/lib/application_insights/channel/contracts/location.rb +16 -36
- data/lib/application_insights/channel/contracts/message_data.rb +24 -77
- data/lib/application_insights/channel/contracts/metric_data.rb +27 -60
- data/lib/application_insights/channel/contracts/operation.rb +19 -121
- data/lib/application_insights/channel/contracts/page_view_data.rb +30 -111
- data/lib/application_insights/channel/contracts/remote_dependency_data.rb +56 -260
- data/lib/application_insights/channel/contracts/request_data.rb +36 -176
- data/lib/application_insights/channel/contracts/session.rb +15 -70
- data/lib/application_insights/channel/contracts/severity_level.rb +13 -25
- data/lib/application_insights/channel/contracts/stack_frame.rb +17 -94
- data/lib/application_insights/channel/contracts/user.rb +19 -104
- data/lib/application_insights/channel/event.rb +68 -64
- data/lib/application_insights/channel/queue_base.rb +65 -62
- data/lib/application_insights/channel/sender_base.rb +79 -72
- data/lib/application_insights/channel/synchronous_queue.rb +45 -39
- data/lib/application_insights/channel/synchronous_sender.rb +17 -15
- data/lib/application_insights/channel/telemetry_channel.rb +120 -102
- data/lib/application_insights/channel/telemetry_context.rb +85 -68
- data/lib/application_insights/rack/track_request.rb +87 -84
- data/lib/application_insights/telemetry_client.rb +229 -217
- data/lib/application_insights/unhandled_exception.rb +49 -47
- data/lib/application_insights/version.rb +3 -3
- data/test/application_insights.rb +8 -9
- data/test/application_insights/channel/contracts/test_application.rb +44 -44
- data/test/application_insights/channel/contracts/test_cloud.rb +44 -0
- data/test/application_insights/channel/contracts/test_data.rb +44 -44
- data/test/application_insights/channel/contracts/test_data_point.rb +109 -109
- data/test/application_insights/channel/contracts/test_device.rb +200 -200
- data/test/application_insights/channel/contracts/test_envelope.rb +209 -209
- data/test/application_insights/channel/contracts/test_event_data.rb +62 -62
- data/test/application_insights/channel/contracts/test_exception_data.rb +111 -111
- data/test/application_insights/channel/contracts/test_exception_details.rb +106 -106
- data/test/application_insights/channel/contracts/test_internal.rb +44 -44
- data/test/application_insights/channel/contracts/test_location.rb +70 -31
- data/test/application_insights/channel/contracts/test_message_data.rb +66 -66
- data/test/application_insights/channel/contracts/test_metric_data.rb +50 -50
- data/test/application_insights/channel/contracts/test_operation.rb +109 -96
- data/test/application_insights/channel/contracts/test_page_view_data.rb +88 -88
- data/test/application_insights/channel/contracts/test_remote_dependency_data.rb +209 -209
- data/test/application_insights/channel/contracts/test_request_data.rb +153 -153
- data/test/application_insights/channel/contracts/test_session.rb +57 -57
- data/test/application_insights/channel/contracts/test_stack_frame.rb +83 -83
- data/test/application_insights/channel/contracts/test_user.rb +96 -83
- data/test/application_insights/channel/test_asynchronous_queue.rb +47 -47
- data/test/application_insights/channel/test_asynchronous_sender.rb +80 -80
- data/test/application_insights/channel/test_event.rb +52 -52
- data/test/application_insights/channel/test_queue_base.rb +88 -88
- data/test/application_insights/channel/test_sender_base.rb +87 -87
- data/test/application_insights/channel/test_synchronous_queue.rb +27 -27
- data/test/application_insights/channel/test_synchronous_sender.rb +10 -10
- data/test/application_insights/channel/test_telemetry_channel.rb +126 -102
- data/test/application_insights/channel/test_telemetry_context.rb +82 -74
- data/test/application_insights/mock_sender.rb +37 -37
- data/test/application_insights/rack/test_track_request.rb +142 -139
- data/test/application_insights/test_telemetry_client.rb +133 -123
- data/test/application_insights/test_unhandled_exception.rb +23 -24
- metadata +23 -33
@@ -1,89 +1,89 @@
|
|
1
|
-
require_relative '../../../lib/application_insights/channel/queue_base'
|
2
|
-
require_relative '../../../lib/application_insights/channel/sender_base'
|
3
|
-
require 'test/unit'
|
4
|
-
|
5
|
-
include ApplicationInsights::Channel
|
6
|
-
|
7
|
-
class TestQueueBase < Test::Unit::TestCase
|
8
|
-
def test_initialize
|
9
|
-
sender = SenderBase.new 'http://tempuri.org'
|
10
|
-
item = QueueBase.new sender
|
11
|
-
assert_equal sender.queue, item
|
12
|
-
assert_equal 500, item.max_queue_length
|
13
|
-
assert_equal sender, item.sender
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_max_queue_length_works_as_expected
|
17
|
-
sender = SenderBase.new 'http://tempuri.org'
|
18
|
-
item = QueueBase.new sender
|
19
|
-
assert_equal 500, item.max_queue_length
|
20
|
-
item.max_queue_length = 42
|
21
|
-
assert_equal 42, item.max_queue_length
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_sender_works_as_expected
|
25
|
-
sender = SenderBase.new 'http://tempuri.org'
|
26
|
-
item = QueueBase.new sender
|
27
|
-
assert_equal sender, item.sender
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_push_will_not_enqueue_nil
|
31
|
-
sender = SenderBase.new 'http://tempuri.org'
|
32
|
-
item = QueueBase.new sender
|
33
|
-
queue = item.instance_variable_get('@queue')
|
34
|
-
item.push nil
|
35
|
-
assert queue.empty?
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_push_works_as_expected
|
39
|
-
sender = SenderBase.new 'http://tempuri.org'
|
40
|
-
item = MockQueueBase.new sender
|
41
|
-
item.max_queue_length = 2
|
42
|
-
queue = item.instance_variable_get('@queue')
|
43
|
-
[[7, 0], [8, 1], [9, 2]].each do |i, count|
|
44
|
-
item.push i
|
45
|
-
assert_equal count, item.flush_count
|
46
|
-
end
|
47
|
-
assert_equal 3, queue.length
|
48
|
-
temp = []
|
49
|
-
queue.length.times do |i|
|
50
|
-
temp.push queue.pop
|
51
|
-
end
|
52
|
-
assert_equal [7, 8, 9], temp
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_pop_works_as_expected
|
56
|
-
sender = SenderBase.new 'http://tempuri.org'
|
57
|
-
item = QueueBase.new sender
|
58
|
-
queue = item.instance_variable_get('@queue')
|
59
|
-
[7, 8, 9].each do |i|
|
60
|
-
queue.push i
|
61
|
-
end
|
62
|
-
[7, 8, 9, nil].each do |i|
|
63
|
-
assert_equal i, item.pop
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_empty_works_as_expected
|
68
|
-
sender = SenderBase.new 'http://tempuri.org'
|
69
|
-
queue = QueueBase.new sender
|
70
|
-
assert_equal true, queue.empty?
|
71
|
-
queue.push 1
|
72
|
-
assert_equal false, queue.empty?
|
73
|
-
queue.pop
|
74
|
-
assert_equal true, queue.empty?
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
class MockQueueBase < QueueBase
|
79
|
-
def initialize(sender)
|
80
|
-
super sender
|
81
|
-
@flush_count = 0
|
82
|
-
end
|
83
|
-
|
84
|
-
attr_accessor :flush_count
|
85
|
-
|
86
|
-
def flush
|
87
|
-
@flush_count += 1
|
88
|
-
end
|
1
|
+
require_relative '../../../lib/application_insights/channel/queue_base'
|
2
|
+
require_relative '../../../lib/application_insights/channel/sender_base'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
include ApplicationInsights::Channel
|
6
|
+
|
7
|
+
class TestQueueBase < Test::Unit::TestCase
|
8
|
+
def test_initialize
|
9
|
+
sender = SenderBase.new 'http://tempuri.org'
|
10
|
+
item = QueueBase.new sender
|
11
|
+
assert_equal sender.queue, item
|
12
|
+
assert_equal 500, item.max_queue_length
|
13
|
+
assert_equal sender, item.sender
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_max_queue_length_works_as_expected
|
17
|
+
sender = SenderBase.new 'http://tempuri.org'
|
18
|
+
item = QueueBase.new sender
|
19
|
+
assert_equal 500, item.max_queue_length
|
20
|
+
item.max_queue_length = 42
|
21
|
+
assert_equal 42, item.max_queue_length
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_sender_works_as_expected
|
25
|
+
sender = SenderBase.new 'http://tempuri.org'
|
26
|
+
item = QueueBase.new sender
|
27
|
+
assert_equal sender, item.sender
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_push_will_not_enqueue_nil
|
31
|
+
sender = SenderBase.new 'http://tempuri.org'
|
32
|
+
item = QueueBase.new sender
|
33
|
+
queue = item.instance_variable_get('@queue')
|
34
|
+
item.push nil
|
35
|
+
assert queue.empty?
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_push_works_as_expected
|
39
|
+
sender = SenderBase.new 'http://tempuri.org'
|
40
|
+
item = MockQueueBase.new sender
|
41
|
+
item.max_queue_length = 2
|
42
|
+
queue = item.instance_variable_get('@queue')
|
43
|
+
[[7, 0], [8, 1], [9, 2]].each do |i, count|
|
44
|
+
item.push i
|
45
|
+
assert_equal count, item.flush_count
|
46
|
+
end
|
47
|
+
assert_equal 3, queue.length
|
48
|
+
temp = []
|
49
|
+
queue.length.times do |i|
|
50
|
+
temp.push queue.pop
|
51
|
+
end
|
52
|
+
assert_equal [7, 8, 9], temp
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_pop_works_as_expected
|
56
|
+
sender = SenderBase.new 'http://tempuri.org'
|
57
|
+
item = QueueBase.new sender
|
58
|
+
queue = item.instance_variable_get('@queue')
|
59
|
+
[7, 8, 9].each do |i|
|
60
|
+
queue.push i
|
61
|
+
end
|
62
|
+
[7, 8, 9, nil].each do |i|
|
63
|
+
assert_equal i, item.pop
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_empty_works_as_expected
|
68
|
+
sender = SenderBase.new 'http://tempuri.org'
|
69
|
+
queue = QueueBase.new sender
|
70
|
+
assert_equal true, queue.empty?
|
71
|
+
queue.push 1
|
72
|
+
assert_equal false, queue.empty?
|
73
|
+
queue.pop
|
74
|
+
assert_equal true, queue.empty?
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class MockQueueBase < QueueBase
|
79
|
+
def initialize(sender)
|
80
|
+
super sender
|
81
|
+
@flush_count = 0
|
82
|
+
end
|
83
|
+
|
84
|
+
attr_accessor :flush_count
|
85
|
+
|
86
|
+
def flush
|
87
|
+
@flush_count += 1
|
88
|
+
end
|
89
89
|
end
|
@@ -1,87 +1,87 @@
|
|
1
|
-
require_relative '../../../lib/application_insights/channel/queue_base'
|
2
|
-
require_relative '../../../lib/application_insights/channel/sender_base'
|
3
|
-
require 'socket'
|
4
|
-
require 'test/unit'
|
5
|
-
require 'thread'
|
6
|
-
|
7
|
-
include ApplicationInsights::Channel
|
8
|
-
|
9
|
-
class TestSenderBase < Test::Unit::TestCase
|
10
|
-
def test_initialize
|
11
|
-
sender = SenderBase.new 'http://tempuri.org'
|
12
|
-
assert_equal 'http://tempuri.org', sender.service_endpoint_uri
|
13
|
-
assert_nil sender.queue
|
14
|
-
assert_equal 100, sender.send_buffer_size
|
15
|
-
end
|
16
|
-
|
17
|
-
def
|
18
|
-
sender = SenderBase.new 'http://tempuri.org'
|
19
|
-
assert_equal 'http://tempuri.org',
|
20
|
-
|
21
|
-
assert_equal 'http://live.com',
|
22
|
-
end
|
23
|
-
|
24
|
-
def
|
25
|
-
sender = SenderBase.new 'http://tempuri.org'
|
26
|
-
assert_nil sender.queue
|
27
|
-
temp = Object.new
|
28
|
-
sender.queue = temp
|
29
|
-
assert_equal temp, sender.queue
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_send_buffer_size_works_as_expected
|
33
|
-
sender = SenderBase.new 'http://tempuri.org'
|
34
|
-
assert_equal 100, sender.send_buffer_size
|
35
|
-
sender.send_buffer_size = 42
|
36
|
-
assert_equal 42, sender.send_buffer_size
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_send_works_as_expected_with_400_code
|
40
|
-
thread, port = execute_server '400 BadRequest'
|
41
|
-
sender = SenderBase.new 'http://localhost:' + port.to_s + '/track'
|
42
|
-
sender.queue = []
|
43
|
-
sender.send([1, 2])
|
44
|
-
thread.join
|
45
|
-
assert_equal [], sender.queue
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_send_works_as_expected_with_500_code
|
49
|
-
thread, port = execute_server '500 InternalServerError'
|
50
|
-
sender = SenderBase.new 'http://localhost:' + port.to_s + '/track'
|
51
|
-
sender.queue = []
|
52
|
-
sender.send([1, 2])
|
53
|
-
thread.join
|
54
|
-
assert_equal [], sender.queue
|
55
|
-
end
|
56
|
-
|
57
|
-
def execute_server(code)
|
58
|
-
port = 50000 + Random.rand(10000)
|
59
|
-
thread = Thread.new {
|
60
|
-
server = TCPServer.new(port)
|
61
|
-
client = server.accept
|
62
|
-
request = ''
|
63
|
-
read_buffer_size = 64
|
64
|
-
while
|
65
|
-
temp = client.recv(read_buffer_size)
|
66
|
-
request += temp
|
67
|
-
break if temp.length < read_buffer_size
|
68
|
-
end
|
69
|
-
request = request.split(/\n/)[-1]
|
70
|
-
response = request
|
71
|
-
headers = [
|
72
|
-
"HTTP/1.1 " + code,
|
73
|
-
"Content-Type: application/json",
|
74
|
-
"Content-Length: #{response.length}\r\n\r\n"
|
75
|
-
].join("\r\n")
|
76
|
-
client.puts headers
|
77
|
-
client.puts response
|
78
|
-
client.close
|
79
|
-
}
|
80
|
-
|
81
|
-
while thread.status != 'sleep'
|
82
|
-
sleep 0.1
|
83
|
-
end
|
84
|
-
|
85
|
-
return thread, port
|
86
|
-
end
|
87
|
-
end
|
1
|
+
require_relative '../../../lib/application_insights/channel/queue_base'
|
2
|
+
require_relative '../../../lib/application_insights/channel/sender_base'
|
3
|
+
require 'socket'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'thread'
|
6
|
+
|
7
|
+
include ApplicationInsights::Channel
|
8
|
+
|
9
|
+
class TestSenderBase < Test::Unit::TestCase
|
10
|
+
def test_initialize
|
11
|
+
sender = SenderBase.new 'http://tempuri.org'
|
12
|
+
assert_equal 'http://tempuri.org', sender.service_endpoint_uri
|
13
|
+
assert_nil sender.queue
|
14
|
+
assert_equal 100, sender.send_buffer_size
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_service_endpoint_uri
|
18
|
+
sender = SenderBase.new 'http://tempuri.org'
|
19
|
+
assert_equal 'http://tempuri.org', sender.service_endpoint_uri
|
20
|
+
sender.service_endpoint_uri = 'http://live.com'
|
21
|
+
assert_equal 'http://live.com', sender.service_endpoint_uri
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_sender_queue_attribute
|
25
|
+
sender = SenderBase.new 'http://tempuri.org'
|
26
|
+
assert_nil sender.queue
|
27
|
+
temp = Object.new
|
28
|
+
sender.queue = temp
|
29
|
+
assert_equal temp, sender.queue
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_send_buffer_size_works_as_expected
|
33
|
+
sender = SenderBase.new 'http://tempuri.org'
|
34
|
+
assert_equal 100, sender.send_buffer_size
|
35
|
+
sender.send_buffer_size = 42
|
36
|
+
assert_equal 42, sender.send_buffer_size
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_send_works_as_expected_with_400_code
|
40
|
+
thread, port = execute_server '400 BadRequest'
|
41
|
+
sender = SenderBase.new 'http://localhost:' + port.to_s + '/track'
|
42
|
+
sender.queue = []
|
43
|
+
sender.send([1, 2])
|
44
|
+
thread.join
|
45
|
+
assert_equal [], sender.queue
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_send_works_as_expected_with_500_code
|
49
|
+
thread, port = execute_server '500 InternalServerError'
|
50
|
+
sender = SenderBase.new 'http://localhost:' + port.to_s + '/track'
|
51
|
+
sender.queue = []
|
52
|
+
sender.send([1, 2])
|
53
|
+
thread.join
|
54
|
+
assert_equal [], sender.queue
|
55
|
+
end
|
56
|
+
|
57
|
+
def execute_server(code)
|
58
|
+
port = 50000 + Random.rand(10000)
|
59
|
+
thread = Thread.new {
|
60
|
+
server = TCPServer.new(port)
|
61
|
+
client = server.accept
|
62
|
+
request = ''
|
63
|
+
read_buffer_size = 64
|
64
|
+
while true
|
65
|
+
temp = client.recv(read_buffer_size)
|
66
|
+
request += temp
|
67
|
+
break if temp.length < read_buffer_size
|
68
|
+
end
|
69
|
+
request = request.split(/\n/)[-1]
|
70
|
+
response = request
|
71
|
+
headers = [
|
72
|
+
"HTTP/1.1 " + code,
|
73
|
+
"Content-Type: application/json",
|
74
|
+
"Content-Length: #{response.length}\r\n\r\n"
|
75
|
+
].join("\r\n")
|
76
|
+
client.puts headers
|
77
|
+
client.puts response
|
78
|
+
client.close
|
79
|
+
}
|
80
|
+
|
81
|
+
while thread.status != 'sleep'
|
82
|
+
sleep 0.1
|
83
|
+
end
|
84
|
+
|
85
|
+
return thread, port
|
86
|
+
end
|
87
|
+
end
|
@@ -1,28 +1,28 @@
|
|
1
|
-
require_relative '../../../lib/application_insights/channel/sender_base'
|
2
|
-
require_relative '../../../lib/application_insights/channel/synchronous_queue'
|
3
|
-
require_relative '../mock_sender'
|
4
|
-
require 'test/unit'
|
5
|
-
|
6
|
-
include ApplicationInsights::Channel
|
7
|
-
|
8
|
-
class TestSynchronousQueue < Test::Unit::TestCase
|
9
|
-
def test_initialize
|
10
|
-
SynchronousQueue.new(MockSynchronousSender.new)
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_flush_works_as_expected
|
14
|
-
sender = MockSynchronousSender.new
|
15
|
-
sender.send_buffer_size = 2
|
16
|
-
queue = SynchronousQueue.new sender
|
17
|
-
queue.max_queue_length = 3
|
18
|
-
(1..7).to_a.each do |i|
|
19
|
-
queue.push i
|
20
|
-
end
|
21
|
-
assert_equal [[1, 2], [3], [4, 5], [6]], sender.buffer
|
22
|
-
temp = []
|
23
|
-
queue.instance_variable_get('@queue').length.times do |i|
|
24
|
-
temp.push queue.instance_variable_get('@queue').pop
|
25
|
-
end
|
26
|
-
assert_equal [7], temp
|
27
|
-
end
|
1
|
+
require_relative '../../../lib/application_insights/channel/sender_base'
|
2
|
+
require_relative '../../../lib/application_insights/channel/synchronous_queue'
|
3
|
+
require_relative '../mock_sender'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
include ApplicationInsights::Channel
|
7
|
+
|
8
|
+
class TestSynchronousQueue < Test::Unit::TestCase
|
9
|
+
def test_initialize
|
10
|
+
SynchronousQueue.new(MockSynchronousSender.new)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_flush_works_as_expected
|
14
|
+
sender = MockSynchronousSender.new
|
15
|
+
sender.send_buffer_size = 2
|
16
|
+
queue = SynchronousQueue.new sender
|
17
|
+
queue.max_queue_length = 3
|
18
|
+
(1..7).to_a.each do |i|
|
19
|
+
queue.push i
|
20
|
+
end
|
21
|
+
assert_equal [[1, 2], [3], [4, 5], [6]], sender.buffer
|
22
|
+
temp = []
|
23
|
+
queue.instance_variable_get('@queue').length.times do |i|
|
24
|
+
temp.push queue.instance_variable_get('@queue').pop
|
25
|
+
end
|
26
|
+
assert_equal [7], temp
|
27
|
+
end
|
28
28
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require_relative '../../../lib/application_insights/channel/synchronous_sender'
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
|
-
include ApplicationInsights::Channel
|
5
|
-
|
6
|
-
class TestSynchronousSender < Test::Unit::TestCase
|
7
|
-
def test_initialize
|
8
|
-
sender = SynchronousSender.new
|
9
|
-
assert_equal 'https://dc.services.visualstudio.com/v2/track', sender.service_endpoint_uri
|
10
|
-
end
|
1
|
+
require_relative '../../../lib/application_insights/channel/synchronous_sender'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
include ApplicationInsights::Channel
|
5
|
+
|
6
|
+
class TestSynchronousSender < Test::Unit::TestCase
|
7
|
+
def test_initialize
|
8
|
+
sender = SynchronousSender.new
|
9
|
+
assert_equal 'https://dc.services.visualstudio.com/v2/track', sender.service_endpoint_uri
|
10
|
+
end
|
11
11
|
end
|
@@ -1,102 +1,126 @@
|
|
1
|
-
require_relative '../../../lib/application_insights/channel/telemetry_channel'
|
2
|
-
require_relative '../../../lib/application_insights/channel/telemetry_context'
|
3
|
-
require_relative '../../../lib/application_insights/channel/synchronous_queue'
|
4
|
-
require_relative '../../../lib/application_insights/channel/synchronous_sender'
|
5
|
-
require 'test/unit'
|
6
|
-
|
7
|
-
include ApplicationInsights::Channel
|
8
|
-
|
9
|
-
class TestTelemetryChannel < Test::Unit::TestCase
|
10
|
-
def test_initialize
|
11
|
-
channel = TelemetryChannel.new
|
12
|
-
assert_not_nil channel.context
|
13
|
-
assert_not_nil channel.queue
|
14
|
-
assert_not_nil channel.sender
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_context_works_as_expected
|
18
|
-
context = TelemetryContext.new
|
19
|
-
channel = TelemetryChannel.new
|
20
|
-
assert_not_nil channel.context
|
21
|
-
assert_not_same context, channel.context
|
22
|
-
channel = TelemetryChannel.new context
|
23
|
-
assert_same context, channel.context
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_queue_works_as_expected
|
27
|
-
queue = SynchronousQueue.new SynchronousSender.new
|
28
|
-
channel = TelemetryChannel.new
|
29
|
-
assert_not_nil channel.queue
|
30
|
-
assert_not_same queue, channel.queue
|
31
|
-
channel = TelemetryChannel.new nil, queue
|
32
|
-
assert_same queue, channel.queue
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_sender_works_as_expected
|
36
|
-
queue = SynchronousQueue.new SynchronousSender.new
|
37
|
-
channel = TelemetryChannel.new
|
38
|
-
assert_not_nil channel.sender
|
39
|
-
assert_not_same queue.sender, channel.sender
|
40
|
-
channel = TelemetryChannel.new nil, queue
|
41
|
-
assert_same queue.sender, channel.sender
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_flush_works_as_expected
|
45
|
-
queue = MockTelemetryChannelQueue.new SynchronousSender.new
|
46
|
-
channel = TelemetryChannel.new nil, queue
|
47
|
-
assert_equal 0, queue.flush_count
|
48
|
-
channel.flush
|
49
|
-
assert_equal 1, queue.flush_count
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_write_works_as_expected
|
53
|
-
queue = MockTelemetryChannelQueue.new SynchronousSender.new
|
54
|
-
context = TelemetryContext.new
|
55
|
-
context.instrumentation_key = 'instrumentation key'
|
56
|
-
channel = TelemetryChannel.new context, queue
|
57
|
-
expected = MockTelemetryItemData.new
|
58
|
-
channel.write expected
|
59
|
-
assert_equal 1, queue.queue.count
|
60
|
-
actual = queue.queue[0]
|
61
|
-
assert_not_nil actual
|
62
|
-
assert_equal 1, actual.ver
|
63
|
-
assert_equal 100, actual.sample_rate
|
64
|
-
assert_equal 'Microsoft.ApplicationInsights.MockTelemetryItem', actual.name
|
65
|
-
assert_not_nil actual.time
|
66
|
-
assert_equal 'instrumentation key', actual.i_key
|
67
|
-
assert_not_nil actual.tags
|
68
|
-
assert_equal 1, actual.tags.count
|
69
|
-
assert_equal 'rb:'+ ApplicationInsights::VERSION, actual.tags['ai.internal.sdkVersion']
|
70
|
-
assert_not_nil actual.data
|
71
|
-
assert_equal 'MockTelemetryItemData', actual.data.base_type
|
72
|
-
assert_same expected, actual.data.base_data
|
73
|
-
end
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
1
|
+
require_relative '../../../lib/application_insights/channel/telemetry_channel'
|
2
|
+
require_relative '../../../lib/application_insights/channel/telemetry_context'
|
3
|
+
require_relative '../../../lib/application_insights/channel/synchronous_queue'
|
4
|
+
require_relative '../../../lib/application_insights/channel/synchronous_sender'
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
include ApplicationInsights::Channel
|
8
|
+
|
9
|
+
class TestTelemetryChannel < Test::Unit::TestCase
|
10
|
+
def test_initialize
|
11
|
+
channel = TelemetryChannel.new
|
12
|
+
assert_not_nil channel.context
|
13
|
+
assert_not_nil channel.queue
|
14
|
+
assert_not_nil channel.sender
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_context_works_as_expected
|
18
|
+
context = TelemetryContext.new
|
19
|
+
channel = TelemetryChannel.new
|
20
|
+
assert_not_nil channel.context
|
21
|
+
assert_not_same context, channel.context
|
22
|
+
channel = TelemetryChannel.new context
|
23
|
+
assert_same context, channel.context
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_queue_works_as_expected
|
27
|
+
queue = SynchronousQueue.new SynchronousSender.new
|
28
|
+
channel = TelemetryChannel.new
|
29
|
+
assert_not_nil channel.queue
|
30
|
+
assert_not_same queue, channel.queue
|
31
|
+
channel = TelemetryChannel.new nil, queue
|
32
|
+
assert_same queue, channel.queue
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_sender_works_as_expected
|
36
|
+
queue = SynchronousQueue.new SynchronousSender.new
|
37
|
+
channel = TelemetryChannel.new
|
38
|
+
assert_not_nil channel.sender
|
39
|
+
assert_not_same queue.sender, channel.sender
|
40
|
+
channel = TelemetryChannel.new nil, queue
|
41
|
+
assert_same queue.sender, channel.sender
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_flush_works_as_expected
|
45
|
+
queue = MockTelemetryChannelQueue.new SynchronousSender.new
|
46
|
+
channel = TelemetryChannel.new nil, queue
|
47
|
+
assert_equal 0, queue.flush_count
|
48
|
+
channel.flush
|
49
|
+
assert_equal 1, queue.flush_count
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_write_works_as_expected
|
53
|
+
queue = MockTelemetryChannelQueue.new SynchronousSender.new
|
54
|
+
context = TelemetryContext.new
|
55
|
+
context.instrumentation_key = 'instrumentation key'
|
56
|
+
channel = TelemetryChannel.new context, queue
|
57
|
+
expected = MockTelemetryItemData.new
|
58
|
+
channel.write expected
|
59
|
+
assert_equal 1, queue.queue.count
|
60
|
+
actual = queue.queue[0]
|
61
|
+
assert_not_nil actual
|
62
|
+
assert_equal 1, actual.ver
|
63
|
+
assert_equal 100, actual.sample_rate
|
64
|
+
assert_equal 'Microsoft.ApplicationInsights.MockTelemetryItem', actual.name
|
65
|
+
assert_not_nil actual.time
|
66
|
+
assert_equal 'instrumentation key', actual.i_key
|
67
|
+
assert_not_nil actual.tags
|
68
|
+
assert_equal 1, actual.tags.count
|
69
|
+
assert_equal 'rb:'+ ApplicationInsights::VERSION, actual.tags['ai.internal.sdkVersion']
|
70
|
+
assert_not_nil actual.data
|
71
|
+
assert_equal 'MockTelemetryItemData', actual.data.base_type
|
72
|
+
assert_same expected, actual.data.base_data
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_get_tags_works_as_expected
|
76
|
+
queue = MockTelemetryChannelQueue.new SynchronousSender.new
|
77
|
+
context = TelemetryContext.new
|
78
|
+
context.application.ver = 'ver'
|
79
|
+
context.cloud.role_name = 'role name'
|
80
|
+
context.device.id = 'device id'
|
81
|
+
context.user.id = 'user id'
|
82
|
+
context.session.id = 'session id'
|
83
|
+
context.location.ip = 'ip'
|
84
|
+
context.operation.id = 'operation id'
|
85
|
+
channel = TelemetryChannel.new context, queue
|
86
|
+
expected = MockTelemetryItemData.new
|
87
|
+
channel.write expected
|
88
|
+
|
89
|
+
assert_equal 1, queue.queue.count
|
90
|
+
tags = queue.queue[0].tags
|
91
|
+
assert_equal 'rb:'+ ApplicationInsights::VERSION, tags['ai.internal.sdkVersion']
|
92
|
+
assert_equal 'ver', tags['ai.application.ver']
|
93
|
+
assert_equal 'role name', tags['ai.cloud.role']
|
94
|
+
assert_equal 'device id', tags['ai.device.id']
|
95
|
+
assert_equal 'user id', tags['ai.user.id']
|
96
|
+
assert_equal 'session id', tags['ai.session.id']
|
97
|
+
assert_equal 'ip', tags['ai.location.ip']
|
98
|
+
assert_equal 'operation id', tags['ai.operation.id']
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class MockTelemetryItemData
|
103
|
+
def initialize
|
104
|
+
@properties = {}
|
105
|
+
end
|
106
|
+
|
107
|
+
attr_accessor :properties
|
108
|
+
end
|
109
|
+
|
110
|
+
class MockTelemetryChannelQueue < QueueBase
|
111
|
+
def initialize(sender)
|
112
|
+
super sender
|
113
|
+
@queue = []
|
114
|
+
@flush_count = 0
|
115
|
+
end
|
116
|
+
|
117
|
+
attr_accessor :flush_count, :queue
|
118
|
+
|
119
|
+
def push(data)
|
120
|
+
@queue.push data
|
121
|
+
end
|
122
|
+
|
123
|
+
def flush
|
124
|
+
@flush_count += 1
|
125
|
+
end
|
126
|
+
end
|