application_insights 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YmYzZWY1NTZhMmUyZGE5MmFiMWU0N2YwZjVmMjEzMmUyNDQwMGIwZg==
5
- data.tar.gz: !binary |-
6
- YTU5M2NlN2NhMjJmZDVkNGVjYjE5NzIxODEzZTU4NGIwNzNmNThmMQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- Y2RlNzYxZjJiNDdkNjRkOGEyYmE4Yjc3NjA4NWQ1YmMyYzFmZWQ4M2Q4ODRk
10
- NDQ4Mzk3ZTVmOTZlMzljMjA3ZDJhODAwMmMyNTdlNDJkYjU3NTFkMjI0ZTA4
11
- ZDQ0NWQ0Nzk5ODVmOWE0NTg1Yzc1MGYwMzRhM2JmNjg5MmE2N2E=
12
- data.tar.gz: !binary |-
13
- NGFhYzM5ZmE3YjBjYmViMWIzZDhmN2ZiMjFmZjMyYmE3MDRiNjQ5YjlmNDk2
14
- MmZiZmVmODdiMDljNWUwMzVmYjhmN2RiMWRhYmZlZjRhNDNlODFiOGY0Y2U5
15
- YTFhMTQ2NDEzMGE0MTFmYmRiZmQwMTYzMjM2YWExZTJiY2RmZmM=
2
+ SHA1:
3
+ metadata.gz: eec95e24b4930002c21840002367106145b2752a
4
+ data.tar.gz: e38cde81727c4a511aaf4b4626c32cd9c3fb5826
5
+ SHA512:
6
+ metadata.gz: 9c55af8a02ca69adefe4396d6b01f4e4ceeddb68e401b9e903db49054f179ab2dd45f171c81cc80b01c2c45b46d80d0eaa4e719d006e2cb6662976f8eabf48e7
7
+ data.tar.gz: 0452d3daa3574d705c26576ea93ca8086ef105559e4ae0f094567ec58be6daee28e5a202cd090bdf7ed51197435a3fad97d5e28039dcc09cbb39eeabfad00042
@@ -1,9 +1,21 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.0
6
- - 2.2.0
7
-
8
- install:
9
- - bundle install
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - 2.2.0
7
+ - 2.3.3
8
+ - 2.4.0
9
+ - ruby-head
10
+
11
+ cache: bundler
12
+
13
+ before_install:
14
+ - gem install bundler
15
+
16
+ matrix:
17
+ allow_failures:
18
+ - rvm: ruby-head
19
+
20
+ install:
21
+ - bundle install
@@ -0,0 +1,30 @@
1
+ # How to Contribute
2
+
3
+ If you're interested in contributing, take a look at the general [contributer's guide](https://github.com/Microsoft/ApplicationInsights-Home/blob/master/CONTRIBUTING.md) first.
4
+
5
+ ## Build Gem
6
+
7
+ Run ```gem build application_insights.gemspec``` to generate the gem file.
8
+
9
+ And you can install the gem to test it locally by running ```gem install application_insights-[version].gem```.
10
+
11
+ ## Run Test
12
+
13
+ Make sure you have bundler installed, you can install it by ```sudo gem install bundler```. And run ```bundler install``` once to install all dependencies.
14
+
15
+ Run ```rake test```.
16
+
17
+ ## Contributing
18
+
19
+ This project welcomes contributions and suggestions. Most contributions require you to
20
+ agree to a Contributor License Agreement (CLA) declaring that you have the right to,
21
+ and actually do, grant us the rights to use your contribution. For details, visit
22
+ https://cla.microsoft.com.
23
+
24
+ When you submit a pull request, a CLA-bot will automatically determine whether you need
25
+ to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the
26
+ instructions provided by the bot. You will only need to do this once across all repositories using our CLA.
27
+
28
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
29
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
30
+ or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in application_insights.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in application_insights.gemspec
4
+ gemspec
@@ -1,11 +1,11 @@
1
- AppInsights-Ruby
2
- Copyright (c) Microsoft Corporation
3
- All rights reserved.
4
-
5
- MIT License
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
-
9
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
-
11
- THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ AppInsights-Ruby
2
+ Copyright (c) Microsoft Corporation
3
+ All rights reserved.
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Application Insights SDK for Ruby #
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/application_insights.svg)](http://badge.fury.io/rb/application_insights)
4
- [![Build Status](https://travis-ci.org/Microsoft/AppInsights-Ruby.svg)](https://travis-ci.org/Microsoft/ApplicationInsights-Ruby)
4
+ [![Build Status](https://travis-ci.org/Microsoft/ApplicationInsights-Ruby.svg)](https://travis-ci.org/Microsoft/ApplicationInsights-Ruby)
5
5
 
6
6
  >Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.
7
7
  > -- <cite>[Ruby - Official Site](https://www.ruby-lang.org/en/)</cite>
@@ -28,7 +28,7 @@ Once installed, you can send telemetry to Application Insights. Here are a few s
28
28
  >**Note**: before you can send data to you will need an instrumentation key. Please see the [Getting an Application Insights Instrumentation Key](https://github.com/Microsoft/AppInsights-Home/wiki#getting-an-application-insights-instrumentation-key) section for more information.
29
29
 
30
30
 
31
- ###Sending a simple event telemetry item###
31
+ ### Sending a simple event telemetry item ###
32
32
  ```ruby
33
33
  require 'application_insights'
34
34
  tc = ApplicationInsights::TelemetryClient.new '<YOUR INSTRUMENTATION KEY GOES HERE>'
@@ -36,7 +36,7 @@ tc.track_event 'My event'
36
36
  tc.flush
37
37
  ```
38
38
 
39
- ###Sending an event telemetry item with custom properties and measurements###
39
+ ### Sending an event telemetry item with custom properties and measurements ###
40
40
  ```ruby
41
41
  require 'application_insights'
42
42
  tc = ApplicationInsights::TelemetryClient.new '<YOUR INSTRUMENTATION KEY GOES HERE>'
@@ -44,15 +44,15 @@ tc.track_event 'My event', :properties => { 'custom property' => 'some value' },
44
44
  tc.flush
45
45
  ```
46
46
 
47
- ###Sending a trace telemetry item with custom properties###
47
+ ### Sending a trace telemetry item with custom properties ###
48
48
  ```ruby
49
49
  require 'application_insights'
50
50
  tc = ApplicationInsights::TelemetryClient.new '<YOUR INSTRUMENTATION KEY GOES HERE>'
51
- tc.track_trace 'My trace statement', :properties => { 'custom property' => 'some value' }
51
+ tc.track_trace 'My trace statement', ApplicationInsights::Channel::Contracts::SeverityLevel::INFORMATION, :properties => { 'custom property' => 'some value' }
52
52
  tc.flush
53
53
  ```
54
54
 
55
- ###Sending a metric telemetry item (without and with optional values)###
55
+ ### Sending a metric telemetry item (without and with optional values) ###
56
56
  ```ruby
57
57
  require 'application_insights'
58
58
  tc = ApplicationInsights::TelemetryClient.new '<YOUR INSTRUMENTATION KEY GOES HERE>'
@@ -62,7 +62,7 @@ tc.track_metric 'My metric', 42, :kind => ApplicationInsights::Channel::Contract
62
62
  tc.flush
63
63
  ```
64
64
 
65
- ###Sending an exception telemetry item with custom properties and measurements###
65
+ ### Sending an exception telemetry item with custom properties and measurements ###
66
66
  ```ruby
67
67
  require 'application_insights'
68
68
  tc = ApplicationInsights::TelemetryClient.new '<YOUR INSTRUMENTATION KEY GOES HERE>'
@@ -74,11 +74,10 @@ end
74
74
  tc.flush
75
75
  ```
76
76
 
77
- ###Configuring context for a telemetry client instance###
77
+ ### Configuring context for a telemetry client instance ###
78
78
  ```ruby
79
79
  require 'application_insights'
80
80
  tc = ApplicationInsights::TelemetryClient.new '<YOUR INSTRUMENTATION KEY GOES HERE>'
81
- tc.context.application.id = 'My application'
82
81
  tc.context.application.ver = '1.2.3'
83
82
  tc.context.device.id = 'My current device'
84
83
  tc.context.device.oem_name = 'Asus'
@@ -89,7 +88,7 @@ tc.track_trace 'My trace with context'
89
88
  tc.flush
90
89
  ```
91
90
 
92
- ###Configuring synchronous (default) channel properties###
91
+ ### Configuring synchronous (default) channel properties ###
93
92
  ```ruby
94
93
  require 'application_insights'
95
94
  tc = ApplicationInsights::TelemetryClient.new
@@ -99,7 +98,7 @@ tc.channel.queue.max_queue_length = 10
99
98
  tc.channel.sender.send_buffer_size = 5
100
99
  ```
101
100
 
102
- ###Configuring an asynchronous channel instead of the synchronous default###
101
+ ### Configuring an asynchronous channel instead of the synchronous default ###
103
102
  ```ruby
104
103
  require 'application_insights'
105
104
  sender = ApplicationInsights::Channel::AsynchronousSender.new
@@ -111,7 +110,7 @@ tc = ApplicationInsights::TelemetryClient.new '<YOUR INSTRUMENTATION KEY GOES HE
111
110
  tc.track_event 'My event'
112
111
  ```
113
112
 
114
- ###Configuring asynchronous channel properties###
113
+ ### Configuring asynchronous channel properties ###
115
114
  ```ruby
116
115
  require 'application_insights'
117
116
  sender = ApplicationInsights::Channel::AsynchronousSender.new
@@ -129,7 +128,7 @@ tc.channel.sender.send_time = 5
129
128
  tc.channel.sender.send_interval = 0.5
130
129
  ```
131
130
 
132
- ###Collecting unhandled exceptions###
131
+ ### Collecting unhandled exceptions ###
133
132
  ```ruby
134
133
  require 'application_insights'
135
134
  # setup unhandled exception handler
@@ -138,7 +137,7 @@ ApplicationInsights::UnhandledException.collect('<YOUR INSTRUMENTATION KEY GOES
138
137
  raise Exception, 'Boom!'
139
138
  ```
140
139
 
141
- ###Collecting requests for rack applications###
140
+ ### Collecting requests for rack applications ###
142
141
  ```ruby
143
142
  # set up the TrackRequest middleware in the rackup (config.ru) file
144
143
  require 'application_insights'
data/Rakefile CHANGED
@@ -1,15 +1,15 @@
1
- require "bundler/gem_tasks"
2
- require 'rake/testtask'
3
- require 'yard'
4
-
5
- Rake::TestTask.new do |test|
6
- test.libs << 'test'
7
- test.test_files = FileList['test/application_insights.rb']
8
- test.verbose = true
9
- end
10
-
11
- YARD::Rake::YardocTask.new do |task|
12
- task.files = ['lib/**/*.rb', '-', 'LICENSE.txt', 'README.md']
13
- end
14
-
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+ require 'yard'
4
+
5
+ Rake::TestTask.new do |test|
6
+ test.libs << 'test'
7
+ test.test_files = FileList['test/application_insights.rb']
8
+ test.verbose = true
9
+ end
10
+
11
+ YARD::Rake::YardocTask.new do |task|
12
+ task.files = ['lib/**/*.rb', '-', 'LICENSE.txt', 'README.md']
13
+ end
14
+
15
15
  task :default => [ :test, :build, :yard ]
@@ -1,29 +1,28 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'application_insights/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'application_insights'
8
- spec.version = ApplicationInsights::VERSION
9
- spec.authors = ['Microsoft']
10
- spec.email = ['aiengdisc@microsoft.com']
11
- spec.summary = %q{Application Insights SDK for Ruby}
12
- spec.description = %q{This project extends the Application Insights API surface to support Ruby.}
13
- spec.homepage = 'https://github.com/Microsoft/AppInsights-Ruby'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ['lib']
20
-
21
- spec.required_ruby_version = '>= 1.9.3'
22
-
23
- spec.add_development_dependency 'bundler', '~> 1.7'
24
- spec.add_development_dependency 'rake', '~> 10.0'
25
- spec.add_development_dependency 'yard', '~> 0.8.7.6'
26
- spec.add_development_dependency 'redcarpet', '~> 3.2.2'
27
- spec.add_development_dependency 'rack', '>= 1.0.0'
28
- spec.add_development_dependency 'test-unit', '~> 3.0.8'
29
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'application_insights/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'application_insights'
8
+ spec.version = ApplicationInsights::VERSION
9
+ spec.authors = ['Microsoft']
10
+ spec.email = ['aiengdisc@microsoft.com']
11
+ spec.summary = %q{Application Insights SDK for Ruby}
12
+ spec.description = %q{This project extends the Application Insights API surface to support Ruby.}
13
+ spec.homepage = 'https://github.com/Microsoft/AppInsights-Ruby'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.required_ruby_version = '>= 1.9.3'
22
+
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'yard', '~> 0.9.11'
25
+ spec.add_development_dependency 'redcarpet', '~> 3.2.2'
26
+ spec.add_development_dependency 'rack', '>= 1.0.0'
27
+ spec.add_development_dependency 'test-unit', '~> 3.0.8'
28
+ end
@@ -1,9 +1,9 @@
1
- require_relative 'application_insights/telemetry_client'
2
- require_relative 'application_insights/unhandled_exception'
3
- require_relative 'application_insights/version'
4
-
5
- module ApplicationInsights
6
- module Rack
7
- autoload :TrackRequest, "application_insights/rack/track_request"
8
- end
9
- end
1
+ require_relative 'application_insights/telemetry_client'
2
+ require_relative 'application_insights/unhandled_exception'
3
+ require_relative 'application_insights/version'
4
+
5
+ module ApplicationInsights
6
+ module Rack
7
+ autoload :TrackRequest, "application_insights/rack/track_request"
8
+ end
9
+ end
@@ -1,51 +1,58 @@
1
- require_relative 'event'
2
- require_relative 'queue_base'
3
-
4
- module ApplicationInsights
5
- module Channel
6
- # An asynchronous queue for use in conjunction with the {AsynchronousSender}. The queue
7
- # will notify the sender that it needs to pick up items when it reaches {#max_queue_length}, or when the consumer
8
- # calls {#flush} via the {#flush_notification} event.
9
- # @example
10
- # require 'application_insights'
11
- # require 'thread'
12
- # queue = ApplicationInsights::Channel::AsynchronousQueue.new nil
13
- # Thread.new do
14
- # sleep 1
15
- # queue.push 1
16
- # queue.flush
17
- # end
18
- # queue.flush_notification.wait
19
- # queue.flush_notification.clear
20
- # result = queue.pop
21
- class AsynchronousQueue < QueueBase
22
- # Initializes a new instance of the class.
23
- # @param [SenderBase] sender the sender object that will be used in conjunction with this queue. In addition to
24
- # the sender object must support a {AsynchronousSender#start} method which is invoked
25
- # each time an item is pushed to the queue as well as use the {#flush_notification} event.
26
- def initialize(sender)
27
- @flush_notification = Event.new
28
- super sender
29
- end
30
-
31
- # The flush notification {ApplicationInsights::Channel::Event} that the {#sender} will use to get notified
32
- # that a flush is needed.
33
- # @return [Event] object that the {#sender} can wait on.
34
- attr_reader :flush_notification
35
-
36
- # Adds the passed in item object to the queue and notifies the {#sender} to start an asynchronous send operation
37
- # by calling {AsynchronousSender#start}.
38
- # @param [Contracts::Envelope] item the telemetry envelope object to send to the service.
39
- def push(item)
40
- super item
41
- @sender.start if @sender
42
- end
43
-
44
- # Flushes the current queue by notifying the {#sender} via the {#flush_notification} event.
45
- def flush
46
- @flush_notification.set
47
- @sender.start if @sender
48
- end
49
- end
50
- end
51
- end
1
+ require_relative 'event'
2
+ require_relative 'queue_base'
3
+
4
+ module ApplicationInsights
5
+ module Channel
6
+ # An asynchronous queue for use in conjunction with the {AsynchronousSender}.
7
+ # The queue will notify the sender that it needs to pick up items when it
8
+ # reaches {#max_queue_length}, or when the consumer calls {#flush} via the
9
+ # {#flush_notification} event.
10
+ #
11
+ # @example
12
+ # require 'application_insights'
13
+ # require 'thread'
14
+ # queue = ApplicationInsights::Channel::AsynchronousQueue.new nil
15
+ # Thread.new do
16
+ # sleep 1
17
+ # queue.push 1
18
+ # queue.flush
19
+ # end
20
+ # queue.flush_notification.wait
21
+ # queue.flush_notification.clear
22
+ # result = queue.pop
23
+ class AsynchronousQueue < QueueBase
24
+ # Initializes a new instance of the class.
25
+ # @param [SenderBase] sender the sender object that will be used in
26
+ # conjunction with this queue. In addition to the sender object must
27
+ # support a {AsynchronousSender#start} method which is invoked each time
28
+ # an item is pushed to the queue as well as use the {#flush_notification}
29
+ # event.
30
+ def initialize(sender)
31
+ @flush_notification = Event.new
32
+ super sender
33
+ end
34
+
35
+ # The flush notification {ApplicationInsights::Channel::Event} that the {#sender}
36
+ # will use to get notified that a flush is needed.
37
+ # @return [Event] object that the {#sender} can wait on.
38
+ attr_reader :flush_notification
39
+
40
+ # Adds the passed in item object to the queue and notifies the {#sender}
41
+ # to start an asynchronous send operation
42
+ # by calling {AsynchronousSender#start}.
43
+ # @param [Contracts::Envelope] item the telemetry envelope object to send
44
+ # to the service.
45
+ def push(item)
46
+ super item
47
+ @sender.start if @sender
48
+ end
49
+
50
+ # Flushes the current queue by notifying the {#sender} via the
51
+ # {#flush_notification} event.
52
+ def flush
53
+ @flush_notification.set
54
+ @sender.start if @sender
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,123 +1,132 @@
1
- require_relative 'sender_base'
2
- require 'thread'
3
-
4
- module ApplicationInsights
5
- module Channel
6
- # An asynchronous sender that works in conjunction with the {AsynchronousQueue}. The sender object will start a
7
- # worker thread that will pull items from the {#queue}. The thread will be created when the client calls {#start} and
8
- # will check for queue items every {#send_interval} seconds. The worker thread can also be forced to check the queue
9
- # by setting the {AsynchronousQueue#flush_notification} event.
10
- #
11
- # - If no items are found, the thread will go back to sleep.
12
- # - If items are found, the worker thread will send items to the specified service in batches of {#send_buffer_size}.
13
- #
14
- # If no queue items are found for {#send_time} seconds, the worker thread will shut down (and {#start} will
15
- # need to be called again).
16
- class AsynchronousSender < SenderBase
17
- # Initializes a new instance of the class.
18
- # @param [String] service_endpoint_uri the address of the service to send telemetry data to.
19
- def initialize(service_endpoint_uri='https://dc.services.visualstudio.com/v2/track')
20
- @send_interval = 1.0
21
- @send_remaining_time = 0
22
- @send_time = 3.0
23
- @lock_work_thread = Mutex.new
24
- @work_thread = nil
25
- @start_notification_processed = true
26
- super service_endpoint_uri
27
- end
28
-
29
- # The time span in seconds at which the the worker thread will check the {#queue} for items (defaults to: 1.0).
30
- # @return [Fixnum] the interval in seconds.
31
- attr_accessor :send_interval
32
-
33
- # The time span in seconds for which the worker thread will stay alive if no items are found in the {#queue} (defaults to 3.0).
34
- # @return [Fixnum] the interval in seconds.
35
- attr_accessor :send_time
36
-
37
- # The worker thread which checks queue items and send data every (#send_interval) seconds or upon flush.
38
- # @return [Thread] the work thread
39
- attr_reader :work_thread
40
-
41
- # Calling this method will create a worker thread that checks the {#queue} every {#send_interval} seconds for
42
- # a total duration of {#send_time} seconds for new items. If a worker thread has already been created, calling
43
- # this method does nothing.
44
- def start
45
- @start_notification_processed = false
46
- # Maintain one working thread at one time
47
- if !@work_thread
48
- @lock_work_thread.synchronize do
49
- if !@work_thread
50
- local_send_interval = (@send_interval < 0.1) ? 0.1 : @send_interval
51
- @send_remaining_time = (@send_time < local_send_interval) ? local_send_interval : @send_time
52
- @work_thread = Thread.new do
53
- run
54
- end
55
- @work_thread.abort_on_exception = false
56
- end
57
- end
58
- end
59
- end
60
-
61
- private
62
-
63
- def run
64
- # save the queue locally
65
- local_queue = @queue
66
- if local_queue == nil
67
- @work_thread = nil
68
- return
69
- end
70
-
71
- begin
72
- # fix up the send interval (can't be lower than 100ms)
73
- local_send_interval = (@send_interval < 0.1) ? 0.1 : @send_interval
74
- while TRUE
75
- @start_notification_processed = true
76
- while TRUE
77
- # get at most @send_buffer_size items from the queue
78
- counter = @send_buffer_size
79
- data = []
80
- while counter > 0
81
- item = local_queue.pop
82
- break if not item
83
- data.push item
84
- counter -= 1
85
- end
86
-
87
- # if we didn't get any items from the queue, we're done here
88
- break if data.length == 0
89
-
90
- # reset the send time
91
- @send_remaining_time = @send_time
92
-
93
- # finally send the data
94
- send data
95
- end
96
-
97
- # wait at most @send_interval ms (or until we get signalled)
98
- result = local_queue.flush_notification.wait local_send_interval
99
- if result
100
- local_queue.flush_notification.clear
101
- next
102
- end
103
-
104
- # decrement the remaining time
105
- @send_remaining_time -= local_send_interval
106
- # If remaining time <=0 and there is no start notification unprocessed, then stop the working thread
107
- if @send_remaining_time <= 0 && @start_notification_processed
108
- # Note: there is still a chance some start notification could be missed, e.g., the start method
109
- # got triggered between the above and following line. However the data is not lost as it would be processed
110
- # later when next start notification comes after the worker thread stops. The cost to ensure no
111
- # notification miss is high where a lock is required each time the start method calls.
112
- @work_thread = nil
113
- break
114
- end
115
- end
116
- rescue
117
- # Make sure work_thread sets to nil when it terminates abnormally
118
- @work_thread = nil
119
- end
120
- end
121
- end
122
- end
123
- end
1
+ require_relative 'sender_base'
2
+ require 'thread'
3
+
4
+ module ApplicationInsights
5
+ module Channel
6
+ # An asynchronous sender that works in conjunction with the {AsynchronousQueue}.
7
+ # The sender object will start a worker thread that will pull items from the
8
+ # {#queue}. The thread will be created when the client calls {#start} and
9
+ # will check for queue items every {#send_interval} seconds. The worker thread
10
+ # can also be forced to check the queue by setting the
11
+ # {AsynchronousQueue#flush_notification} event.
12
+ #
13
+ # - If no items are found, the thread will go back to sleep.
14
+ # - If items are found, the worker thread will send items to the specified
15
+ # service in batches of {#send_buffer_size}.
16
+ #
17
+ # If no queue items are found for {#send_time} seconds, the worker thread
18
+ # will shut down (and {#start} will need to be called again).
19
+ class AsynchronousSender < SenderBase
20
+ SERVICE_ENDPOINT_URI = 'https://dc.services.visualstudio.com/v2/track'
21
+ # Initializes a new instance of the class.
22
+ # @param [String] service_endpoint_uri the address of the service to send
23
+ # telemetry data to.
24
+ def initialize(service_endpoint_uri = SERVICE_ENDPOINT_URI)
25
+ @send_interval = 1.0
26
+ @send_remaining_time = 0
27
+ @send_time = 3.0
28
+ @lock_work_thread = Mutex.new
29
+ @work_thread = nil
30
+ @start_notification_processed = true
31
+ super service_endpoint_uri
32
+ end
33
+
34
+ # The time span in seconds at which the the worker thread will check the
35
+ # {#queue} for items (defaults to: 1.0).
36
+ # @return [Fixnum] the interval in seconds.
37
+ attr_accessor :send_interval
38
+
39
+ # The time span in seconds for which the worker thread will stay alive if
40
+ # no items are found in the {#queue} (defaults to 3.0).
41
+ # @return [Fixnum] the interval in seconds.
42
+ attr_accessor :send_time
43
+
44
+ # The worker thread which checks queue items and send data every
45
+ # (#send_interval) seconds or upon flush.
46
+ # @return [Thread] the work thread
47
+ attr_reader :work_thread
48
+
49
+ # Calling this method will create a worker thread that checks the {#queue}
50
+ # every {#send_interval} seconds for a total duration of {#send_time}
51
+ # seconds for new items. If a worker thread has already been created,
52
+ # calling this method does nothing.
53
+ def start
54
+ @start_notification_processed = false
55
+ # Maintain one working thread at one time
56
+ unless @work_thread
57
+ @lock_work_thread.synchronize do
58
+ unless @work_thread
59
+ local_send_interval = [@send_interval, 0.1].max
60
+ @send_remaining_time = [@send_time, local_send_interval].max
61
+ @work_thread = Thread.new { run }
62
+ @work_thread.abort_on_exception = false
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def run
71
+ # save the queue locally
72
+ local_queue = @queue
73
+ if local_queue.nil?
74
+ @work_thread = nil
75
+ return
76
+ end
77
+
78
+ begin
79
+ # fix up the send interval (can't be lower than 100ms)
80
+ local_send_interval = [@send_interval, 0.1].max
81
+
82
+ while true
83
+ @start_notification_processed = true
84
+ while true
85
+ # get at most @send_buffer_size items from the queue
86
+ data = []
87
+ @send_buffer_size.downto(1) do
88
+ item = local_queue.pop
89
+ break if not item
90
+ data.push item
91
+ end
92
+
93
+ # if we didn't get any items from the queue, we're done here
94
+ break if data.length == 0
95
+
96
+ # reset the send time
97
+ @send_remaining_time = @send_time
98
+
99
+ # finally send the data
100
+ send data
101
+ end
102
+
103
+ # wait at most @send_interval ms (or until we get signalled)
104
+ result = local_queue.flush_notification.wait local_send_interval
105
+ if result
106
+ local_queue.flush_notification.clear
107
+ next
108
+ end
109
+
110
+ # decrement the remaining time
111
+ @send_remaining_time -= local_send_interval
112
+ # If remaining time <=0 and there is no start notification unprocessed,
113
+ # then stop the working thread
114
+ if @send_remaining_time <= 0 && @start_notification_processed
115
+ # Note: there is still a chance some start notification could be
116
+ # missed, e.g., the start method got triggered between the above and
117
+ # following line. However the data is not lost as it would be
118
+ # processed later when next start notification comes after the worker
119
+ # thread stops. The cost to ensure no notification miss is high where
120
+ # a lock is required each time the start method calls.
121
+ @work_thread = nil
122
+ break
123
+ end
124
+ end
125
+ rescue
126
+ # Make sure work_thread sets to nil when it terminates abnormally
127
+ @work_thread = nil
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end