appinsights 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/appinsights.gemspec +4 -2
- data/lib/appinsights.rb +10 -8
- data/lib/config_loader.rb +2 -2
- data/lib/context.rb +4 -0
- data/lib/installers/base.rb +34 -0
- data/lib/installers/rails.rb +16 -0
- data/lib/installers/sinatra.rb +20 -0
- data/lib/version.rb +3 -0
- data/test/base_installer_test.rb +50 -0
- data/test/config_loader_test.rb +10 -0
- data/test/middlewares_test.rb +5 -7
- metadata +9 -5
- data/lib/frameworks/rails.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01003d9d4c44a67f7f73bb0ff83ce5a4d763a4ac
|
4
|
+
data.tar.gz: 880be6e1ab0a7bbb7726900c7c4af58b7dee518e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc062486cb66e7ca600f8f278e08a7a7e08cbddf370c4fbe7d5148d396a35439adce123fccbe9261b31134a9ab888284a5e7d7eac44e7c658bf7417794d0df09
|
7
|
+
data.tar.gz: 49ae01dd89528edbfda574e6bd43b33ab4415ccd6ae6502aff308074c7e7cc7c1161183be3512508151fcd43cdf101949f08532b8d31dc946d1bb9b1bec5ce74
|
data/README.md
CHANGED
@@ -1,2 +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)
|
6
|
+
|
7
|
+
Microsoft Application Insights Auto Installer for Ruby frameworks
|
data/appinsights.gemspec
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
require_relative 'lib/version'
|
2
|
+
|
1
3
|
Gem::Specification.new do |s|
|
2
4
|
s.name = 'appinsights'
|
3
|
-
s.version =
|
5
|
+
s.version = AppInsights::VERSION
|
4
6
|
s.date = Time.now.strftime('%Y-%m-%d')
|
5
7
|
s.summary = 'Application Insights Auto-Installer'
|
6
8
|
s.description = 'Application Insights AutoInstaller for Ruby'
|
@@ -20,5 +22,5 @@ Gem::Specification.new do |s|
|
|
20
22
|
s.add_dependency 'toml-rb', '~> 0.2.1'
|
21
23
|
s.add_dependency 'application_insights', '~> 0.5.0'
|
22
24
|
|
23
|
-
s.add_development_dependency 'rack', '~> 1.6', '>= 1.
|
25
|
+
s.add_development_dependency 'rack', '~> 1.6', '>= 1.0.0'
|
24
26
|
end
|
data/lib/appinsights.rb
CHANGED
@@ -2,19 +2,21 @@ require_relative 'errors'
|
|
2
2
|
require_relative 'context'
|
3
3
|
require_relative 'middlewares'
|
4
4
|
require_relative 'config_loader'
|
5
|
+
require_relative 'installers/base'
|
5
6
|
|
6
7
|
module AppInsights
|
7
8
|
if defined?(Rails::VERSION)
|
8
|
-
require_relative '
|
9
|
+
require_relative 'installers/rails'
|
10
|
+
elsif defined?(Sinatra::VERSION)
|
11
|
+
require_relative 'installers/sinatra'
|
9
12
|
else
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
require 'logger'
|
14
|
+
|
15
|
+
logger = Logger.new STDOUT
|
16
|
+
logger.info <<-EOS
|
17
|
+
Framework unknown, auto installation suspended.
|
18
|
+
Use AppInsights::BaseInstaller.new app, root, filename
|
13
19
|
to setup the Context and middlewares.
|
14
20
|
EOS
|
15
|
-
|
16
|
-
# Initialize for other frameworks
|
17
|
-
#
|
18
|
-
# loader = ConfigLoader.new __FILE__
|
19
21
|
end
|
20
22
|
end
|
data/lib/config_loader.rb
CHANGED
data/lib/context.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
module AppInsights
|
2
|
+
class BaseInstaller
|
3
|
+
attr_accessor :app, :root, :filename, :logger
|
4
|
+
|
5
|
+
def initialize(app, root, filename = nil, logger = nil)
|
6
|
+
@app, @root, @filename, @logger = app, root, filename, logger
|
7
|
+
end
|
8
|
+
|
9
|
+
def install
|
10
|
+
AppInsights::ConfigLoader.new @root, @filename
|
11
|
+
|
12
|
+
AppInsights::Middlewares.enabled.each do |middleware, args|
|
13
|
+
@app.use middleware, *args.values
|
14
|
+
end
|
15
|
+
rescue AppInsights::ConfigFileNotFound => e
|
16
|
+
@logger.error e.message
|
17
|
+
@logger.info config_file_not_found_message
|
18
|
+
end
|
19
|
+
|
20
|
+
def logger
|
21
|
+
@logger ||= Logger.new STDOUT
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def config_file_not_found_message
|
27
|
+
<<-EOS
|
28
|
+
Place your config file `application_insights.toml`
|
29
|
+
under the `config` or root directory of your application.
|
30
|
+
Check the README for manual installation.
|
31
|
+
EOS
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module AppInsights
|
2
|
+
class RailsInstaller < Rails::Railtie
|
3
|
+
initializer 'appinsights.start_plugin' do |_app|
|
4
|
+
init Rails.root
|
5
|
+
end
|
6
|
+
|
7
|
+
def init(root, filename = nil)
|
8
|
+
installer = AppInsights::Base.new config.app_middleware,
|
9
|
+
root,
|
10
|
+
filename,
|
11
|
+
Rails.logger
|
12
|
+
|
13
|
+
installer.install
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module AppInsights
|
4
|
+
class SinatraInstaller < Sinatra::Application
|
5
|
+
def self.root
|
6
|
+
File.dirname app_file
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.init(root, filename = nil)
|
10
|
+
installer = AppInsights::Base.new Sinatra::Application,
|
11
|
+
root,
|
12
|
+
filename
|
13
|
+
|
14
|
+
installer.install
|
15
|
+
end
|
16
|
+
|
17
|
+
# This will call the init method as soon as this file is required
|
18
|
+
SinatraInstaller.init SinatraInstaller.root
|
19
|
+
end
|
20
|
+
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative 'mock/mock_app'
|
3
|
+
require_relative 'mock/mock_logger'
|
4
|
+
|
5
|
+
describe AppInsights::Context do
|
6
|
+
before do
|
7
|
+
@app = MockApp.new
|
8
|
+
@root = './test'
|
9
|
+
@logger = MockLogger.new
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'install' do
|
13
|
+
it 'logs an error if the config file is not found' do
|
14
|
+
installer = AppInsights::BaseInstaller.new @app, @root, 'wrong_file', @logger
|
15
|
+
|
16
|
+
assert @logger.messages.empty?
|
17
|
+
|
18
|
+
installer.install
|
19
|
+
|
20
|
+
deny @logger.messages.empty?
|
21
|
+
assert_equal Logger::ERROR, @logger.messages.first.first
|
22
|
+
assert_equal Logger::INFO, @logger.messages.last.first
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'loads the configs from the file with no errors' do
|
26
|
+
installer = AppInsights::BaseInstaller.new @app, @root, nil, @logger
|
27
|
+
|
28
|
+
assert @logger.messages.empty?
|
29
|
+
|
30
|
+
installer.install
|
31
|
+
context = AppInsights::Context.context
|
32
|
+
|
33
|
+
assert @logger.messages.empty?
|
34
|
+
deny AppInsights::Middlewares.settings.empty?
|
35
|
+
deny AppInsights::Middlewares.enabled.empty?
|
36
|
+
assert_equal 'aaaaaaaa-aaaa-aaaa-aaaa', context.instrumentation_key
|
37
|
+
assert_equal '0.2.0', context.application.ver
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'register the middlewares automatically' do
|
41
|
+
installer = AppInsights::BaseInstaller.new @app, @root, nil, @logger
|
42
|
+
|
43
|
+
assert @app.middlewares.empty?
|
44
|
+
|
45
|
+
installer.install
|
46
|
+
|
47
|
+
deny @app.middlewares.empty?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/test/config_loader_test.rb
CHANGED
@@ -33,6 +33,16 @@ describe AppInsights::ConfigLoader do
|
|
33
33
|
deny loader.settings.empty?
|
34
34
|
end
|
35
35
|
|
36
|
+
it 'loads the config file from the ENV variable' do
|
37
|
+
ENV['AI_CONFIG_RPATH'] = 'test/config/non_default_file.toml'
|
38
|
+
|
39
|
+
loader = AppInsights::ConfigLoader.new './'
|
40
|
+
|
41
|
+
deny loader.settings.empty?
|
42
|
+
|
43
|
+
ENV.delete 'AI_CONFIG_RPATH'
|
44
|
+
end
|
45
|
+
|
36
46
|
it 'autoconfigure the Context and middlewares' do
|
37
47
|
tc = AppInsights::Context.telemetry_client
|
38
48
|
settings = AppInsights::Middlewares.settings
|
data/test/middlewares_test.rb
CHANGED
@@ -2,6 +2,11 @@ require_relative 'helper'
|
|
2
2
|
|
3
3
|
describe AppInsights::Middlewares do
|
4
4
|
before do
|
5
|
+
AppInsights::Middlewares.tap do |klass|
|
6
|
+
klass.instance_variable_set :@settings, nil
|
7
|
+
klass.instance_variable_set :@enabled_middlewares, nil
|
8
|
+
end
|
9
|
+
|
5
10
|
@configs = [
|
6
11
|
{
|
7
12
|
'name' => 'AppInsights::ExceptionHandling',
|
@@ -14,13 +19,6 @@ describe AppInsights::Middlewares do
|
|
14
19
|
]
|
15
20
|
end
|
16
21
|
|
17
|
-
after do
|
18
|
-
AppInsights::Middlewares.tap do |klass|
|
19
|
-
klass.instance_variable_set :@settings, nil
|
20
|
-
klass.instance_variable_set :@enabled_middlewares, nil
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
22
|
describe 'enabled' do
|
25
23
|
it 'returns the middlewares enabled' do
|
26
24
|
AppInsights::Middlewares.configure @configs
|
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.2
|
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-02-
|
11
|
+
date: 2015-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: toml-rb
|
@@ -47,7 +47,7 @@ dependencies:
|
|
47
47
|
version: '1.6'
|
48
48
|
- - ">="
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: 1.
|
50
|
+
version: 1.0.0
|
51
51
|
type: :development
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
version: '1.6'
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: 1.
|
60
|
+
version: 1.0.0
|
61
61
|
description: Application Insights AutoInstaller for Ruby
|
62
62
|
email:
|
63
63
|
- emiliano.mancuso@gmail.com
|
@@ -71,10 +71,14 @@ files:
|
|
71
71
|
- lib/config_loader.rb
|
72
72
|
- lib/context.rb
|
73
73
|
- lib/errors.rb
|
74
|
-
- lib/
|
74
|
+
- lib/installers/base.rb
|
75
|
+
- lib/installers/rails.rb
|
76
|
+
- lib/installers/sinatra.rb
|
75
77
|
- lib/middlewares.rb
|
76
78
|
- lib/middlewares/exception_handling.rb
|
79
|
+
- lib/version.rb
|
77
80
|
- rakefile
|
81
|
+
- test/base_installer_test.rb
|
78
82
|
- test/config_loader_test.rb
|
79
83
|
- test/context_test.rb
|
80
84
|
- test/helper.rb
|
data/lib/frameworks/rails.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
module AppInsights
|
2
|
-
class Railtie < Rails::Railtie
|
3
|
-
initializer 'ai_agent.start_plugin' do |_app|
|
4
|
-
AppInsights::ConfigLoader.new Rails.root
|
5
|
-
|
6
|
-
AppInsights::Middlewares.enabled.each do |middleware, args|
|
7
|
-
config.app_middleware.use middleware, *args.values
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|