rails_opentracer 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebecd0945eb679dfeb98e6cca76563c0f0876be5
4
- data.tar.gz: 1b74a57df36cb548c7afac1930e0fceb525680aa
3
+ metadata.gz: d15842672de526bc49701d76608ad4721e9296aa
4
+ data.tar.gz: 9b4b7e1859877526b2212eb1a2099c8089ca15fb
5
5
  SHA512:
6
- metadata.gz: 3790f9481f5e7d2687fd1e5ea6b481beab79a7f4ebf717c3805d3a1cb446b92de37ddda3f844845061f9f6e6ed1c4bb381b3a268994ef21b755d3b9cb703c3bf
7
- data.tar.gz: c67f581ca1bb9d16e42b77c0899c0f84656fe9a34d278de18e3395aae4e579363da949bc97b0f1283971e6564a073a0f6d279314349536eeb7f3532833944d44
6
+ metadata.gz: aa2a5835ea28709c759a8410e03a4b565c4a9b7251d4f94297e15f0ca1aacca7d0b0e0d69c4996b6fb4bf07d698517b57a04b822a174bb5222051fb458deb497
7
+ data.tar.gz: e04c7d812f52162fe813dc07633165d867447499303db62809c88f7f5a4bcaa4b2a1751185ff3e5b1952df301a607eb05205bd534e0c26239e2c995716286db0
data/README.md CHANGED
@@ -9,7 +9,7 @@ TODO:
9
9
  - Testz
10
10
  - Is faraday_tracer.rb required ?
11
11
  - Instrument active record tracing (and give creditz to ruby-rails-tracer's dude)
12
- - Are all those generators "the way" we want to do thingz?
12
+ - Are all those generators "the way" we want to do things?
13
13
 
14
14
  ## Installation
15
15
 
@@ -0,0 +1,65 @@
1
+ module ActiveRecord
2
+ module RailsOpentracer
3
+ DEFAULT_OPERATION_NAME = "sql.query".freeze
4
+
5
+ class << self
6
+ def instrument(tracer: OpenTracing.global_tracer, active_span: nil)
7
+ clear_subscribers
8
+ @subscriber = ::ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
9
+ ActiveRecord::Tracer.sql(tracer: tracer, active_span: active_span, args: args)
10
+ end
11
+
12
+ self
13
+ end
14
+
15
+ def disable
16
+ if @subscriber
17
+ ActiveSupport::Notifications.unsubscribe(@subscriber)
18
+ @subscriber = nil
19
+ end
20
+
21
+ self
22
+ end
23
+ alias :clear_subscribers :disable
24
+
25
+ def sql(tracer: OpenTracing.global_tracer, active_span: nil, args:)
26
+ _, start, finish, _, payload = *args
27
+
28
+ span = start_span(payload.fetch(:name),
29
+ tracer: tracer,
30
+ active_span: active_span,
31
+ start_time: start,
32
+ sql: payload.fetch(:sql),
33
+ cached: payload.fetch(:cached, false),
34
+ connection_id: payload.fetch(:connection_id))
35
+
36
+ if payload[:exception]
37
+ RailsOpenTracer::SpanHelpers.set_error(span, payload[:exception_object] || payload[:exception])
38
+ end
39
+
40
+ span.finish(end_time: finish)
41
+ end
42
+
43
+
44
+ def start_span(operation_name, tracer: OpenTracing.global_tracer, active_span: nil, start_time: Time.now, **fields)
45
+ connection_config = ::ActiveRecord::Base.connection_config
46
+
47
+ span = tracer.start_span(operation_name || DEFAULT_OPERATION_NAME,
48
+ child_of: active_span.respond_to?(:call) ? active_span.call : active_span,
49
+ start_time: start_time,
50
+ tags: {
51
+ 'component' => 'ActiveRecord',
52
+ 'span.kind' => 'client',
53
+ 'db.user' => connection_config.fetch(:username, 'unknown'),
54
+ 'db.instance' => connection_config.fetch(:database),
55
+ 'db.vendor' => connection_config.fetch(:adapter),
56
+ 'db.connection_id' => fields.fetch(:connection_id, 'unknown'),
57
+ 'db.cached' => fields.fetch(:cached, false),
58
+ 'db.statement' => fields.fetch(:sql),
59
+ 'db.type' => 'sql'
60
+ })
61
+ span
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,17 @@
1
+ module RailsOpentracer
2
+ module SpanHelpers
3
+ class << self
4
+ def set_error(span, exception)
5
+ span.set_tag('error', true)
6
+
7
+ case exception
8
+ when Array
9
+ exception_class, exception_message = exception
10
+ span.log(event: 'error', :'error.kind' => exception_class, message: exception_message)
11
+ when Exception
12
+ span.log(event: 'error', :'error.object' => exception)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsOpentracer
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -1,7 +1,20 @@
1
+ require 'rails_opentracing/activerecord/rails_opentracer.rb'
2
+ require 'rails_opentracing/span_helpers'
1
3
  require 'rails_opentracer/version'
2
4
  require 'faraday'
3
5
 
4
6
  module RailsOpentracer
7
+
8
+ class << self
9
+ def instrument(tracer: OpenTracing.global_tracer, active_span: nil, active_record: true)
10
+ ActiveRecord::RailsOpentracer.instrument(tracer: tracer, active_span: active_span) if active_record
11
+ end
12
+
13
+ def disable
14
+ ActiveRecord::RailsOpenTracer.disable
15
+ end
16
+ end
17
+
5
18
  def get(url)
6
19
  connection = Faraday.new do |con|
7
20
  con.use FaradayTracer
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_opentracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Erasmus
@@ -115,6 +115,8 @@ files:
115
115
  - lib/generators/templates/rails_opentracer_initializer.rb
116
116
  - lib/generators/templates/tracer.rb
117
117
  - lib/rails_opentracer.rb
118
+ - lib/rails_opentracer/active_record/rails_opentracer.rb
119
+ - lib/rails_opentracer/span_helpers.rb
118
120
  - lib/rails_opentracer/version.rb
119
121
  - rails_opentracer.gemspec
120
122
  homepage: https://github.com/nuclearnic/rails_opentracer