appinsights 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01003d9d4c44a67f7f73bb0ff83ce5a4d763a4ac
4
- data.tar.gz: 880be6e1ab0a7bbb7726900c7c4af58b7dee518e
3
+ metadata.gz: 9d20dcc9f60a001f8ace5c97f9e9cb8157c0a9de
4
+ data.tar.gz: 83e30a63ca45290f6089ca93a221a67b85908307
5
5
  SHA512:
6
- metadata.gz: fc062486cb66e7ca600f8f278e08a7a7e08cbddf370c4fbe7d5148d396a35439adce123fccbe9261b31134a9ab888284a5e7d7eac44e7c658bf7417794d0df09
7
- data.tar.gz: 49ae01dd89528edbfda574e6bd43b33ab4415ccd6ae6502aff308074c7e7cc7c1161183be3512508151fcd43cdf101949f08532b8d31dc946d1bb9b1bec5ce74
6
+ metadata.gz: ff7a702005292eaa2e6d2e8dbc6ff960c8cfe82c1905d2a9f642e48418d501a0fe1d58980d2a3a978c539661071c07b9975cc4ef6acee48f5645647bdd7f0137
7
+ data.tar.gz: 969fa848c73a60da51faec3ffb187082f5598bda75ac607cc8590757a3c9684b3a1d30a851b5f91bd50c4e42f55a990494dd23278e469602464e96d86d7ae360
data/README.md CHANGED
@@ -5,3 +5,191 @@
5
5
  [![Dependency Status](https://gemnasium.com/citrusbyte/appinsights.svg)](https://gemnasium.com/citrusbyte/appinsights)
6
6
 
7
7
  Microsoft Application Insights Auto Installer for Ruby frameworks
8
+
9
+ ## Dependencies
10
+
11
+ `appinsights` requires:
12
+
13
+ - Ruby 2.0 or later
14
+ - `application_insights` to connect with Microsoft Application Insights
15
+ - `toml-rb` to read the config file
16
+
17
+ Install dependencies using `dep` is easy as run:
18
+
19
+ $ dep install
20
+
21
+ # Installation
22
+
23
+ Install the latest release using `gem`
24
+
25
+ $ gem install appinsights
26
+
27
+ Or just add `gem 'appinsights'` in your _Gemfile_ and then run:
28
+
29
+ $ bundle install
30
+
31
+ ## Automatic
32
+
33
+ This is the recommended installation and it will be automatically fired if your
34
+ application uses one of the supported frameworks:
35
+
36
+ - Rails
37
+ - Sinatra
38
+
39
+ In case the _automatic installation_ is not available (non-supported framework,
40
+ missing config file, etc.) you can always install the Application Insights Instruments
41
+ using the _Manual_ installation
42
+
43
+
44
+ ### Rails
45
+
46
+ `rails` automatically loads the gem if it is listed on the _Gemfile_.
47
+ There is nothing else to do.
48
+
49
+ ### Sinatra
50
+
51
+ `sinatra`, like other `rack` based frameworks, needs to require the library.
52
+
53
+ Add the following line in your _sinatra application file_:
54
+
55
+ require 'appinsights'
56
+
57
+ > NOTE: Ensure that `sinatra` was required first.
58
+
59
+ ## Manual
60
+
61
+ Choosing a _Manual_ configuration is for those who have an application using a
62
+ non-supported framework or the ones who wants to have total control of the application.
63
+
64
+ The only requisite for your _application_ is to support usage of `rack` middlewares.
65
+
66
+ ```ruby
67
+ require 'appinsights'
68
+
69
+ # app - Application where we will attach the middlewares
70
+ # root - Root directory of the application
71
+ # filename (optional) - Relative path of the config file
72
+ # logger (optional) - Logger object to log errors and info.
73
+
74
+ installer = AppInsights::BaseInstaller.new app, root, filename, logger
75
+
76
+ # Now you have an installer ready to be executed
77
+
78
+ installer.install
79
+
80
+ # This will load the configuration file and add the middlewares enabled on the
81
+ # config file.
82
+ ```
83
+
84
+ In case you want to check the configs or which middlewares were enabled using
85
+ ruby code, here is some useful lines of code:
86
+
87
+ ```ruby
88
+ # Check the Context settings.
89
+ Application::Context.context
90
+ => #<ApplicationInsights::Channel::TelemetryContext:0x007f961dbf3b18 ...>
91
+
92
+
93
+ # Check the Middlewares settings
94
+ AppInsights::Middlewares.settings
95
+ => [{"name"=>"AppInsights::ExceptionHandling", "enabled"=>true}, ... ]
96
+
97
+ # Check the Middlewares enabled
98
+ AppInsights::Middlewares.enabled
99
+ => [[AppInsights::ExceptionHandling, {}], ... ]
100
+ ```
101
+
102
+
103
+ # Configuration file
104
+
105
+ `appinsights` uses TOML, a minimal configuration file format that's easy to read.
106
+ If you are not familiar with TOML, please [read the specs][toml_specs].
107
+
108
+ ## Structure
109
+
110
+ There are two big _structures_ inside the configuration file.
111
+
112
+ 1. Application Insights Context settings
113
+ 2. Middlewares
114
+
115
+ ### 1. Application Insights Context settings
116
+
117
+ All this settings must be grouped by _'ai'_ table.
118
+ This settings are defined for every _contract_ on the [SDK][ai_sdk]
119
+
120
+ The only exception and the most important setting is the **instrumentation_key**
121
+ that must be defined under the _'ai'_ table.
122
+
123
+ Lets see an example:
124
+
125
+ ```toml
126
+ [ai]
127
+ instrumentation_key = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
128
+ custom = 4
129
+ properties = 'belong to the context'
130
+
131
+ # Contracts configuration
132
+
133
+ [ai.application]
134
+ ver = '0.2.0'
135
+
136
+ [ai.device]
137
+ id = 'device001'
138
+ os = 'OSX'
139
+
140
+ [ai.user]
141
+ id = 'a_user_id'
142
+ accountId = '1234567890'
143
+ ```
144
+
145
+ ### 2. Middlewares
146
+
147
+ This is the other important structure on the configuration file.
148
+ Here we will define which middleware we want to use and enable or disable it.
149
+ We defined `appinsights` to be as flexible as possible, so we can configure
150
+ middlewares defined in other libraries but they were defined in our scope.
151
+
152
+ Of course that you can add extra parameters for your personal usage but
153
+ there are two required parameters for every _middleware_ definition:
154
+
155
+ - `name` - Complete constant name of the middleware
156
+ - `enabled` - boolean
157
+
158
+ And given there are some _middleware_ which needs extra parameters at the
159
+ initialization process, you can define a hash with the attributes and we will
160
+ preserve the order of the attributes defined.
161
+
162
+ If you are a little confused, here is a valid example for both scenarios:
163
+
164
+ ```toml
165
+ [[middleware]]
166
+ name = 'AppInsights::ExceptionHandling'
167
+ enabled = true
168
+
169
+ [[middleware]]
170
+ name = 'ApplicationInsights::Rack::TrackRequest'
171
+ enabled = true
172
+
173
+ [middleware.initialize]
174
+ instrumentation_key = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
175
+ buffer_size = 250
176
+ send_interval = 30
177
+ ```
178
+
179
+ ## Location
180
+
181
+ By default `appinsights` will search for the configuration file, starting at
182
+ the root of the project
183
+
184
+ - `./config/application_insights.toml`
185
+ - `./application_insights.toml`
186
+
187
+ You can also use a custom file name and path before start the application.
188
+ Set the environment variable `AI_CONFIG_RPATH` with the relative path of the file
189
+
190
+ $ export AI_CONFIG_RPATH='./settings/appinsights_settings.toml'
191
+
192
+
193
+
194
+ [toml_specs]: https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.3.1.md
195
+ [ai_sdk]: https://github.com/Microsoft/AppInsights-Ruby/tree/master/lib/application_insights/channel/contracts
@@ -1,4 +1,4 @@
1
- require_relative 'lib/version'
1
+ require_relative 'lib/appinsights/version'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'appinsights'
@@ -1,14 +1,14 @@
1
- require_relative 'errors'
2
- require_relative 'context'
3
- require_relative 'middlewares'
4
- require_relative 'config_loader'
5
- require_relative 'installers/base'
1
+ require_relative 'appinsights/errors'
2
+ require_relative 'appinsights/context'
3
+ require_relative 'appinsights/middlewares'
4
+ require_relative 'appinsights/config_loader'
5
+ require_relative 'appinsights/installers/base'
6
6
 
7
7
  module AppInsights
8
8
  if defined?(Rails::VERSION)
9
- require_relative 'installers/rails'
9
+ require_relative 'appinsights/installers/rails'
10
10
  elsif defined?(Sinatra::VERSION)
11
- require_relative 'installers/sinatra'
11
+ require_relative 'appinsights/installers/sinatra'
12
12
  else
13
13
  require 'logger'
14
14
 
File without changes
@@ -0,0 +1,18 @@
1
+ require_relative 'base'
2
+
3
+ module AppInsights
4
+ class RailsInstaller < Rails::Railtie
5
+ initializer 'appinsights.start_plugin' do |_app|
6
+ init Rails.root
7
+ end
8
+
9
+ def init(root, filename = nil)
10
+ installer = AppInsights::BaseInstaller.new config.app_middleware,
11
+ root,
12
+ filename,
13
+ Rails.logger
14
+
15
+ installer.install
16
+ end
17
+ end
18
+ end
@@ -7,9 +7,9 @@ module AppInsights
7
7
  end
8
8
 
9
9
  def self.init(root, filename = nil)
10
- installer = AppInsights::Base.new Sinatra::Application,
11
- root,
12
- filename
10
+ installer = AppInsights::BaseInstaller.new Sinatra::Application,
11
+ root,
12
+ filename
13
13
 
14
14
  installer.install
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module AppInsights
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  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.2
4
+ version: 0.0.3
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-12 00:00:00.000000000 Z
11
+ date: 2015-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: toml-rb
@@ -68,15 +68,15 @@ files:
68
68
  - README.md
69
69
  - appinsights.gemspec
70
70
  - lib/appinsights.rb
71
- - lib/config_loader.rb
72
- - lib/context.rb
73
- - lib/errors.rb
74
- - lib/installers/base.rb
75
- - lib/installers/rails.rb
76
- - lib/installers/sinatra.rb
77
- - lib/middlewares.rb
78
- - lib/middlewares/exception_handling.rb
79
- - lib/version.rb
71
+ - lib/appinsights/config_loader.rb
72
+ - lib/appinsights/context.rb
73
+ - lib/appinsights/errors.rb
74
+ - lib/appinsights/installers/base.rb
75
+ - lib/appinsights/installers/rails.rb
76
+ - lib/appinsights/installers/sinatra.rb
77
+ - lib/appinsights/middlewares.rb
78
+ - lib/appinsights/middlewares/exception_handling.rb
79
+ - lib/appinsights/version.rb
80
80
  - rakefile
81
81
  - test/base_installer_test.rb
82
82
  - test/config_loader_test.rb
@@ -1,16 +0,0 @@
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