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.
Files changed (82) hide show
  1. checksums.yaml +6 -14
  2. data/.travis.yml +21 -9
  3. data/CONTRIBUTING.md +30 -0
  4. data/Gemfile +4 -4
  5. data/LICENSE.txt +11 -11
  6. data/README.md +13 -14
  7. data/Rakefile +14 -14
  8. data/application_insights.gemspec +28 -29
  9. data/lib/application_insights.rb +9 -9
  10. data/lib/application_insights/channel/asynchronous_queue.rb +58 -51
  11. data/lib/application_insights/channel/asynchronous_sender.rb +132 -123
  12. data/lib/application_insights/channel/contracts/application.rb +14 -53
  13. data/lib/application_insights/channel/contracts/cloud.rb +14 -0
  14. data/lib/application_insights/channel/contracts/data.rb +14 -48
  15. data/lib/application_insights/channel/contracts/data_point.rb +24 -130
  16. data/lib/application_insights/channel/contracts/data_point_type.rb +7 -16
  17. data/lib/application_insights/channel/contracts/dependency_kind.rb +9 -19
  18. data/lib/application_insights/channel/contracts/dependency_source_type.rb +9 -19
  19. data/lib/application_insights/channel/contracts/device.rb +28 -257
  20. data/lib/application_insights/channel/contracts/envelope.rb +40 -266
  21. data/lib/application_insights/channel/contracts/event_data.rb +28 -77
  22. data/lib/application_insights/channel/contracts/exception_data.rb +37 -140
  23. data/lib/application_insights/channel/contracts/exception_details.rb +28 -129
  24. data/lib/application_insights/channel/contracts/internal.rb +14 -53
  25. data/lib/application_insights/channel/contracts/json_serializable.rb +59 -59
  26. data/lib/application_insights/channel/contracts/location.rb +16 -36
  27. data/lib/application_insights/channel/contracts/message_data.rb +24 -77
  28. data/lib/application_insights/channel/contracts/metric_data.rb +27 -60
  29. data/lib/application_insights/channel/contracts/operation.rb +19 -121
  30. data/lib/application_insights/channel/contracts/page_view_data.rb +30 -111
  31. data/lib/application_insights/channel/contracts/remote_dependency_data.rb +56 -260
  32. data/lib/application_insights/channel/contracts/request_data.rb +36 -176
  33. data/lib/application_insights/channel/contracts/session.rb +15 -70
  34. data/lib/application_insights/channel/contracts/severity_level.rb +13 -25
  35. data/lib/application_insights/channel/contracts/stack_frame.rb +17 -94
  36. data/lib/application_insights/channel/contracts/user.rb +19 -104
  37. data/lib/application_insights/channel/event.rb +68 -64
  38. data/lib/application_insights/channel/queue_base.rb +65 -62
  39. data/lib/application_insights/channel/sender_base.rb +79 -72
  40. data/lib/application_insights/channel/synchronous_queue.rb +45 -39
  41. data/lib/application_insights/channel/synchronous_sender.rb +17 -15
  42. data/lib/application_insights/channel/telemetry_channel.rb +120 -102
  43. data/lib/application_insights/channel/telemetry_context.rb +85 -68
  44. data/lib/application_insights/rack/track_request.rb +87 -84
  45. data/lib/application_insights/telemetry_client.rb +229 -217
  46. data/lib/application_insights/unhandled_exception.rb +49 -47
  47. data/lib/application_insights/version.rb +3 -3
  48. data/test/application_insights.rb +8 -9
  49. data/test/application_insights/channel/contracts/test_application.rb +44 -44
  50. data/test/application_insights/channel/contracts/test_cloud.rb +44 -0
  51. data/test/application_insights/channel/contracts/test_data.rb +44 -44
  52. data/test/application_insights/channel/contracts/test_data_point.rb +109 -109
  53. data/test/application_insights/channel/contracts/test_device.rb +200 -200
  54. data/test/application_insights/channel/contracts/test_envelope.rb +209 -209
  55. data/test/application_insights/channel/contracts/test_event_data.rb +62 -62
  56. data/test/application_insights/channel/contracts/test_exception_data.rb +111 -111
  57. data/test/application_insights/channel/contracts/test_exception_details.rb +106 -106
  58. data/test/application_insights/channel/contracts/test_internal.rb +44 -44
  59. data/test/application_insights/channel/contracts/test_location.rb +70 -31
  60. data/test/application_insights/channel/contracts/test_message_data.rb +66 -66
  61. data/test/application_insights/channel/contracts/test_metric_data.rb +50 -50
  62. data/test/application_insights/channel/contracts/test_operation.rb +109 -96
  63. data/test/application_insights/channel/contracts/test_page_view_data.rb +88 -88
  64. data/test/application_insights/channel/contracts/test_remote_dependency_data.rb +209 -209
  65. data/test/application_insights/channel/contracts/test_request_data.rb +153 -153
  66. data/test/application_insights/channel/contracts/test_session.rb +57 -57
  67. data/test/application_insights/channel/contracts/test_stack_frame.rb +83 -83
  68. data/test/application_insights/channel/contracts/test_user.rb +96 -83
  69. data/test/application_insights/channel/test_asynchronous_queue.rb +47 -47
  70. data/test/application_insights/channel/test_asynchronous_sender.rb +80 -80
  71. data/test/application_insights/channel/test_event.rb +52 -52
  72. data/test/application_insights/channel/test_queue_base.rb +88 -88
  73. data/test/application_insights/channel/test_sender_base.rb +87 -87
  74. data/test/application_insights/channel/test_synchronous_queue.rb +27 -27
  75. data/test/application_insights/channel/test_synchronous_sender.rb +10 -10
  76. data/test/application_insights/channel/test_telemetry_channel.rb +126 -102
  77. data/test/application_insights/channel/test_telemetry_context.rb +82 -74
  78. data/test/application_insights/mock_sender.rb +37 -37
  79. data/test/application_insights/rack/test_track_request.rb +142 -139
  80. data/test/application_insights/test_telemetry_client.rb +133 -123
  81. data/test/application_insights/test_unhandled_exception.rb +23 -24
  82. metadata +23 -33
@@ -1,83 +1,96 @@
1
- require_relative '../../../../lib/application_insights/channel/contracts/user'
2
- require 'test/unit'
3
-
4
- include ApplicationInsights::Channel
5
-
6
- class TestUser < Test::Unit::TestCase
7
- def test_initialize
8
- item = Contracts::User.new
9
- assert_not_nil item
10
- end
11
-
12
- def test_account_acquisition_date_works_as_expected
13
- expected = 'Test string'
14
- item = Contracts::User.new
15
- item.account_acquisition_date = expected
16
- actual = item.account_acquisition_date
17
- assert_equal expected, actual
18
- expected = 'Other string'
19
- item.account_acquisition_date = expected
20
- actual = item.account_acquisition_date
21
- assert_equal expected, actual
22
- end
23
-
24
- def test_account_id_works_as_expected
25
- expected = 'Test string'
26
- item = Contracts::User.new
27
- item.account_id = expected
28
- actual = item.account_id
29
- assert_equal expected, actual
30
- expected = 'Other string'
31
- item.account_id = expected
32
- actual = item.account_id
33
- assert_equal expected, actual
34
- end
35
-
36
- def test_user_agent_works_as_expected
37
- expected = 'Test string'
38
- item = Contracts::User.new
39
- item.user_agent = expected
40
- actual = item.user_agent
41
- assert_equal expected, actual
42
- expected = 'Other string'
43
- item.user_agent = expected
44
- actual = item.user_agent
45
- assert_equal expected, actual
46
- end
47
-
48
- def test_id_works_as_expected
49
- expected = 'Test string'
50
- item = Contracts::User.new
51
- item.id = expected
52
- actual = item.id
53
- assert_equal expected, actual
54
- expected = 'Other string'
55
- item.id = expected
56
- actual = item.id
57
- assert_equal expected, actual
58
- end
59
-
60
- def test_store_region_works_as_expected
61
- expected = 'Test string'
62
- item = Contracts::User.new
63
- item.store_region = expected
64
- actual = item.store_region
65
- assert_equal expected, actual
66
- expected = 'Other string'
67
- item.store_region = expected
68
- actual = item.store_region
69
- assert_equal expected, actual
70
- end
71
-
72
- def test_to_json_works_as_expected
73
- item = Contracts::User.new
74
- item.account_acquisition_date = 'Test string'
75
- item.account_id = 'Test string'
76
- item.user_agent = 'Test string'
77
- item.id = 'Test string'
78
- item.store_region = 'Test string'
79
- actual = item.to_json
80
- expected = '{"ai.user.accountAcquisitionDate":"Test string","ai.user.accountId":"Test string","ai.user.userAgent":"Test string","ai.user.id":"Test string","ai.user.storeRegion":"Test string"}'
81
- assert_equal expected, actual
82
- end
83
- end
1
+ require_relative '../../../../lib/application_insights/channel/contracts/user'
2
+ require 'test/unit'
3
+
4
+ include ApplicationInsights::Channel
5
+
6
+ class TestUser < Test::Unit::TestCase
7
+ def test_initialize
8
+ item = Contracts::User.new
9
+ assert_not_nil item
10
+ end
11
+
12
+ def test_account_acquisition_date_works_as_expected
13
+ expected = 'Test string'
14
+ item = Contracts::User.new
15
+ item.account_acquisition_date = expected
16
+ actual = item.account_acquisition_date
17
+ assert_equal expected, actual
18
+ expected = 'Other string'
19
+ item.account_acquisition_date = expected
20
+ actual = item.account_acquisition_date
21
+ assert_equal expected, actual
22
+ end
23
+
24
+ def test_account_id_works_as_expected
25
+ expected = 'Test string'
26
+ item = Contracts::User.new
27
+ item.account_id = expected
28
+ actual = item.account_id
29
+ assert_equal expected, actual
30
+ expected = 'Other string'
31
+ item.account_id = expected
32
+ actual = item.account_id
33
+ assert_equal expected, actual
34
+ end
35
+
36
+ def test_user_agent_works_as_expected
37
+ expected = 'Test string'
38
+ item = Contracts::User.new
39
+ item.user_agent = expected
40
+ actual = item.user_agent
41
+ assert_equal expected, actual
42
+ expected = 'Other string'
43
+ item.user_agent = expected
44
+ actual = item.user_agent
45
+ assert_equal expected, actual
46
+ end
47
+
48
+ def test_id_works_as_expected
49
+ expected = 'Test string'
50
+ item = Contracts::User.new
51
+ item.id = expected
52
+ actual = item.id
53
+ assert_equal expected, actual
54
+ expected = 'Other string'
55
+ item.id = expected
56
+ actual = item.id
57
+ assert_equal expected, actual
58
+ end
59
+
60
+ def test_user_auth_id_as_expected
61
+ expected = 'Test string'
62
+ item = Contracts::User.new
63
+ item.auth_user_id = expected
64
+ actual = item.auth_user_id
65
+ assert_equal expected, actual
66
+ expected = 'Other string'
67
+ item.auth_user_id = expected
68
+ actual = item.auth_user_id
69
+ assert_equal expected, actual
70
+ end
71
+
72
+ def test_store_region_works_as_expected
73
+ expected = 'Test string'
74
+ item = Contracts::User.new
75
+ item.store_region = expected
76
+ actual = item.store_region
77
+ assert_equal expected, actual
78
+ expected = 'Other string'
79
+ item.store_region = expected
80
+ actual = item.store_region
81
+ assert_equal expected, actual
82
+ end
83
+
84
+ def test_to_json_works_as_expected
85
+ item = Contracts::User.new
86
+ item.account_acquisition_date = 'Test string'
87
+ item.account_id = 'Test string'
88
+ item.user_agent = 'Test string'
89
+ item.id = 'Test string'
90
+ item.store_region = 'Test string'
91
+ item.auth_user_id = 'Test string'
92
+ actual = item.to_json
93
+ expected = '{"ai.user.accountAcquisitionDate":"Test string","ai.user.accountId":"Test string","ai.user.userAgent":"Test string","ai.user.id":"Test string","ai.user.authUserId":"Test string","ai.user.storeRegion":"Test string"}'
94
+ assert_equal expected, actual
95
+ end
96
+ end
@@ -1,47 +1,47 @@
1
- require_relative '../../../lib/application_insights/channel/sender_base'
2
- require_relative '../../../lib/application_insights/channel/asynchronous_queue'
3
- require_relative '../mock_sender'
4
- require 'test/unit'
5
-
6
- include ApplicationInsights::Channel
7
-
8
- class TestAsynchronousQueue < Test::Unit::TestCase
9
- def test_initialize
10
- queue = AsynchronousQueue.new MockAsynchronousSender.new
11
- assert_not_nil queue.flush_notification
12
- end
13
-
14
- def test_flush_notification_works_as_expected
15
- queue = AsynchronousQueue.new MockAsynchronousSender.new
16
- assert_not_nil queue.flush_notification
17
- result = queue.flush_notification.wait 1
18
- assert_equal false, result
19
- queue.flush_notification.set
20
- result = queue.flush_notification.wait
21
- assert_equal true, result
22
- queue.flush_notification.clear
23
- result = queue.flush_notification.wait 1
24
- assert_equal false, result
25
- end
26
-
27
- def test_push_works_As_expected
28
- sender = MockAsynchronousSender.new
29
- queue = AsynchronousQueue.new sender
30
- queue.push 42
31
- assert_equal 1, sender.start_call_count
32
- assert_equal 42, queue.pop
33
- assert_nil queue.pop
34
- end
35
-
36
- def test_flush_works_as_expected
37
- sender = MockAsynchronousSender.new
38
- queue = AsynchronousQueue.new sender
39
- assert_not_nil queue.flush_notification
40
- result = queue.flush_notification.wait 1
41
- assert_equal false, result
42
- queue.flush
43
- assert_equal 1, sender.start_call_count
44
- result = queue.flush_notification.wait
45
- assert_equal true, result
46
- end
47
- end
1
+ require_relative '../../../lib/application_insights/channel/sender_base'
2
+ require_relative '../../../lib/application_insights/channel/asynchronous_queue'
3
+ require_relative '../mock_sender'
4
+ require 'test/unit'
5
+
6
+ include ApplicationInsights::Channel
7
+
8
+ class TestAsynchronousQueue < Test::Unit::TestCase
9
+ def test_initialize
10
+ queue = AsynchronousQueue.new MockAsynchronousSender.new
11
+ assert_not_nil queue.flush_notification
12
+ end
13
+
14
+ def test_flush_notification_works_as_expected
15
+ queue = AsynchronousQueue.new MockAsynchronousSender.new
16
+ assert_not_nil queue.flush_notification
17
+ result = queue.flush_notification.wait 1
18
+ assert_equal false, result
19
+ queue.flush_notification.set
20
+ result = queue.flush_notification.wait
21
+ assert_equal true, result
22
+ queue.flush_notification.clear
23
+ result = queue.flush_notification.wait 1
24
+ assert_equal false, result
25
+ end
26
+
27
+ def test_push_works_As_expected
28
+ sender = MockAsynchronousSender.new
29
+ queue = AsynchronousQueue.new sender
30
+ queue.push 42
31
+ assert_equal 1, sender.start_call_count
32
+ assert_equal 42, queue.pop
33
+ assert_nil queue.pop
34
+ end
35
+
36
+ def test_flush_works_as_expected
37
+ sender = MockAsynchronousSender.new
38
+ queue = AsynchronousQueue.new sender
39
+ assert_not_nil queue.flush_notification
40
+ result = queue.flush_notification.wait 1
41
+ assert_equal false, result
42
+ queue.flush
43
+ assert_equal 1, sender.start_call_count
44
+ result = queue.flush_notification.wait
45
+ assert_equal true, result
46
+ end
47
+ end
@@ -1,81 +1,81 @@
1
- require_relative '../../../lib/application_insights/channel/sender_base'
2
- require_relative '../../../lib/application_insights/channel/asynchronous_sender'
3
- require_relative '../../../lib/application_insights/channel/asynchronous_queue'
4
- require 'test/unit'
5
-
6
- include ApplicationInsights::Channel
7
-
8
- class TestAsynchronousSender < Test::Unit::TestCase
9
- def test_initialize
10
- sender = AsynchronousSender.new
11
- assert_equal 'https://dc.services.visualstudio.com/v2/track', sender.service_endpoint_uri
12
- assert_equal 1.0, sender.send_interval
13
- assert_equal 3.0, sender.send_time
14
- end
15
-
16
- def test_send_interval_works_as_expected
17
- sender = AsynchronousSender.new
18
- assert_equal 1.0, sender.send_interval
19
- sender.send_interval = 10.0
20
- assert_equal 10.0, sender.send_interval
21
- end
22
-
23
- def test_send_time_works_as_expected
24
- sender = AsynchronousSender.new
25
- assert_equal 3.0, sender.send_time
26
- sender.send_time = 10.0
27
- assert_equal 10.0, sender.send_time
28
- end
29
-
30
- def test_work_thread_works_as_expected
31
- sender = InterceptableAsynchronousSender.new
32
- assert_nil sender.work_thread
33
- sender.send_interval = 1.0
34
- sender.send_time = 3.0
35
- queue = AsynchronousQueue.new sender
36
- sender.invoke_base_start = true
37
- queue.push 1
38
- assert_not_nil sender.work_thread
39
- sleep 5.0
40
- assert_nil sender.work_thread
41
- end
42
-
43
- def test_start
44
- sender = InterceptableAsynchronousSender.new
45
- sender.send_interval = 1.0
46
- sender.send_time = 3.0
47
- queue = AsynchronousQueue.new sender
48
- sender.invoke_base_start = false
49
- queue.push 1
50
- queue.push 2
51
- sender.invoke_base_start = true
52
- sender.start
53
- sleep 2.0
54
- queue.push 3
55
- sleep 5.0
56
- data = sender.data_to_send
57
- assert_equal [[1, 2], [3]], data
58
- end
59
-
60
- end
61
-
62
- class InterceptableAsynchronousSender < AsynchronousSender
63
- def initialize
64
- @data_to_send = []
65
- @invoke_base_start = false
66
- super
67
- end
68
-
69
- attr_accessor :invoke_base_start
70
- attr_accessor :data_to_send
71
-
72
- def start
73
- if invoke_base_start
74
- super
75
- end
76
- end
77
-
78
- def send(data_to_send)
79
- @data_to_send.push data_to_send
80
- end
1
+ require_relative '../../../lib/application_insights/channel/sender_base'
2
+ require_relative '../../../lib/application_insights/channel/asynchronous_sender'
3
+ require_relative '../../../lib/application_insights/channel/asynchronous_queue'
4
+ require 'test/unit'
5
+
6
+ include ApplicationInsights::Channel
7
+
8
+ class TestAsynchronousSender < Test::Unit::TestCase
9
+ def test_initialize
10
+ sender = AsynchronousSender.new
11
+ assert_equal 'https://dc.services.visualstudio.com/v2/track', sender.service_endpoint_uri
12
+ assert_equal 1.0, sender.send_interval
13
+ assert_equal 3.0, sender.send_time
14
+ end
15
+
16
+ def test_send_interval_works_as_expected
17
+ sender = AsynchronousSender.new
18
+ assert_equal 1.0, sender.send_interval
19
+ sender.send_interval = 10.0
20
+ assert_equal 10.0, sender.send_interval
21
+ end
22
+
23
+ def test_send_time_works_as_expected
24
+ sender = AsynchronousSender.new
25
+ assert_equal 3.0, sender.send_time
26
+ sender.send_time = 10.0
27
+ assert_equal 10.0, sender.send_time
28
+ end
29
+
30
+ def test_work_thread_works_as_expected
31
+ sender = InterceptableAsynchronousSender.new
32
+ assert_nil sender.work_thread
33
+ sender.send_interval = 1.0
34
+ sender.send_time = 3.0
35
+ queue = AsynchronousQueue.new sender
36
+ sender.invoke_base_start = true
37
+ queue.push 1
38
+ assert_not_nil sender.work_thread
39
+ sleep 5.0
40
+ assert_nil sender.work_thread
41
+ end
42
+
43
+ def test_start
44
+ sender = InterceptableAsynchronousSender.new
45
+ sender.send_interval = 1.0
46
+ sender.send_time = 3.0
47
+ queue = AsynchronousQueue.new sender
48
+ sender.invoke_base_start = false
49
+ queue.push 1
50
+ queue.push 2
51
+ sender.invoke_base_start = true
52
+ sender.start
53
+ sleep 2.0
54
+ queue.push 3
55
+ sleep 5.0
56
+ data = sender.data_to_send
57
+ assert_equal [[1, 2], [3]], data
58
+ end
59
+
60
+ end
61
+
62
+ class InterceptableAsynchronousSender < AsynchronousSender
63
+ def initialize
64
+ @data_to_send = []
65
+ @invoke_base_start = false
66
+ super
67
+ end
68
+
69
+ attr_accessor :invoke_base_start
70
+ attr_accessor :data_to_send
71
+
72
+ def start
73
+ if invoke_base_start
74
+ super
75
+ end
76
+ end
77
+
78
+ def send(data_to_send)
79
+ @data_to_send.push data_to_send
80
+ end
81
81
  end
@@ -1,53 +1,53 @@
1
- require_relative '../../../lib/application_insights/channel/sender_base'
2
- require_relative '../../../lib/application_insights/channel/asynchronous_queue'
3
- require 'thread'
4
- require 'test/unit'
5
-
6
- include ApplicationInsights::Channel
7
-
8
- class TestEvent < Test::Unit::TestCase
9
- def test_initialize
10
- event = Event.new
11
- assert_equal false, event.signal
12
- end
13
-
14
- def test_set_works_as_expected
15
- event = Event.new
16
- assert_equal false, event.signal
17
- Thread.new do
18
- sleep 1
19
- event.set
20
- end
21
- result = event.wait 2.0
22
- assert_equal true, result
23
- end
24
-
25
- def test_clear_works_as_expected
26
- event = Event.new
27
- assert_equal false, event.signal
28
- event.set
29
- assert_equal true, event.signal
30
- event.clear
31
- assert_equal false, event.signal
32
- end
33
-
34
- def test_wait_works_as_expected
35
- event1 = Event.new
36
- assert_equal false, event1.signal
37
- Thread.new do
38
- sleep 1
39
- event1.set
40
- end
41
- result = event1.wait 0.5
42
- assert_equal false, result
43
-
44
- event2 = Event.new
45
- assert_equal false, event1.signal
46
- Thread.new do
47
- sleep 1
48
- event2.set
49
- end
50
- result = event2.wait 2.0
51
- assert_equal true, result
52
- end
1
+ require_relative '../../../lib/application_insights/channel/sender_base'
2
+ require_relative '../../../lib/application_insights/channel/asynchronous_queue'
3
+ require 'thread'
4
+ require 'test/unit'
5
+
6
+ include ApplicationInsights::Channel
7
+
8
+ class TestEvent < Test::Unit::TestCase
9
+ def test_initialize
10
+ event = Event.new
11
+ assert_equal false, event.signal
12
+ end
13
+
14
+ def test_set_works_as_expected
15
+ event = Event.new
16
+ assert_equal false, event.signal
17
+ Thread.new do
18
+ sleep 1
19
+ event.set
20
+ end
21
+ result = event.wait 2.0
22
+ assert_equal true, result
23
+ end
24
+
25
+ def test_clear_works_as_expected
26
+ event = Event.new
27
+ assert_equal false, event.signal
28
+ event.set
29
+ assert_equal true, event.signal
30
+ event.clear
31
+ assert_equal false, event.signal
32
+ end
33
+
34
+ def test_wait_works_as_expected
35
+ event1 = Event.new
36
+ assert_equal false, event1.signal
37
+ Thread.new do
38
+ sleep 1
39
+ event1.set
40
+ end
41
+ result = event1.wait 0.5
42
+ assert_equal false, result
43
+
44
+ event2 = Event.new
45
+ assert_equal false, event1.signal
46
+ Thread.new do
47
+ sleep 1
48
+ event2.set
49
+ end
50
+ result = event2.wait 2.0
51
+ assert_equal true, result
52
+ end
53
53
  end