appinsights 0.0.5 → 0.0.6
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 +4 -4
- data/README.md +18 -3
- data/appinsights.gemspec +1 -1
- data/lib/appinsights.rb +1 -0
- data/lib/appinsights/context.rb +10 -0
- data/lib/appinsights/installers/rails.rb +2 -0
- data/lib/appinsights/logger_proxy.rb +54 -0
- data/lib/appinsights/version.rb +1 -1
- data/test/config_loader_test.rb +13 -0
- data/test/logger_proxy_test.rb +43 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0506d8d1fd001b6ffaa47dd345c533ddb89ee2a
|
4
|
+
data.tar.gz: 3c6add6aad383f469058db834ed25b2af82ff748
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f97842a5238eade94e1716738d81ec1e52df3fb497bf37afa66056249a2e598f376b1e231e39d66602ccba74b5b5aa13e5e243b7edb34be4674f90db238c99ea
|
7
|
+
data.tar.gz: 134e2c23dd07ae6c8dd81cfc37751f9d2f28146b2c72c1e5cf6028197f0bc751fe75ef7e63cd62993bc81c8c2e12a5fdefa3b001715f8de325c82bc33d251545
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# appinsights
|
2
2
|
[](http://badge.fury.io/rb/appinsights)
|
3
|
-
[](https://gemnasium.com/citrusbyte/appinsights)
|
3
|
+
[](https://travis-ci.org/Theorem/appinsights)
|
4
|
+
[](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
|
+

|
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._
|
data/appinsights.gemspec
CHANGED
@@ -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/
|
11
|
+
s.homepage = 'http://github.com/Theorem/appinsights'
|
12
12
|
s.license = 'MIT'
|
13
13
|
|
14
14
|
s.files = Dir[
|
data/lib/appinsights.rb
CHANGED
@@ -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
|
data/lib/appinsights/context.rb
CHANGED
@@ -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|
|
@@ -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
|
data/lib/appinsights/version.rb
CHANGED
data/test/config_loader_test.rb
CHANGED
@@ -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.
|
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:
|
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/
|
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.
|
103
|
+
rubygems_version: 2.5.2.3
|
102
104
|
signing_key:
|
103
105
|
specification_version: 4
|
104
106
|
summary: Application Insights Auto-Installer
|