pantomath 0.4.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.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +78 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +39 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/pantomath.rb +43 -0
  13. data/lib/pantomath/configuration.rb +17 -0
  14. data/lib/pantomath/injector/httparty.rb +23 -0
  15. data/lib/pantomath/injector/net_http.rb +34 -0
  16. data/lib/pantomath/injector/sidekiq.rb +31 -0
  17. data/lib/pantomath/instrumentation/abstract_tracer.rb +115 -0
  18. data/lib/pantomath/instrumentation/action_controller.rb +6 -0
  19. data/lib/pantomath/instrumentation/action_controller/adapter.rb +23 -0
  20. data/lib/pantomath/instrumentation/action_controller/tracer.rb +37 -0
  21. data/lib/pantomath/instrumentation/grape.rb +6 -0
  22. data/lib/pantomath/instrumentation/grape/adapter.rb +22 -0
  23. data/lib/pantomath/instrumentation/grape/tracer.rb +32 -0
  24. data/lib/pantomath/instrumentation/httparty.rb +6 -0
  25. data/lib/pantomath/instrumentation/httparty/adapter.rb +20 -0
  26. data/lib/pantomath/instrumentation/httparty/tracer.rb +26 -0
  27. data/lib/pantomath/instrumentation/net_http.rb +6 -0
  28. data/lib/pantomath/instrumentation/net_http/adapter.rb +25 -0
  29. data/lib/pantomath/instrumentation/net_http/tracer.rb +27 -0
  30. data/lib/pantomath/instrumentation/sidekiq.rb +10 -0
  31. data/lib/pantomath/instrumentation/sidekiq/adapter.rb +23 -0
  32. data/lib/pantomath/instrumentation/sidekiq/tracer.rb +30 -0
  33. data/lib/pantomath/version.rb +5 -0
  34. data/pantomath.gemspec +35 -0
  35. metadata +189 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 917bf553a63cfb0272a0f10f446657cd7f4bae42
4
+ data.tar.gz: 375f7b71616a311721467e58b0dd326ebd67bab8
5
+ SHA512:
6
+ metadata.gz: 74498680cd4f02ca053b48f04523aba2e279e7f2f06be24cf5a58b62c0f386c9dbc4e2b82b8d6d1c7734ba1e2d61f209961525a0d5e5457b5828cdf50b5033d7
7
+ data.tar.gz: d42a4debe96986eb3c7735111eab9421781d043eb187c4053136d989097fff3cd9dce6850b12835678c3406b58fdff8d790c93f09cfc4003e8829af050d3d1f4
@@ -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
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.3
7
+ before_install: gem install bundler -v 1.17.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in pantomath.gemspec
6
+ gemspec
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pantomath (0.4.3)
5
+ jaeger-client (~> 0.10.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.2)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ coderay (1.1.2)
13
+ connection_pool (2.2.2)
14
+ crack (0.4.3)
15
+ safe_yaml (~> 1.0.0)
16
+ diff-lcs (1.3)
17
+ hashdiff (0.3.7)
18
+ httparty (0.16.3)
19
+ mime-types (~> 3.0)
20
+ multi_xml (>= 0.5.2)
21
+ jaeger-client (0.10.0)
22
+ opentracing (~> 0.3)
23
+ thrift
24
+ method_source (0.9.2)
25
+ mime-types (3.2.2)
26
+ mime-types-data (~> 3.2015)
27
+ mime-types-data (3.2018.0812)
28
+ multi_xml (0.6.0)
29
+ opentracing (0.4.3)
30
+ pry (0.12.2)
31
+ coderay (~> 1.1.0)
32
+ method_source (~> 0.9.0)
33
+ public_suffix (3.0.3)
34
+ rack (2.0.6)
35
+ rack-protection (2.0.5)
36
+ rack
37
+ rake (10.5.0)
38
+ redis (4.1.0)
39
+ rspec (3.8.0)
40
+ rspec-core (~> 3.8.0)
41
+ rspec-expectations (~> 3.8.0)
42
+ rspec-mocks (~> 3.8.0)
43
+ rspec-core (3.8.0)
44
+ rspec-support (~> 3.8.0)
45
+ rspec-expectations (3.8.2)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.8.0)
48
+ rspec-mocks (3.8.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.8.0)
51
+ rspec-support (3.8.0)
52
+ safe_yaml (1.0.4)
53
+ sidekiq (5.2.5)
54
+ connection_pool (~> 2.2, >= 2.2.2)
55
+ rack (>= 1.5.0)
56
+ rack-protection (>= 1.5.0)
57
+ redis (>= 3.3.5, < 5)
58
+ thrift (0.11.0.0)
59
+ webmock (3.4.2)
60
+ addressable (>= 2.3.6)
61
+ crack (>= 0.3.2)
62
+ hashdiff
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ bundler (~> 1.17)
69
+ httparty
70
+ pantomath!
71
+ pry
72
+ rake (~> 10.0)
73
+ rspec (~> 3.0)
74
+ sidekiq
75
+ webmock
76
+
77
+ BUNDLED WITH
78
+ 1.17.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Mehmet Emin INAC
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.
@@ -0,0 +1,39 @@
1
+ # Pantomath
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pantomath`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'pantomath'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install pantomath
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pantomath.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pantomath"
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__)
@@ -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,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jaeger/client"
4
+ require "pantomath/version"
5
+ require "pantomath/configuration"
6
+
7
+ module Pantomath
8
+
9
+ def self.configuration
10
+ @configuration ||= Configuration.new
11
+ end
12
+
13
+ def self.configure(&block)
14
+ block.call(configuration)
15
+ end
16
+
17
+ def self.tracer
18
+ @tracer ||= Jaeger::Client.build(
19
+ host: configuration.agent_host,
20
+ port: configuration.agent_port,
21
+ service_name: configuration.service_name
22
+ )
23
+ end
24
+
25
+ def self.active_scope
26
+ tracer.scope_manager.active
27
+ end
28
+
29
+ def self.active_span
30
+ tracer.active_span
31
+ end
32
+
33
+ def self.extract(format, carrier)
34
+ tracer.extract(format, carrier)
35
+ end
36
+
37
+ def self.inject(format, carrier)
38
+ return unless active_span
39
+
40
+ tracer.inject(active_span.context, format, carrier)
41
+ end
42
+
43
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ostruct"
4
+
5
+ module Pantomath
6
+ class Configuration
7
+ attr_accessor :agent_host, :agent_port, :service_name
8
+
9
+ def tag_collectors
10
+ @tag_collectors ||= OpenStruct.new
11
+ end
12
+
13
+ def exclude_patterns
14
+ @exclude_patterns ||= OpenStruct.new
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pantomath
4
+ module Injector
5
+ module HTTParty
6
+
7
+ def initialize(http_method, path, options = {})
8
+ options[:headers] ||= {}
9
+ inject_trace_id(options[:headers])
10
+
11
+ super(http_method, path, options)
12
+ end
13
+
14
+ private
15
+ def inject_trace_id(headers)
16
+ Pantomath.inject(OpenTracing::FORMAT_RACK, headers)
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+
23
+ HTTParty::Request.send(:prepend, Pantomath::Injector::HTTParty)
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pantomath
4
+ module Injector
5
+ module NetHTTP
6
+
7
+ def initialize(path, initheader = nil)
8
+ headers = prepare_headers(initheader)
9
+
10
+ super(path, headers)
11
+ end
12
+
13
+ def initialize_http_header(initheader)
14
+ headers = prepare_headers(initheader)
15
+
16
+ super(headers)
17
+ end
18
+
19
+ private
20
+ def prepare_headers(initheader)
21
+ headers = initheader ? initheader.dup : {}
22
+ inject_trace_id(headers)
23
+ headers
24
+ end
25
+
26
+ def inject_trace_id(headers)
27
+ Pantomath.inject(OpenTracing::FORMAT_RACK, headers)
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+
34
+ Net::HTTPRequest.send(:prepend, Pantomath::Injector::NetHTTP)
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pantomath
4
+ module Injector
5
+ class Sidekiq
6
+ def call(worker_class, job, queue, redis_pool)
7
+ inject_trace_id(job)
8
+ yield
9
+ end
10
+
11
+ private
12
+ def inject_trace_id(job)
13
+ Pantomath.inject(OpenTracing::FORMAT_TEXT_MAP, job)
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+
20
+ Sidekiq.configure_client do |config|
21
+ config.client_middleware do |chain|
22
+ chain.add Pantomath::Injector::Sidekiq
23
+ end
24
+ end
25
+
26
+ Sidekiq.configure_server do |config|
27
+ config.client_middleware do |chain|
28
+ chain.add Pantomath::Injector::Sidekiq
29
+ end
30
+ end
31
+
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pantomath
4
+ module Instrumentation
5
+ class AbstractTracer
6
+
7
+ class << self
8
+ def tag_collector
9
+ Pantomath.configuration.tag_collectors.send(config_name)
10
+ end
11
+
12
+ def exclude_pattern
13
+ Pantomath.configuration.exclude_patterns.send(config_name)
14
+ end
15
+
16
+ private
17
+ def config_name
18
+ @config_name ||= group_name.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
19
+ end
20
+
21
+ def group_name
22
+ name.split("::")[2]
23
+ end
24
+
25
+ end
26
+
27
+ attr_reader :context
28
+
29
+ def initialize(context)
30
+ @context = context
31
+ end
32
+
33
+ def trace(&block)
34
+ return yield if exclude?
35
+
36
+ track(&block)
37
+ end
38
+
39
+ private
40
+ def track
41
+ start_span
42
+ result = yield
43
+ set_status
44
+ result
45
+ rescue Exception => e
46
+ handle_exception(e)
47
+ ensure
48
+ close_span
49
+ end
50
+
51
+ def exclude?
52
+ exclude_pattern && span_name =~ exclude_pattern
53
+ end
54
+
55
+ def start_span
56
+ Pantomath.tracer.start_active_span(
57
+ span_name,
58
+ child_of: tracer_context,
59
+ tags: span_tags
60
+ )
61
+ end
62
+
63
+ def set_status
64
+ Pantomath.active_span.set_tag(*status) if status
65
+ end
66
+
67
+ def span_name
68
+ raise "Should be implemented"
69
+ end
70
+
71
+ def tags
72
+ raise "Should be implemented"
73
+ end
74
+
75
+ def tracer_context; end
76
+
77
+ # Return an array of status tag key and status
78
+ # to set status of Span.
79
+ def status; end
80
+
81
+ def close_span
82
+ Pantomath.active_scope.close if Pantomath.active_scope
83
+ end
84
+
85
+ def span_tags
86
+ tags.merge!(collected_tags)
87
+ end
88
+
89
+ def collected_tags
90
+ return {} unless tag_collector
91
+
92
+ tag_collector.is_a?(Proc) ? context.instance_exec(&tag_collector) : context.send(tag_collector)
93
+ end
94
+
95
+ def exclude_pattern
96
+ self.class.exclude_pattern
97
+ end
98
+
99
+ def tag_collector
100
+ self.class.tag_collector
101
+ end
102
+
103
+ def handle_exception(exception)
104
+ Pantomath.active_span.set_tag(:error, true)
105
+ Pantomath.active_span.log_kv(
106
+ "event": "error",
107
+ "error.object": exception,
108
+ stack: exception.backtrace.take(10) # This is important because stacktrace can be too long which exceeds the maximum udp messages size
109
+ )
110
+ raise exception
111
+ end
112
+
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pantomath/instrumentation/action_controller/adapter"
4
+ require "pantomath/instrumentation/action_controller/tracer"
5
+
6
+ ActionController::Base.send(:include, Pantomath::Instrumentation::ActionController::Adapter)
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pantomath
4
+ module Instrumentation
5
+ module ActionController
6
+ module Adapter
7
+ def self.included(base)
8
+ base.send(:around_action, :trace_request)
9
+ end
10
+
11
+ def trace_request(&block)
12
+ tracer.trace(&block)
13
+ end
14
+
15
+ private
16
+ def tracer
17
+ Tracer.new(self)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pantomath/instrumentation/abstract_tracer"
4
+
5
+ module Pantomath
6
+ module Instrumentation
7
+ module ActionController
8
+ class Tracer < AbstractTracer
9
+ private
10
+ def tags
11
+ {
12
+ "span.kind" => "web",
13
+ "span.tracer" => "Pantomath::Tracer::ActionController",
14
+ "http.request.method" => context.request.method,
15
+ "http.request.url" => context.request.original_url,
16
+ "http.request.path" => context.request.path,
17
+ "action_controller.controller_name" => context.controller_name,
18
+ "action_controller.action_name" => context.action_name
19
+ }
20
+ end
21
+
22
+ def span_name
23
+ "#{context.request.method} #{context.request.path}"
24
+ end
25
+
26
+ def tracer_context
27
+ Pantomath.extract(OpenTracing::FORMAT_RACK, context.request.env)
28
+ end
29
+
30
+ def status
31
+ ["http.response.status_code", context.status]
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pantomath/instrumentation/grape/adapter"
4
+ require "pantomath/instrumentation/grape/tracer"
5
+
6
+ Grape::Endpoint.send(:prepend, Pantomath::Instrumentation::Grape::Adapter)
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pantomath
4
+ module Instrumentation
5
+ module Grape
6
+ module Adapter
7
+ def run(env)
8
+ @env = env
9
+ @request = ::Grape::Request.new(env)
10
+
11
+ tracer.trace { super }
12
+ end
13
+
14
+ private
15
+ def tracer
16
+ Tracer.new(self)
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pantomath/instrumentation/abstract_tracer"
4
+
5
+ module Pantomath
6
+ module Instrumentation
7
+ module Grape
8
+ class Tracer < AbstractTracer
9
+ private
10
+ def tags
11
+ {
12
+ "span.kind" => "web",
13
+ "span.tracer" => "Pantomath::Tracer::Grape",
14
+ "http.request.method" => context.route.route_method,
15
+ "http.request.url" => context.request.url,
16
+ "http.request.path" => context.request.path,
17
+ "grape.route.version" => context.route.route_version,
18
+ "grape.route.path" => context.route.route_path
19
+ }
20
+ end
21
+
22
+ def span_name
23
+ "#{context.request.env['REQUEST_METHOD']} #{context.request.path}"
24
+ end
25
+
26
+ def tracer_context
27
+ Pantomath.extract(OpenTracing::FORMAT_RACK, context.request.env)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pantomath/instrumentation/httparty/adapter"
4
+ require "pantomath/instrumentation/httparty/tracer"
5
+
6
+ HTTParty::Request.send(:prepend, Pantomath::Instrumentation::HTTParty::Adapter)
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pantomath
4
+ module Instrumentation
5
+ module HTTParty
6
+ module Adapter
7
+
8
+ def perform(&block)
9
+ tracer.trace { super }
10
+ end
11
+
12
+ private
13
+ def tracer
14
+ Tracer.new(self)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pantomath/instrumentation/abstract_tracer"
4
+
5
+ module Pantomath
6
+ module Instrumentation
7
+ module HTTParty
8
+ class Tracer < AbstractTracer
9
+ private
10
+ def tags
11
+ {
12
+ "span.kind" => "external/http",
13
+ "span.tracer" => "Pantomath::Tracer::HTTParty",
14
+ "external.http.request.method" => context.http_method::METHOD,
15
+ "external.http.request.host" => context.uri.host,
16
+ "external.http.request.path" => context.uri.path
17
+ }
18
+ end
19
+
20
+ def span_name
21
+ "NET/HTTP Call to #{context.uri.host}"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pantomath/instrumentation/net_http/adapter"
4
+ require "pantomath/instrumentation/net_http/tracer"
5
+
6
+ Net::HTTP.send(:prepend, Pantomath::Instrumentation::NetHTTP::Adapter)
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ostruct'
4
+
5
+ module Pantomath
6
+ module Instrumentation
7
+ module NetHTTP
8
+ module Adapter
9
+
10
+ def request(req, body = nil, &block)
11
+ return tracer(req).trace { super } unless started?
12
+
13
+ super
14
+ end
15
+
16
+ private
17
+ def tracer(req)
18
+ context = OpenStruct.new(http: self, req: req)
19
+ Tracer.new(context)
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pantomath/instrumentation/abstract_tracer"
4
+
5
+ module Pantomath
6
+ module Instrumentation
7
+ module NetHTTP
8
+ class Tracer < AbstractTracer
9
+ private
10
+ def tags
11
+ {
12
+ "span.kind" => "external/http",
13
+ "span.tracer" => "Pantomath::Tracer::NetHTTP",
14
+ "external.http.request.method" => context.req.method,
15
+ "external.http.request.host" => context.http.address,
16
+ "external.http.request.port" => context.http.port,
17
+ "external.http.request.path" => context.req.path
18
+ }
19
+ end
20
+
21
+ def span_name
22
+ "NET/HTTP Call to #{context.http.address}"
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pantomath/instrumentation/sidekiq/adapter"
4
+ require "pantomath/instrumentation/sidekiq/tracer"
5
+
6
+ Sidekiq.configure_server do |config|
7
+ config.server_middleware do |chain|
8
+ chain.add Pantomath::Instrumentation::Sidekiq::Adapter
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ostruct"
4
+
5
+ module Pantomath
6
+ module Instrumentation
7
+ module Sidekiq
8
+ class Adapter
9
+
10
+ def call(*args)
11
+ tracer(*args).trace { yield }
12
+ end
13
+
14
+ private
15
+ def tracer(worker, job, queue)
16
+ context = OpenStruct.new(worker: worker, job: job, queue: queue)
17
+ Tracer.new(context)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pantomath/instrumentation/abstract_tracer"
4
+
5
+ module Pantomath
6
+ module Instrumentation
7
+ module Sidekiq
8
+ class Tracer < AbstractTracer
9
+ private
10
+ def tags
11
+ {
12
+ "span.kind" => "async/worker",
13
+ "span.tracer" => "Pantomath::Tracer::Sidekiq",
14
+ "worker.queue" => context.queue,
15
+ "worker.class" => context.job["class"]
16
+ }
17
+ end
18
+
19
+ def span_name
20
+ "Async/Worker #{context.job['class']}"
21
+ end
22
+
23
+ def tracer_context
24
+ Pantomath.extract(OpenTracing::FORMAT_TEXT_MAP, context.job)
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pantomath
4
+ VERSION = "0.4.3"
5
+ end
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "pantomath/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pantomath"
8
+ spec.version = Pantomath::VERSION
9
+ spec.authors = ["Mehmet Emin INAC"]
10
+ spec.email = ["mehmetemininac@gmail.com"]
11
+
12
+ spec.summary = "Opentracing utility"
13
+ spec.description = "Opentracing utility"
14
+ spec.homepage = "https://bitbucket.org/modomoto/pantomath/src"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "jaeger-client", "~> 0.10.0"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.17"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ spec.add_development_dependency "pry"
32
+ spec.add_development_dependency "httparty"
33
+ spec.add_development_dependency "webmock"
34
+ spec.add_development_dependency "sidekiq"
35
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pantomath
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.3
5
+ platform: ruby
6
+ authors:
7
+ - Mehmet Emin INAC
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jaeger-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.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.10.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: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
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: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sidekiq
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Opentracing utility
126
+ email:
127
+ - mehmetemininac@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - Gemfile.lock
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - bin/console
141
+ - bin/setup
142
+ - lib/pantomath.rb
143
+ - lib/pantomath/configuration.rb
144
+ - lib/pantomath/injector/httparty.rb
145
+ - lib/pantomath/injector/net_http.rb
146
+ - lib/pantomath/injector/sidekiq.rb
147
+ - lib/pantomath/instrumentation/abstract_tracer.rb
148
+ - lib/pantomath/instrumentation/action_controller.rb
149
+ - lib/pantomath/instrumentation/action_controller/adapter.rb
150
+ - lib/pantomath/instrumentation/action_controller/tracer.rb
151
+ - lib/pantomath/instrumentation/grape.rb
152
+ - lib/pantomath/instrumentation/grape/adapter.rb
153
+ - lib/pantomath/instrumentation/grape/tracer.rb
154
+ - lib/pantomath/instrumentation/httparty.rb
155
+ - lib/pantomath/instrumentation/httparty/adapter.rb
156
+ - lib/pantomath/instrumentation/httparty/tracer.rb
157
+ - lib/pantomath/instrumentation/net_http.rb
158
+ - lib/pantomath/instrumentation/net_http/adapter.rb
159
+ - lib/pantomath/instrumentation/net_http/tracer.rb
160
+ - lib/pantomath/instrumentation/sidekiq.rb
161
+ - lib/pantomath/instrumentation/sidekiq/adapter.rb
162
+ - lib/pantomath/instrumentation/sidekiq/tracer.rb
163
+ - lib/pantomath/version.rb
164
+ - pantomath.gemspec
165
+ homepage: https://bitbucket.org/modomoto/pantomath/src
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.6.8
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Opentracing utility
189
+ test_files: []