application_insights 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +40 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +106 -0
  6. data/Rakefile +10 -0
  7. data/application_insights.gemspec +25 -0
  8. data/lib/application_insights.rb +2 -0
  9. data/lib/application_insights/channel/contracts/application.rb +35 -0
  10. data/lib/application_insights/channel/contracts/data.rb +47 -0
  11. data/lib/application_insights/channel/contracts/data_point.rb +125 -0
  12. data/lib/application_insights/channel/contracts/data_point_type.rb +16 -0
  13. data/lib/application_insights/channel/contracts/dependency_kind.rb +22 -0
  14. data/lib/application_insights/channel/contracts/dependency_source_type.rb +19 -0
  15. data/lib/application_insights/channel/contracts/device.rb +243 -0
  16. data/lib/application_insights/channel/contracts/envelope.rb +254 -0
  17. data/lib/application_insights/channel/contracts/event_data.rb +77 -0
  18. data/lib/application_insights/channel/contracts/exception_data.rb +105 -0
  19. data/lib/application_insights/channel/contracts/exception_details.rb +125 -0
  20. data/lib/application_insights/channel/contracts/internal.rb +51 -0
  21. data/lib/application_insights/channel/contracts/json_serializable.rb +59 -0
  22. data/lib/application_insights/channel/contracts/location.rb +35 -0
  23. data/lib/application_insights/channel/contracts/message_data.rb +76 -0
  24. data/lib/application_insights/channel/contracts/metric_data.rb +60 -0
  25. data/lib/application_insights/channel/contracts/operation.rb +83 -0
  26. data/lib/application_insights/channel/contracts/page_view_data.rb +109 -0
  27. data/lib/application_insights/channel/contracts/remote_dependency_data.rb +218 -0
  28. data/lib/application_insights/channel/contracts/request_data.rb +173 -0
  29. data/lib/application_insights/channel/contracts/session.rb +67 -0
  30. data/lib/application_insights/channel/contracts/severity_level.rb +25 -0
  31. data/lib/application_insights/channel/contracts/stack_frame.rb +91 -0
  32. data/lib/application_insights/channel/contracts/user.rb +83 -0
  33. data/lib/application_insights/channel/queue_base.rb +48 -0
  34. data/lib/application_insights/channel/sender_base.rb +46 -0
  35. data/lib/application_insights/channel/synchronous_queue.rb +28 -0
  36. data/lib/application_insights/channel/synchronous_sender.rb +13 -0
  37. data/lib/application_insights/channel/telemetry_channel.rb +81 -0
  38. data/lib/application_insights/channel/telemetry_context.rb +49 -0
  39. data/lib/application_insights/telemetry_client.rb +111 -0
  40. data/lib/application_insights/version.rb +3 -0
  41. data/test/application_insights.rb +9 -0
  42. data/test/application_insights/channel/contracts/test_application.rb +31 -0
  43. data/test/application_insights/channel/contracts/test_data.rb +44 -0
  44. data/test/application_insights/channel/contracts/test_data_point.rb +109 -0
  45. data/test/application_insights/channel/contracts/test_device.rb +200 -0
  46. data/test/application_insights/channel/contracts/test_envelope.rb +209 -0
  47. data/test/application_insights/channel/contracts/test_event_data.rb +62 -0
  48. data/test/application_insights/channel/contracts/test_exception_data.rb +85 -0
  49. data/test/application_insights/channel/contracts/test_exception_details.rb +106 -0
  50. data/test/application_insights/channel/contracts/test_internal.rb +44 -0
  51. data/test/application_insights/channel/contracts/test_location.rb +31 -0
  52. data/test/application_insights/channel/contracts/test_message_data.rb +66 -0
  53. data/test/application_insights/channel/contracts/test_metric_data.rb +50 -0
  54. data/test/application_insights/channel/contracts/test_operation.rb +70 -0
  55. data/test/application_insights/channel/contracts/test_page_view_data.rb +88 -0
  56. data/test/application_insights/channel/contracts/test_remote_dependency_data.rb +183 -0
  57. data/test/application_insights/channel/contracts/test_request_data.rb +153 -0
  58. data/test/application_insights/channel/contracts/test_session.rb +57 -0
  59. data/test/application_insights/channel/contracts/test_stack_frame.rb +83 -0
  60. data/test/application_insights/channel/contracts/test_user.rb +70 -0
  61. data/test/application_insights/channel/test_queue_base.rb +88 -0
  62. data/test/application_insights/channel/test_sender_base.rb +96 -0
  63. data/test/application_insights/channel/test_synchronous_queue.rb +42 -0
  64. data/test/application_insights/channel/test_synchronous_sender.rb +11 -0
  65. data/test/application_insights/channel/test_telemetry_channel.rb +102 -0
  66. data/test/application_insights/channel/test_telemetry_context.rb +72 -0
  67. data/test/application_insights/test_telemetry_client.rb +107 -0
  68. metadata +166 -0
@@ -0,0 +1,72 @@
1
+ require_relative '../../../lib/application_insights/channel/telemetry_context'
2
+ require 'test/unit'
3
+
4
+ include ApplicationInsights::Channel
5
+
6
+ class TestTelemetryContext < Test::Unit::TestCase
7
+ def test_initialize
8
+ context = TelemetryContext.new
9
+ assert_nil context.instrumentation_key
10
+ assert_not_nil context.application
11
+ assert_not_nil context.device
12
+ assert_not_nil context.user
13
+ assert_not_nil context.session
14
+ assert_not_nil context.operation
15
+ assert_not_nil context.location
16
+ assert_not_nil context.properties
17
+ end
18
+
19
+ def test_application_works_as_expected
20
+ context = TelemetryContext.new
21
+ assert_not_nil context.application
22
+ expected = Contracts::Application.new
23
+ context.application = expected
24
+ assert_same expected, context.application
25
+ end
26
+
27
+ def test_device_works_as_expected
28
+ context = TelemetryContext.new
29
+ assert_not_nil context.device
30
+ expected = Contracts::Device.new
31
+ context.device = expected
32
+ assert_same expected, context.device
33
+ end
34
+
35
+ def test_user_works_as_expected
36
+ context = TelemetryContext.new
37
+ assert_not_nil context.user
38
+ expected = Contracts::User.new
39
+ context.user = expected
40
+ assert_same expected, context.user
41
+ end
42
+
43
+ def test_session_works_as_expected
44
+ context = TelemetryContext.new
45
+ assert_not_nil context.session
46
+ expected = Contracts::Session.new
47
+ context.session = expected
48
+ assert_same expected, context.session
49
+ end
50
+
51
+ def test_operation_works_as_expected
52
+ context = TelemetryContext.new
53
+ assert_not_nil context.operation
54
+ expected = Contracts::Operation.new
55
+ context.operation = expected
56
+ assert_same expected, context.operation
57
+ end
58
+
59
+ def test_location_works_as_expected
60
+ context = TelemetryContext.new
61
+ assert_not_nil context.location
62
+ expected = Contracts::Location.new
63
+ context.location = expected
64
+ assert_same expected, context.location
65
+ end
66
+
67
+ def test_properties_works_as_expected
68
+ context = TelemetryContext.new
69
+ assert_not_nil context.properties
70
+ assert_equal 0, context.properties.count
71
+ end
72
+ end
@@ -0,0 +1,107 @@
1
+ require_relative '../../lib/application_insights/telemetry_client'
2
+ require_relative '../../lib/application_insights/channel/sender_base'
3
+ require_relative '../../lib/application_insights/channel/synchronous_queue'
4
+ require_relative '../../lib/application_insights/channel/telemetry_channel'
5
+ require 'json'
6
+ require 'test/unit'
7
+
8
+ include ApplicationInsights
9
+
10
+ class TestTelemetryClient < Test::Unit::TestCase
11
+ def test_initialize
12
+ client = TelemetryClient.new
13
+ assert_not_nil client.context
14
+ assert_not_nil client.channel
15
+
16
+ channel = Object.new
17
+ client = TelemetryClient.new channel
18
+ assert_not_nil client.context
19
+ assert_same channel, client.channel
20
+ end
21
+
22
+ def test_context_property_works_as_expected
23
+ client = TelemetryClient.new
24
+ assert_not_nil client.context
25
+ end
26
+
27
+ def test_channel_property_works_as_expected
28
+ client = TelemetryClient.new
29
+ assert_not_nil client.channel
30
+ end
31
+
32
+ def test_track_page_view_works_as_expected
33
+ client, sender = self.create_client
34
+ client.track_page_view 'test', 'http://tempuri.org'
35
+ client.flush
36
+ expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.PageView","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:0.1.0"},"data":{"baseType":"PageViewData","baseData":{"ver":2,"url":"http://tempuri.org","name":"test"}}}]'
37
+ sender.data_to_send[0].time = 'TIME_PLACEHOLDER'
38
+ actual = sender.data_to_send.to_json
39
+ assert_equal expected, actual
40
+ end
41
+
42
+ def test_track_exception_works_as_expected
43
+ client, sender = self.create_client
44
+ begin
45
+ raise ArgumentError, 'Some error'
46
+ rescue => e
47
+ client.track_exception e
48
+ end
49
+ client.flush
50
+ expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.Exception","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:0.1.0"},"data":{"baseType":"ExceptionData","baseData":{"ver":2,"handledAt":"UserCode","exceptions":[{"id":1,"outerId":0,"typeName":"ArgumentError","message":"Some error","hasFullStack":true,"stack":"STACK_PLACEHOLDER"}]}}}]'
51
+ sender.data_to_send[0].time = 'TIME_PLACEHOLDER'
52
+ sender.data_to_send[0].data.base_data.exceptions[0].stack = 'STACK_PLACEHOLDER'
53
+ actual = sender.data_to_send.to_json
54
+ assert_equal expected, actual
55
+ end
56
+
57
+ def test_track_event_view_works_as_expected
58
+ client, sender = self.create_client
59
+ client.track_event 'test'
60
+ client.flush
61
+ expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.Event","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:0.1.0"},"data":{"baseType":"EventData","baseData":{"ver":2,"name":"test"}}}]'
62
+ sender.data_to_send[0].time = 'TIME_PLACEHOLDER'
63
+ actual = sender.data_to_send.to_json
64
+ assert_equal expected, actual
65
+ end
66
+
67
+ def test_track_metric_view_works_as_expected
68
+ client, sender = self.create_client
69
+ client.track_metric 'test', 42
70
+ client.flush
71
+ expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.Metric","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:0.1.0"},"data":{"baseType":"MetricData","baseData":{"ver":2,"metrics":[{"name":"test","kind":1,"value":42}]}}}]'
72
+ sender.data_to_send[0].time = 'TIME_PLACEHOLDER'
73
+ actual = sender.data_to_send.to_json
74
+ assert_equal expected, actual
75
+ end
76
+
77
+ def test_track_trace_view_works_as_expected
78
+ client, sender = self.create_client
79
+ client.track_trace 'test'
80
+ client.flush
81
+ expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.Message","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:0.1.0"},"data":{"baseType":"MessageData","baseData":{"ver":2,"message":"test"}}}]'
82
+ sender.data_to_send[0].time = 'TIME_PLACEHOLDER'
83
+ actual = sender.data_to_send.to_json
84
+ assert_equal expected, actual
85
+ end
86
+
87
+ def create_client
88
+ sender = MockTelemetryClientSender.new
89
+ queue = Channel::SynchronousQueue.new sender
90
+ channel = Channel::TelemetryChannel.new nil, queue
91
+ client = TelemetryClient.new channel
92
+ return client, sender
93
+ end
94
+ end
95
+
96
+ class MockTelemetryClientSender < Channel::SenderBase
97
+ def initialize
98
+ super 'http://tempuri.org'
99
+ @data_to_send = []
100
+ end
101
+
102
+ attr_accessor :data_to_send
103
+
104
+ def send(data_to_send)
105
+ @data_to_send = data_to_send
106
+ end
107
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: application_insights
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Microsoft
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: This project extends the Application Insights API surface to support
42
+ Ruby.
43
+ email:
44
+ - aiengdisc@microsoft.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - application_insights.gemspec
55
+ - lib/application_insights.rb
56
+ - lib/application_insights/channel/contracts/application.rb
57
+ - lib/application_insights/channel/contracts/data.rb
58
+ - lib/application_insights/channel/contracts/data_point.rb
59
+ - lib/application_insights/channel/contracts/data_point_type.rb
60
+ - lib/application_insights/channel/contracts/dependency_kind.rb
61
+ - lib/application_insights/channel/contracts/dependency_source_type.rb
62
+ - lib/application_insights/channel/contracts/device.rb
63
+ - lib/application_insights/channel/contracts/envelope.rb
64
+ - lib/application_insights/channel/contracts/event_data.rb
65
+ - lib/application_insights/channel/contracts/exception_data.rb
66
+ - lib/application_insights/channel/contracts/exception_details.rb
67
+ - lib/application_insights/channel/contracts/internal.rb
68
+ - lib/application_insights/channel/contracts/json_serializable.rb
69
+ - lib/application_insights/channel/contracts/location.rb
70
+ - lib/application_insights/channel/contracts/message_data.rb
71
+ - lib/application_insights/channel/contracts/metric_data.rb
72
+ - lib/application_insights/channel/contracts/operation.rb
73
+ - lib/application_insights/channel/contracts/page_view_data.rb
74
+ - lib/application_insights/channel/contracts/remote_dependency_data.rb
75
+ - lib/application_insights/channel/contracts/request_data.rb
76
+ - lib/application_insights/channel/contracts/session.rb
77
+ - lib/application_insights/channel/contracts/severity_level.rb
78
+ - lib/application_insights/channel/contracts/stack_frame.rb
79
+ - lib/application_insights/channel/contracts/user.rb
80
+ - lib/application_insights/channel/queue_base.rb
81
+ - lib/application_insights/channel/sender_base.rb
82
+ - lib/application_insights/channel/synchronous_queue.rb
83
+ - lib/application_insights/channel/synchronous_sender.rb
84
+ - lib/application_insights/channel/telemetry_channel.rb
85
+ - lib/application_insights/channel/telemetry_context.rb
86
+ - lib/application_insights/telemetry_client.rb
87
+ - lib/application_insights/version.rb
88
+ - test/application_insights.rb
89
+ - test/application_insights/channel/contracts/test_application.rb
90
+ - test/application_insights/channel/contracts/test_data.rb
91
+ - test/application_insights/channel/contracts/test_data_point.rb
92
+ - test/application_insights/channel/contracts/test_device.rb
93
+ - test/application_insights/channel/contracts/test_envelope.rb
94
+ - test/application_insights/channel/contracts/test_event_data.rb
95
+ - test/application_insights/channel/contracts/test_exception_data.rb
96
+ - test/application_insights/channel/contracts/test_exception_details.rb
97
+ - test/application_insights/channel/contracts/test_internal.rb
98
+ - test/application_insights/channel/contracts/test_location.rb
99
+ - test/application_insights/channel/contracts/test_message_data.rb
100
+ - test/application_insights/channel/contracts/test_metric_data.rb
101
+ - test/application_insights/channel/contracts/test_operation.rb
102
+ - test/application_insights/channel/contracts/test_page_view_data.rb
103
+ - test/application_insights/channel/contracts/test_remote_dependency_data.rb
104
+ - test/application_insights/channel/contracts/test_request_data.rb
105
+ - test/application_insights/channel/contracts/test_session.rb
106
+ - test/application_insights/channel/contracts/test_stack_frame.rb
107
+ - test/application_insights/channel/contracts/test_user.rb
108
+ - test/application_insights/channel/test_queue_base.rb
109
+ - test/application_insights/channel/test_sender_base.rb
110
+ - test/application_insights/channel/test_synchronous_queue.rb
111
+ - test/application_insights/channel/test_synchronous_sender.rb
112
+ - test/application_insights/channel/test_telemetry_channel.rb
113
+ - test/application_insights/channel/test_telemetry_context.rb
114
+ - test/application_insights/test_telemetry_client.rb
115
+ homepage: https://github.com/Microsoft/AppInsights-Ruby
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: 1.9.3
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.4.5
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Application Insights SDK for Ruby
139
+ test_files:
140
+ - test/application_insights.rb
141
+ - test/application_insights/channel/contracts/test_application.rb
142
+ - test/application_insights/channel/contracts/test_data.rb
143
+ - test/application_insights/channel/contracts/test_data_point.rb
144
+ - test/application_insights/channel/contracts/test_device.rb
145
+ - test/application_insights/channel/contracts/test_envelope.rb
146
+ - test/application_insights/channel/contracts/test_event_data.rb
147
+ - test/application_insights/channel/contracts/test_exception_data.rb
148
+ - test/application_insights/channel/contracts/test_exception_details.rb
149
+ - test/application_insights/channel/contracts/test_internal.rb
150
+ - test/application_insights/channel/contracts/test_location.rb
151
+ - test/application_insights/channel/contracts/test_message_data.rb
152
+ - test/application_insights/channel/contracts/test_metric_data.rb
153
+ - test/application_insights/channel/contracts/test_operation.rb
154
+ - test/application_insights/channel/contracts/test_page_view_data.rb
155
+ - test/application_insights/channel/contracts/test_remote_dependency_data.rb
156
+ - test/application_insights/channel/contracts/test_request_data.rb
157
+ - test/application_insights/channel/contracts/test_session.rb
158
+ - test/application_insights/channel/contracts/test_stack_frame.rb
159
+ - test/application_insights/channel/contracts/test_user.rb
160
+ - test/application_insights/channel/test_queue_base.rb
161
+ - test/application_insights/channel/test_sender_base.rb
162
+ - test/application_insights/channel/test_synchronous_queue.rb
163
+ - test/application_insights/channel/test_synchronous_sender.rb
164
+ - test/application_insights/channel/test_telemetry_channel.rb
165
+ - test/application_insights/channel/test_telemetry_context.rb
166
+ - test/application_insights/test_telemetry_client.rb