sentry-rails 4.6.5 → 4.7.3

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: d5717087ed6c8fd8d83680fc7950992b553bb3bdfdc9bf60622b334d3c757b7c
4
- data.tar.gz: 687f5baaa514011efcadc412e246fcb12b13a9f467c5f518dc45498b6e1e2d7d
3
+ metadata.gz: cec5336b01a20ec1922a32d103bd4dcf1587e8bf53288bd58520ba76aaa181a3
4
+ data.tar.gz: e38495a0f02aa5d1293167cb8894671948d0eaf1d4c1eac987e7bb74a28f3b0d
5
5
  SHA512:
6
- metadata.gz: c7b506fd42ec78b1e0a9dee799de829afc2fae6280753fe5e69d193905b6b12d43bdbfe7a5f2a69c185225e1a082093aaf5b80cd765674b6184e8cca164507c1
7
- data.tar.gz: 6d77e33885b0779a6e9c0bfd5ca0a2973adb5e64146ff1fa8b1a3a4b123febeff98d000583bb8f49567dbf9ddd816a5cea31d157f9613ac20040b2dd73215b3d
6
+ metadata.gz: a2a44a181625827c72a1393c96c3f783a9b0eb8317d626baa44ebd1a91f099e0fc135fba8270f45dab649b3bf8e87a65b0f79aa865fb400e52c0e1ecba961f62
7
+ data.tar.gz: f6e5fd836f4b7e9cdaabd776b0f2b2918fcc422f0e170b75dce77b32f36f230e1046d02cd437aa59fb1017239a829032cb78daf0f1af20668786897555467ecc
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 st0012
3
+ Copyright (c) 2020 Sentry
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -22,11 +22,6 @@ if defined?(ActiveJob)
22
22
  end
23
23
 
24
24
  def perform(event, hint = {})
25
- # users don't need the tracing result of this job
26
- if transaction = Sentry.get_current_scope.span
27
- transaction.instance_variable_set(:@sampled, false)
28
- end
29
-
30
25
  Sentry.send_event(event, hint)
31
26
  end
32
27
  end
@@ -21,7 +21,12 @@ module Sentry
21
21
 
22
22
  def capture_and_reraise_with_sentry(job, scope, block)
23
23
  scope.set_transaction_name(job.class.name)
24
- transaction = Sentry.start_transaction(name: scope.transaction_name, op: "active_job")
24
+ transaction =
25
+ if job.is_a?(::Sentry::SendEventJob)
26
+ nil
27
+ else
28
+ Sentry.start_transaction(name: scope.transaction_name, op: "active_job")
29
+ end
25
30
 
26
31
  scope.set_span(transaction) if transaction
27
32
 
@@ -0,0 +1,44 @@
1
+ require "sentry/rails/instrument_payload_cleanup_helper"
2
+
3
+ module Sentry
4
+ module Rails
5
+ module Breadcrumb
6
+ module MonotonicActiveSupportLogger
7
+ class << self
8
+ include InstrumentPayloadCleanupHelper
9
+
10
+ def add(name, started, _finished, _unique_id, data)
11
+ # skip Rails' internal events
12
+ return if name.start_with?("!")
13
+
14
+ if data.is_a?(Hash)
15
+ # we should only mutate the copy of the data
16
+ data = data.dup
17
+ cleanup_data(data)
18
+ end
19
+
20
+ crumb = Sentry::Breadcrumb.new(
21
+ data: data,
22
+ category: name,
23
+ timestamp: started.to_i
24
+ )
25
+ Sentry.add_breadcrumb(crumb)
26
+ end
27
+
28
+ def inject
29
+ @subscriber = ::ActiveSupport::Notifications.monotonic_subscribe(/.*/) do |name, started, finished, unique_id, data|
30
+ # we only record events that has a float as started timestamp
31
+ if started.is_a?(Float)
32
+ add(name, started, finished, unique_id, data)
33
+ end
34
+ end
35
+ end
36
+
37
+ def detach
38
+ ::ActiveSupport::Notifications.unsubscribe(@subscriber)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,7 +1,7 @@
1
1
  module Sentry
2
2
  module Rails
3
3
  module InstrumentPayloadCleanupHelper
4
- IGNORED_DATA_TYPES = [:request, :response, :headers, :exception, :exception_object]
4
+ IGNORED_DATA_TYPES = [:request, :response, :headers, :exception, :exception_object, Tracing::START_TIMESTAMP_NAME]
5
5
 
6
6
  def cleanup_data(data)
7
7
  IGNORED_DATA_TYPES.each do |key|
@@ -8,8 +8,8 @@ module Sentry
8
8
  initializer "sentry.use_rack_middleware" do |app|
9
9
  # placed after all the file-sending middlewares so we can avoid unnecessary transactions
10
10
  app.config.middleware.insert_after ActionDispatch::Executor, Sentry::Rails::CaptureExceptions
11
- # need to be placed at last to smuggle app exceptions via env
12
- app.config.middleware.use(Sentry::Rails::RescuedExceptionInterceptor)
11
+ # need to place as close to DebugExceptions as possible to intercept most of the exceptions, including those raised by middlewares
12
+ app.config.middleware.insert_after ActionDispatch::DebugExceptions, Sentry::Rails::RescuedExceptionInterceptor
13
13
  end
14
14
 
15
15
  # because the extension works by registering the around_perform callcack, it should always be ran
@@ -69,6 +69,13 @@ module Sentry
69
69
  require 'sentry/rails/breadcrumb/active_support_logger'
70
70
  Sentry::Rails::Breadcrumb::ActiveSupportLogger.inject
71
71
  end
72
+
73
+ if Sentry.configuration.breadcrumbs_logger.include?(:monotonic_active_support_logger)
74
+ return warn "Usage of `monotonic_active_support_logger` require a version of Rails >= 6.1, please upgrade your Rails version or use another logger" if ::Rails.version.to_f < 6.1
75
+
76
+ require 'sentry/rails/breadcrumb/monotonic_active_support_logger'
77
+ Sentry::Rails::Breadcrumb::MonotonicActiveSupportLogger.inject
78
+ end
72
79
  end
73
80
 
74
81
  def setup_backtrace_cleanup_callback
@@ -16,7 +16,7 @@ module Sentry
16
16
 
17
17
  record_on_current_span(
18
18
  op: event_name,
19
- start_timestamp: payload[:start_timestamp],
19
+ start_timestamp: payload[START_TIMESTAMP_NAME],
20
20
  description: "#{controller}##{action}",
21
21
  duration: duration
22
22
  ) do |span|
@@ -8,7 +8,7 @@ module Sentry
8
8
 
9
9
  def self.subscribe!
10
10
  subscribe_to_event(EVENT_NAME) do |event_name, duration, payload|
11
- record_on_current_span(op: event_name, start_timestamp: payload[:start_timestamp], description: payload[:identifier], duration: duration)
11
+ record_on_current_span(op: event_name, start_timestamp: payload[START_TIMESTAMP_NAME], description: payload[:identifier], duration: duration)
12
12
  end
13
13
  end
14
14
  end
@@ -11,7 +11,7 @@ module Sentry
11
11
  subscribe_to_event(EVENT_NAME) do |event_name, duration, payload|
12
12
  next if EXCLUDED_EVENTS.include? payload[:name]
13
13
 
14
- record_on_current_span(op: event_name, start_timestamp: payload[:start_timestamp], description: payload[:sql], duration: duration) do |span|
14
+ record_on_current_span(op: event_name, start_timestamp: payload[START_TIMESTAMP_NAME], description: payload[:sql], duration: duration) do |span|
15
15
  span.set_data(:connection_id, payload[:connection_id])
16
16
  end
17
17
  end
@@ -1,6 +1,8 @@
1
1
  module Sentry
2
2
  module Rails
3
3
  module Tracing
4
+ START_TIMESTAMP_NAME = :sentry_start_timestamp
5
+
4
6
  def self.register_subscribers(subscribers)
5
7
  @subscribers = subscribers
6
8
  end
@@ -9,11 +11,18 @@ module Sentry
9
11
  @subscribers
10
12
  end
11
13
 
14
+ def self.subscribed_tracing_events
15
+ @subscribed_tracing_events ||= []
16
+ end
17
+
12
18
  def self.subscribe_tracing_events
13
19
  # need to avoid duplicated subscription
14
20
  return if @subscribed
15
21
 
16
- subscribers.each(&:subscribe!)
22
+ subscribers.each do |subscriber|
23
+ subscriber.subscribe!
24
+ subscribed_tracing_events << subscriber::EVENT_NAME
25
+ end
17
26
 
18
27
  @subscribed = true
19
28
  end
@@ -22,6 +31,7 @@ module Sentry
22
31
  return unless @subscribed
23
32
 
24
33
  subscribers.each(&:unsubscribe!)
34
+ subscribed_tracing_events.clear
25
35
 
26
36
  @subscribed = false
27
37
  end
@@ -35,9 +45,10 @@ module Sentry
35
45
 
36
46
  SentryNotificationExtension.module_eval do
37
47
  def instrument(name, payload = {}, &block)
38
- is_public_event = name[0] != "!"
39
-
40
- payload[:start_timestamp] = Time.now.utc.to_f if is_public_event
48
+ # only inject timestamp to the events the SDK subscribes to
49
+ if Tracing.subscribed_tracing_events.include?(name)
50
+ payload[START_TIMESTAMP_NAME] = Time.now.utc.to_f if name[0] != "!" && payload.is_a?(Hash)
51
+ end
41
52
 
42
53
  super(name, payload, &block)
43
54
  end
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Rails
3
- VERSION = "4.6.5"
3
+ VERSION = "4.7.3"
4
4
  end
5
5
  end
data/lib/sentry/rails.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require "rails"
2
2
  require "sentry-ruby"
3
3
  require "sentry/integrable"
4
+ require "sentry/rails/tracing"
4
5
  require "sentry/rails/configuration"
5
6
  require "sentry/rails/engine"
6
7
  require "sentry/rails/railtie"
7
- require "sentry/rails/tracing"
8
8
 
9
9
  module Sentry
10
10
  module Rails
data/sentry-rails.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ["Sentry Team"]
7
7
  spec.description = spec.summary = "A gem that provides Rails integration for the Sentry error logger"
8
8
  spec.email = "accounts@sentry.io"
9
- spec.license = 'Apache-2.0'
9
+ spec.license = 'MIT'
10
10
  spec.homepage = "https://github.com/getsentry/sentry-ruby"
11
11
 
12
12
  spec.platform = Gem::Platform::RUBY
@@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ["lib"]
24
24
 
25
25
  spec.add_dependency "railties", ">= 5.0"
26
- spec.add_dependency "sentry-ruby-core", "~> 4.6.0"
26
+ spec.add_dependency "sentry-ruby-core", "~> 4.7.0"
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.6.5
4
+ version: 4.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-12 00:00:00.000000000 Z
11
+ date: 2021-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 4.6.0
33
+ version: 4.7.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 4.6.0
40
+ version: 4.7.0
41
41
  description: A gem that provides Rails integration for the Sentry error logger
42
42
  email: accounts@sentry.io
43
43
  executables: []
@@ -64,6 +64,7 @@ files:
64
64
  - lib/sentry/rails/background_worker.rb
65
65
  - lib/sentry/rails/backtrace_cleaner.rb
66
66
  - lib/sentry/rails/breadcrumb/active_support_logger.rb
67
+ - lib/sentry/rails/breadcrumb/monotonic_active_support_logger.rb
67
68
  - lib/sentry/rails/capture_exceptions.rb
68
69
  - lib/sentry/rails/configuration.rb
69
70
  - lib/sentry/rails/controller_methods.rb
@@ -82,7 +83,7 @@ files:
82
83
  - sentry-rails.gemspec
83
84
  homepage: https://github.com/getsentry/sentry-ruby
84
85
  licenses:
85
- - Apache-2.0
86
+ - MIT
86
87
  metadata:
87
88
  homepage_uri: https://github.com/getsentry/sentry-ruby
88
89
  source_code_uri: https://github.com/getsentry/sentry-ruby