rack-instrumentation 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f316ead3113e6157837293e94c50dc528466f27ee8983b8911f8630ce71f783d
4
+ data.tar.gz: 5a47543c79961dc0b2ef7af9f6ec7b3b7e390a160f34308898fdcf2f14a748cc
5
+ SHA512:
6
+ metadata.gz: b9c23714e2f2444d4c005f272ecff7a3bb2b3f927aa3dcc54a8ac17c1266baccdae89d5fd29e2adc9adcde11f58b9543c8a7cb7f70a2d72548bfa51ddc537a26
7
+ data.tar.gz: 8c122474d7dc0e302ce4a2190496eabdaf55dbd54bf10e4aba79cfc9c4f579050bccfc5076030cfb88af081e52618490907d5a4895f26beafb11ea0f804656c6
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ Changelog
2
+ =========
3
+
4
+ ## 0.1.0 11/07/2019
5
+ * Instrumention for OpenTracing using the rack middleware
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rack-instrumentation-ruby.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rack-instrumentation (0.1.0.pre)
5
+ opentracing (~> 0.5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ opentracing (0.5.0)
12
+ opentracing_test_tracer (0.1.1)
13
+ opentracing
14
+ rack (2.0.7)
15
+ rake (10.5.0)
16
+ rspec (3.9.0)
17
+ rspec-core (~> 3.9.0)
18
+ rspec-expectations (~> 3.9.0)
19
+ rspec-mocks (~> 3.9.0)
20
+ rspec-core (3.9.0)
21
+ rspec-support (~> 3.9.0)
22
+ rspec-expectations (3.9.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.9.0)
25
+ rspec-mocks (3.9.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.9.0)
28
+ rspec-support (3.9.0)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 2.0)
35
+ opentracing_test_tracer (~> 0.1)
36
+ rack (~> 2.0)
37
+ rack-instrumentation!
38
+ rake (~> 10.0)
39
+ rspec (~> 3.0)
40
+
41
+ BUNDLED WITH
42
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Josh Lauer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # rack-instrumentation
2
+
3
+ Open Tracing instrumentation for [rack](https://github.com/rack/rack). By default it starts a new span for every request and follows the open tracing tagging [semantic conventions](https://opentracing.io/specification/conventions). This is inspired by the [rack-tracer](https://github.com/opentracing-contrib/ruby-rack-tracer) gem, and sections of the code here are taken from there.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "rack-instrumentation"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rack-instrumentation
20
+
21
+ ## Usage
22
+
23
+ Require the gem (Note: this won't automatically instrument rack)
24
+ ```ruby
25
+ require "rack/instrumentation"
26
+ ```
27
+
28
+ If you have set up `OpenTracing.global_tracer` you can turn on spans for all requests in your `config.ru` thusly:
29
+ ```ruby
30
+ use Rack::OpenTracing::Tracer
31
+ ```
32
+
33
+ Similarly, this works for rails applications:
34
+ ```ruby
35
+ Rails.application.configure do
36
+ config.middleware.use Rack::Instrumentation::Tracer
37
+ end
38
+ ```
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rack-instrumentation-ruby.
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rack/instrumentation"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ require "rack/instrumentation/version"
2
+ require "rack/instrumentation/tracer"
3
+
4
+ module Rack
5
+ module Instrumentation
6
+ end
7
+ end
@@ -0,0 +1,70 @@
1
+ require "rack/instrumentation/version"
2
+ require "opentracing"
3
+
4
+ module Rack
5
+ module Instrumentation
6
+ class Tracer
7
+ attr_reader :app, :tracer
8
+
9
+ # Create a new Rack Tracer middleware.
10
+ #
11
+ # @param app The Rack application/middlewares stack.
12
+ # @param tracer [OpenTracing::Tracer] A tracer to be used when start_span, and extract
13
+ # is called.
14
+ def initialize(app, tracer: OpenTracing.global_tracer)
15
+ @app = app
16
+ @tracer = tracer
17
+ end
18
+
19
+ def call(env)
20
+ tracer.start_active_span(*span_args(env)) do |scope|
21
+ span = scope.span
22
+ env['rack.span'] = span
23
+
24
+ app.call(env).tap do |status_code, _headers, _body|
25
+ span.set_tag('http.status_code', status_code)
26
+
27
+ route = route_from_env(env)
28
+ span.operation_name = route if route
29
+ end
30
+ rescue StandardError => e
31
+ span.set_tag('error', true)
32
+ span.log_kv(
33
+ event: 'error',
34
+ :'error.kind' => e.class.to_s,
35
+ :'error.object' => e,
36
+ message: e.message,
37
+ stack: e.backtrace.join("\n")
38
+ )
39
+ raise
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def span_args(env)
46
+ method = env["REQUEST_METHOD"]
47
+ context = tracer.extract(OpenTracing::FORMAT_RACK, env)
48
+
49
+ [
50
+ method,
51
+ child_of: context,
52
+ tags: {
53
+ 'component' => 'rack',
54
+ 'span.kind' => 'server',
55
+ 'http.method' => method,
56
+ 'http.url' => env["REQUEST_URI"]
57
+ }
58
+ ]
59
+ end
60
+
61
+ def route_from_env(env)
62
+ rails_controller = env['action_controller.instance']
63
+
64
+ if rails_controller
65
+ "#{env["REQUEST_METHOD"]} #{rails_controller.controller_name}/#{rails_controller.action_name}"
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ module Instrumentation
3
+ VERSION = "0.1.0.pre"
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "rack/instrumentation/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rack-instrumentation"
7
+ spec.version = Rack::Instrumentation::VERSION
8
+ spec.authors = ["Josh Lauer"]
9
+ spec.email = ["me@joshlauer.com"]
10
+
11
+ spec.summary = "OpenTracing instrumentation for rack"
12
+ spec.description = "OpenTracing instrumentation for rack"
13
+ spec.homepage = "https://github.com/josh-lauer/rack-instrumentation-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/josh-lauer/rack-instrumentation-ruby"
20
+ spec.metadata["changelog_uri"] = "https://github.com/josh-lauer/rack-instrumentation-ruby/master/CHANGELOG"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "opentracing", "~> 0.5.0"
32
+
33
+ spec.add_development_dependency "bundler", "~> 2.0"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "rack", "~> 2.0"
37
+ spec.add_development_dependency "opentracing_test_tracer", "~> 0.1"
38
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-instrumentation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - Josh Lauer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: opentracing
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: opentracing_test_tracer
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.1'
97
+ description: OpenTracing instrumentation for rack
98
+ email:
99
+ - me@joshlauer.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CHANGELOG.md
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - lib/rack/instrumentation.rb
116
+ - lib/rack/instrumentation/tracer.rb
117
+ - lib/rack/instrumentation/version.rb
118
+ - rack-instrumentation-ruby.gemspec
119
+ homepage: https://github.com/josh-lauer/rack-instrumentation-ruby
120
+ licenses:
121
+ - MIT
122
+ metadata:
123
+ allowed_push_host: https://rubygems.org
124
+ homepage_uri: https://github.com/josh-lauer/rack-instrumentation-ruby
125
+ source_code_uri: https://github.com/josh-lauer/rack-instrumentation-ruby
126
+ changelog_uri: https://github.com/josh-lauer/rack-instrumentation-ruby/master/CHANGELOG
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">"
139
+ - !ruby/object:Gem::Version
140
+ version: 1.3.1
141
+ requirements: []
142
+ rubygems_version: 3.0.3
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: OpenTracing instrumentation for rack
146
+ test_files: []