appinsights 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c65da559b14e0faaa10194daca2f4195975ecd8c
4
- data.tar.gz: 0d2407bf143a0dfb1270d17a86109b994449a6dc
3
+ metadata.gz: b0506d8d1fd001b6ffaa47dd345c533ddb89ee2a
4
+ data.tar.gz: 3c6add6aad383f469058db834ed25b2af82ff748
5
5
  SHA512:
6
- metadata.gz: fc79a718e28cb339b430252fbac4f14c2ddabef381d88a4a955880287d29c5f24c693c4d278337aaf85a221dd9e9e25b35ad8b77ffaf38f67e751535a36f4176
7
- data.tar.gz: 38c287810aa1d1fa4506b27ade652a1db0472485bb26ace530dd50055125936decac9d7a05949226193aee16ba219a325c9728c01a160aec87c752c598d1a1d7
6
+ metadata.gz: f97842a5238eade94e1716738d81ec1e52df3fb497bf37afa66056249a2e598f376b1e231e39d66602ccba74b5b5aa13e5e243b7edb34be4674f90db238c99ea
7
+ data.tar.gz: 134e2c23dd07ae6c8dd81cfc37751f9d2f28146b2c72c1e5cf6028197f0bc751fe75ef7e63cd62993bc81c8c2e12a5fdefa3b001715f8de325c82bc33d251545
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # appinsights
2
2
  [![Gem Version](https://badge.fury.io/rb/appinsights.svg)](http://badge.fury.io/rb/appinsights)
3
- [![Build Status](https://travis-ci.org/citrusbyte/appinsights.svg)](https://travis-ci.org/citrusbyte/appinsights)
4
- [![Code Climate](https://codeclimate.com/github/citrusbyte/appinsights/badges/gpa.svg)](https://codeclimate.com/github/citrusbyte/appinsights)
5
- [![Dependency Status](https://gemnasium.com/citrusbyte/appinsights.svg)](https://gemnasium.com/citrusbyte/appinsights)
3
+ [![Build Status](https://travis-ci.org/Theorem/appinsights.svg)](https://travis-ci.org/Theorem/appinsights)
4
+ [![Code Climate](https://codeclimate.com/github/Theorem/appinsights/badges/gpa.svg)](https://codeclimate.com/github/Theorem/appinsights)
6
5
 
7
6
  Microsoft Application Insights Auto Installer for Ruby frameworks
8
7
 
@@ -209,3 +208,19 @@ Set the environment variable `AI_CONFIG_RPATH` with the relative path of the fil
209
208
 
210
209
  [toml_specs]: https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.3.1.md
211
210
  [ai_sdk]: https://github.com/Microsoft/AppInsights-Ruby/tree/master/lib/application_insights/channel/contracts
211
+
212
+ ## About Theorem
213
+
214
+ ![Theorem](docs/images/theorem.jpg)
215
+
216
+ This software is lovingly maintained and funded by Theorem.
217
+ From whiteboarding new concepts to long-term support, Theorem works with startups and large multi-national enterprises to develop new applications, software, services, and platforms to achieve the best results and deliver Full Stack Innovation™
218
+
219
+ At Theorem we believe in and support open-source software.
220
+
221
+ - Check out more of our open-source software at Theorem.
222
+ - Learn more about [our work](https://theorem.co/portfolio).
223
+ - [Hire us](https://theorem.co/contact) to work on your project.
224
+ - [Want to join the team?](https://theorem.co/careers)
225
+
226
+ _Theorem and the Theorem logo are trademarks or registered trademarks of Theorem, LLC._
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.description = 'Application Insights AutoInstaller for Ruby'
9
9
  s.authors = ['Emiliano Mancuso']
10
10
  s.email = ['emiliano.mancuso@gmail.com']
11
- s.homepage = 'http://github.com/citrusbyte/appinsights'
11
+ s.homepage = 'http://github.com/Theorem/appinsights'
12
12
  s.license = 'MIT'
13
13
 
14
14
  s.files = Dir[
@@ -3,6 +3,7 @@ require_relative 'appinsights/errors'
3
3
  require_relative 'appinsights/context'
4
4
  require_relative 'appinsights/middlewares'
5
5
  require_relative 'appinsights/config_loader'
6
+ require_relative 'appinsights/logger_proxy'
6
7
  require_relative 'appinsights/installers/base'
7
8
 
8
9
  module AppInsights
@@ -4,6 +4,16 @@ module AppInsights
4
4
  class Context
5
5
  class << self
6
6
  def configure(config = {})
7
+ if config.fetch('async', false)
8
+ sender = ApplicationInsights::Channel::AsynchronousSender.new
9
+ sender.send_interval = config.fetch('async_send_interval_seconds', 60)
10
+ sender.send_buffer_size = config.fetch('async_send_buffer_size', 100)
11
+ queue = ApplicationInsights::Channel::AsynchronousQueue.new sender
12
+ queue.max_queue_length = config.fetch('async_max_queue_length', 500)
13
+ channel = ApplicationInsights::Channel::TelemetryChannel.new(nil, queue)
14
+ @client = ApplicationInsights::TelemetryClient.new(nil, channel)
15
+ end
16
+
7
17
  @context = telemetry_client.context
8
18
 
9
19
  contracts.each do |contract|
@@ -13,6 +13,8 @@ module AppInsights
13
13
  Rails.logger
14
14
 
15
15
  installer.install
16
+
17
+ Rails.logger = AppInsights::LoggerProxy.new Rails.logger
16
18
  end
17
19
  end
18
20
  end
@@ -0,0 +1,54 @@
1
+ require 'application_insights'
2
+
3
+ module AppInsights
4
+ class LoggerProxy < Object
5
+ @@severity_levels = {
6
+ :debug => ApplicationInsights::Channel::Contracts::SeverityLevel::VERBOSE,
7
+ :info => ApplicationInsights::Channel::Contracts::SeverityLevel::INFORMATION,
8
+ :warn => ApplicationInsights::Channel::Contracts::SeverityLevel::WARNING,
9
+ :error => ApplicationInsights::Channel::Contracts::SeverityLevel::ERROR,
10
+ :fatal => ApplicationInsights::Channel::Contracts::SeverityLevel::CRITICAL,
11
+ :unknown => ApplicationInsights::Channel::Contracts::SeverityLevel::CRITICAL,
12
+ }
13
+
14
+ def initialize(logger, ignore_log_level=false, telemetry_client=nil)
15
+ @logger = logger
16
+ @ignore_log_level = ignore_log_level
17
+ @telemetry_client = telemetry_client
18
+
19
+ %w(debug info warn error fatal unknown).each do |level|
20
+ LoggerProxy.class_eval do
21
+ define_method level.to_sym do |*args , &block|
22
+ if !@ignore_log_level && !logger.send("#{level}?".to_sym)
23
+ return true
24
+ end
25
+
26
+ msg = message(*args, &block)
27
+ tc = @telemetry_client || AppInsights::Context.telemetry_client
28
+ tc.track_trace(msg, @@severity_levels[level.to_sym])
29
+ @logger.send(level, msg, &block)
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ protected
36
+
37
+ def method_missing(name, *args, &block)
38
+ @logger.send(name, *args, &block)
39
+ end
40
+
41
+ private
42
+
43
+ def message(*args, &block)
44
+ if block_given?
45
+ block.call
46
+ else
47
+ args = args.flatten.compact
48
+ args = (args.count == 1 ? args[0] : args)
49
+ args.is_a?(Proc) ? args.call : args
50
+ end
51
+ end
52
+
53
+ end
54
+ end
@@ -1,3 +1,3 @@
1
1
  module AppInsights
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -62,5 +62,18 @@ describe AppInsights::ConfigLoader do
62
62
  deny settings.empty?
63
63
  deny middlewares.empty?
64
64
  end
65
+
66
+ it 'autoconfigure the Context as async' do
67
+ AppInsights::ConfigLoader.new './test/config', 'async_file.toml'
68
+
69
+ tc = AppInsights::Context.telemetry_client
70
+
71
+ assert tc.context.instrumentation_key
72
+ assert_equal 'ApplicationInsights::Channel::AsynchronousQueue', tc.channel.queue.class.name
73
+ assert_equal 'ApplicationInsights::Channel::AsynchronousSender', tc.channel.queue.sender.class.name
74
+ assert_equal 1, tc.channel.queue.sender.send_interval
75
+ assert_equal 2, tc.channel.queue.sender.send_buffer_size
76
+ assert_equal 3, tc.channel.queue.max_queue_length
77
+ end
65
78
  end
66
79
  end
@@ -0,0 +1,43 @@
1
+ require 'application_insights'
2
+ require_relative 'mock/mock_logger'
3
+ require_relative 'mock/mock_telemetry_client'
4
+
5
+ describe AppInsights::LoggerProxy do
6
+ before do
7
+ @client = MockTelemetryClient.new
8
+ @logger = MockLogger.new
9
+ end
10
+
11
+ describe 'log' do
12
+ it 'sends traces to AppInsights' do
13
+ proxy = AppInsights::LoggerProxy.new(@logger, false, @client)
14
+ proxy.level = :info
15
+
16
+ proxy.info('a info message')
17
+
18
+ assert_equal 1, @logger.messages.length
19
+ assert_equal [Logger::INFO, nil, 'a info message'], @logger.messages.first[0, 3]
20
+ assert_equal 1, @client.traces.length
21
+ assert_equal ['a info message', ApplicationInsights::Channel::Contracts::SeverityLevel::INFORMATION], @client.traces.first
22
+ end
23
+
24
+ it 'does not send traces to AppInsights if the log level is too low' do
25
+ proxy = AppInsights::LoggerProxy.new(@logger, false, @client)
26
+ proxy.level = :warn
27
+
28
+ proxy.debug('a debug message')
29
+
30
+ assert @client.traces.empty?
31
+ end
32
+
33
+ it 'sends traces to AppInsights for low log level when telemetry sending is forced' do
34
+ proxy = AppInsights::LoggerProxy.new(@logger, true, @client)
35
+ proxy.level = :warn
36
+
37
+ proxy.debug('a debug message')
38
+
39
+ assert_equal 1, @client.traces.length
40
+ assert_equal ['a debug message', ApplicationInsights::Channel::Contracts::SeverityLevel::VERBOSE], @client.traces.first
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appinsights
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emiliano Mancuso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-31 00:00:00.000000000 Z
11
+ date: 2020-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: toml-rb
@@ -69,6 +69,7 @@ files:
69
69
  - lib/appinsights/installers/cuba.rb
70
70
  - lib/appinsights/installers/rails.rb
71
71
  - lib/appinsights/installers/sinatra.rb
72
+ - lib/appinsights/logger_proxy.rb
72
73
  - lib/appinsights/middlewares.rb
73
74
  - lib/appinsights/middlewares/exception_handling.rb
74
75
  - lib/appinsights/version.rb
@@ -77,8 +78,9 @@ files:
77
78
  - test/config_loader_test.rb
78
79
  - test/context_test.rb
79
80
  - test/helper.rb
81
+ - test/logger_proxy_test.rb
80
82
  - test/middlewares_test.rb
81
- homepage: http://github.com/citrusbyte/appinsights
83
+ homepage: http://github.com/Theorem/appinsights
82
84
  licenses:
83
85
  - MIT
84
86
  metadata: {}
@@ -98,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
100
  version: '0'
99
101
  requirements: []
100
102
  rubyforge_project:
101
- rubygems_version: 2.4.5
103
+ rubygems_version: 2.5.2.3
102
104
  signing_key:
103
105
  specification_version: 4
104
106
  summary: Application Insights Auto-Installer