logtail-rails 0.2.2 → 0.2.4

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
  SHA256:
3
- metadata.gz: ed20f6d4677ee4cce10f91ce1acde469e3f201c12092aaccec4d172137089119
4
- data.tar.gz: 3c8e38d62f4a9b58c37ec1aae0f1cdddbbddec16cd8caf3d790cba641fd8effa
3
+ metadata.gz: 4d238560ec59e0d1b0d936ae0b3b92e11865ba2e80fcc4adeb4d6cb43676c7ae
4
+ data.tar.gz: 97e280b2a2c9297a0862dbbd733a4a36e902928b749be07bed9c904243a167f9
5
5
  SHA512:
6
- metadata.gz: f0394b6d9ec9e4282082ed6abde5ae81a6ec0768faa738c5f6c753535bfb7ddf4e3913839393ef59ddd968d99816a53abf7ad7f6f173ced965c4abb28c20f695
7
- data.tar.gz: 1a77af8d51a25997f1af62d066868fd73bda872b2932c499d688c04829d2a5abad15b3398435db95164e81b8948040725186bb5f36135756cdcf1cc544de9050
6
+ metadata.gz: bc9b5ab10bb6cb45a9896a1056399c5adb5a8297cc06d7b424bd077884ff3848c6892d526004a2c3dc620ff4b2ce0505fc589be9c0d3b4d60485fd8165b7d5eb
7
+ data.tar.gz: 2cbd54fa234e026c71feba8f050e41d6a5b5ae513b806548921943bade86665248a826274d949924b4607a7ce1e72e2fb31137629991ac3cf3c30f59c3d5983c
@@ -27,6 +27,7 @@ jobs:
27
27
  - truffleruby-23.0.0
28
28
  - truffleruby-22.1.0
29
29
  gemfile:
30
+ - rails-edge
30
31
  - rails-7.0
31
32
  - rails-6.1
32
33
  - rails-6.0
@@ -34,6 +35,17 @@ jobs:
34
35
  - rails-5.1
35
36
  - rails-5.0
36
37
  exclude:
38
+ - gemfile: rails-edge
39
+ ruby-version: 2.6.6
40
+ - gemfile: rails-edge
41
+ ruby-version: 2.5.8
42
+ - gemfile: rails-edge
43
+ ruby-version: jruby-9.4.3.0
44
+ - gemfile: rails-edge
45
+ ruby-version: jruby-9.2.14.0
46
+ - gemfile: rails-edge
47
+ ruby-version: truffleruby-23.0.0
48
+
37
49
  - gemfile: rails-7.0
38
50
  ruby-version: 2.6.6
39
51
  - gemfile: rails-7.0
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', github: 'rails/rails', branch: 'main'
4
+
5
+ gem 'logtail'
6
+ gem 'logtail-rack'
7
+
8
+ if RUBY_PLATFORM == "java"
9
+ gem 'mime-types', '2.6.2'
10
+ end
11
+
12
+ gemspec :path => '../'
@@ -7,6 +7,7 @@ module Logtail
7
7
  # @private
8
8
  class LogSubscriber < Integrator
9
9
  def initialize
10
+ require "action_controller"
10
11
  require "action_controller/log_subscriber"
11
12
  require "logtail-rails/action_controller/log_subscriber/logtail_log_subscriber"
12
13
  rescue LoadError => e
@@ -25,6 +25,7 @@ module Logtail
25
25
  )
26
26
  end
27
27
  end
28
+ subscribe_log_level :render_template, :info if defined?(subscribe_log_level)
28
29
 
29
30
  def render_partial(event)
30
31
  return true if silence?
@@ -66,6 +67,18 @@ module Logtail
66
67
  end
67
68
  end
68
69
 
70
+ def self.attach_to(*)
71
+ super
72
+
73
+ if ::Rails::VERSION::MAJOR > 7 || ::Rails::VERSION::MAJOR == 7 && ::Rails::VERSION::MINOR >= 1
74
+ # Clean extra listeners subscribed in parent's attach_to method
75
+ ::ActiveSupport::Notifications.notifier.listeners_for("render_template.action_view")
76
+ .concat(::ActiveSupport::Notifications.notifier.listeners_for("render_layout.action_view")).flatten
77
+ .filter { |listener| listener.delegate.class == ::ActionView::LogSubscriber::Start }
78
+ .each { |listener| ActiveSupport::Notifications.unsubscribe(listener) }
79
+ end
80
+ end
81
+
69
82
  private
70
83
  def log_rendering_start(*args)
71
84
  # Consolidates 2 template rendering events into 1. We don't need 2 events for
@@ -18,6 +18,11 @@ module Logtail
18
18
  # I don't know why this has to be so complicated, but it is. This code was taken from
19
19
  # lograge :/
20
20
  def unsubscribe!(component, type)
21
+ if defined?(type.detach_from)
22
+ type.detach_from(component)
23
+ return
24
+ end
25
+
21
26
  subscriber = find(component, type)
22
27
 
23
28
  if !subscriber
@@ -32,7 +32,16 @@ module Logtail
32
32
  io_device = STDOUT
33
33
  end
34
34
 
35
- self.create_logger(io_device)
35
+ logger = self.create_logger(io_device)
36
+
37
+ if defined?(Sidekiq)
38
+ Sidekiq.configure_server do |config|
39
+ logger = self.create_logger(io_device, config.logger) if config.logger.class == Sidekiq::Logger
40
+ config.logger = logger
41
+ end
42
+ end
43
+
44
+ logger
36
45
  end
37
46
  end
38
47
  end
@@ -0,0 +1,38 @@
1
+ # integrates Logtail::CurrentContext with Sidekiq::Context if installed
2
+
3
+ begin
4
+ require 'sidekiq/job_logger'
5
+
6
+ class Sidekiq::JobLogger
7
+ def call(_item, _queue)
8
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
9
+
10
+ Logtail::CurrentContext.with({ sidekiq: Sidekiq::Context.current.to_h }) do
11
+ @logger.info("start")
12
+
13
+ yield
14
+ end
15
+
16
+ Sidekiq::Context.add(:elapsed, elapsed(start))
17
+ Logtail::CurrentContext.with({ sidekiq: Sidekiq::Context.current.to_h }) do
18
+ @logger.info('done')
19
+ end
20
+ rescue Exception
21
+ Sidekiq::Context.add(:elapsed, elapsed(start))
22
+ Logtail::CurrentContext.with({ sidekiq: Sidekiq::Context.current.to_h }) do
23
+ @logger.info('fail')
24
+ end
25
+
26
+ raise
27
+ end
28
+
29
+ private
30
+
31
+ def elapsed(start)
32
+ (Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start).round(3)
33
+ end
34
+ end
35
+
36
+ rescue LoadError
37
+ # sidekiq is not present
38
+ end
@@ -1,7 +1,7 @@
1
1
  module Logtail
2
2
  module Integrations
3
3
  module Rails
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.4"
5
5
  end
6
6
  end
7
7
  end
data/lib/logtail-rails.rb CHANGED
@@ -21,6 +21,7 @@ require "logtail-rails/action_controller"
21
21
  require "logtail-rails/action_dispatch"
22
22
  require "logtail-rails/action_view"
23
23
  require "logtail-rails/active_record"
24
+ require "logtail-rails/sidekiq"
24
25
 
25
26
  require "logtail-rails/log_entry"
26
27
  require "logtail-rails/logger"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logtail-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Better Stack
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-12 00:00:00.000000000 Z
11
+ date: 2023-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logtail
@@ -306,6 +306,7 @@ files:
306
306
  - gemfiles/rails-6.0.gemfile
307
307
  - gemfiles/rails-6.1.gemfile
308
308
  - gemfiles/rails-7.0.gemfile
309
+ - gemfiles/rails-edge.gemfile
309
310
  - lib/logtail-rails.rb
310
311
  - lib/logtail-rails/action_controller.rb
311
312
  - lib/logtail-rails/action_controller/log_subscriber.rb
@@ -334,6 +335,7 @@ files:
334
335
  - lib/logtail-rails/rack_logger.rb
335
336
  - lib/logtail-rails/railtie.rb
336
337
  - lib/logtail-rails/session_context.rb
338
+ - lib/logtail-rails/sidekiq.rb
337
339
  - lib/logtail-rails/version.rb
338
340
  - logtail-rails.gemspec
339
341
  homepage: https://github.com/logtail/logtail-ruby-rails