sentry-delayed_job 5.16.1 → 5.17.0

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: bd65248bd96ef0128bdea13f9bbbffaf40f254baf08994bb068ccfe26ab91e0f
4
- data.tar.gz: 3644f99752eb096f9e78b98cc63ee7a205cb9cd13b3e1fa98fbd55f366c37a6b
3
+ metadata.gz: 1982ed4c43b807a18a08dc82a6ff89c4145d043fb3f05c2450383fcf5b02e0fd
4
+ data.tar.gz: 43c8fcd55480b2d17cc8a872b43a93e3a43683527fa768437f395f64af9fa86d
5
5
  SHA512:
6
- metadata.gz: 560f853d6952c43de01a2e818202b389d16357ecedcbfea1c708607678469249b3271ef8a78d1f3de29a53f2a659575de1aa1bd97d8dc1e09bd966081a120858
7
- data.tar.gz: faaf2a4da2e76e82cd5aa97dad2ea9a3dc003d7d55a62ac61d32965bb7dd32e07909809e6a79a1121de185564a464e034bfc2c451fb5337f21a12c5f2dbc6169
6
+ metadata.gz: 572a579f738ec7d483be96b197c28cbb69a143c39c8fd90dec9a6d9c8bd17d7661139edf72bda94f273888401835deae62723b1aff137fa8e438a8f0893a80c3
7
+ data.tar.gz: f32de1898887c2a72654c085541d72a0b9d345fd72a2a721fd9fc6cef62e92bb6e2f7f7457700618fd52336a663bc7ecaf9288d8a182c9e06f36bb92426e86b8
data/Rakefile CHANGED
@@ -5,4 +5,4 @@ RSpec::Core::RakeTask.new(:spec).tap do |task|
5
5
  task.rspec_opts = "--order rand"
6
6
  end
7
7
 
8
- task :default => :spec
8
+ task default: :spec
data/example/Gemfile CHANGED
@@ -7,5 +7,4 @@ gem 'delayed_job_active_record'
7
7
  gem "sentry-delayed_job", path: "../"
8
8
  gem "sentry-ruby", path: "../../sentry-ruby"
9
9
 
10
- gem "pry"
11
10
  gem "debug", github: "ruby/debug"
data/example/app.rb CHANGED
@@ -1,4 +1,3 @@
1
- require "pry"
2
1
  require "active_job"
3
2
  require "active_record"
4
3
  require "delayed_job"
@@ -64,5 +63,3 @@ begin
64
63
  rescue => e
65
64
  puts("inline job failed because of \"#{e.message}\"")
66
65
  end
67
-
68
-
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "delayed_job"
3
4
 
4
5
  module Sentry
@@ -10,7 +11,12 @@ module Sentry
10
11
  OP_NAME = "queue.delayed_job".freeze
11
12
 
12
13
  callbacks do |lifecycle|
14
+ lifecycle.before(:enqueue) do |job, *args, &block|
15
+ inject_trace_data(job) if Sentry.initialized?
16
+ end
17
+
13
18
  lifecycle.around(:invoke_job) do |job, *args, &block|
19
+ env = extract_trace_data(job)
14
20
  next block.call(job, *args) unless Sentry.initialized?
15
21
 
16
22
  Sentry.with_scope do |scope|
@@ -20,12 +26,7 @@ module Sentry
20
26
  scope.set_contexts(**contexts)
21
27
  scope.set_tags("delayed_job.queue" => job.queue, "delayed_job.id" => job.id.to_s)
22
28
 
23
- transaction = Sentry.start_transaction(
24
- name: scope.transaction_name,
25
- source: scope.transaction_source,
26
- op: OP_NAME,
27
- custom_sampling_context: contexts
28
- )
29
+ transaction = start_transaction(scope, env, contexts)
29
30
  scope.set_span(transaction) if transaction
30
31
 
31
32
  begin
@@ -55,7 +56,7 @@ module Sentry
55
56
  created_at: job.created_at,
56
57
  last_error: job.last_error&.byteslice(0..1000),
57
58
  handler: job.handler&.byteslice(0..1000),
58
- job_class: compute_job_class(job.payload_object),
59
+ job_class: compute_job_class(job.payload_object)
59
60
  }
60
61
 
61
62
  if job.payload_object.respond_to?(:job_data)
@@ -70,7 +71,7 @@ module Sentry
70
71
  end
71
72
 
72
73
  def self.compute_job_class(payload_object)
73
- if payload_object.is_a? Delayed::PerformableMethod
74
+ if payload_object.is_a?(Delayed::PerformableMethod)
74
75
  klass = payload_object.object.is_a?(Class) ? payload_object.object.name : payload_object.object.class.name
75
76
  "#{klass}##{payload_object.method_name}"
76
77
  else
@@ -91,12 +92,40 @@ module Sentry
91
92
  job.attempts >= max_attempts
92
93
  end
93
94
 
95
+ def self.start_transaction(scope, env, contexts)
96
+ options = { name: scope.transaction_name, source: scope.transaction_source, op: OP_NAME }
97
+ transaction = Sentry.continue_trace(env, **options)
98
+ Sentry.start_transaction(transaction: transaction, custom_sampling_context: contexts, **options)
99
+ end
100
+
94
101
  def self.finish_transaction(transaction, status)
95
102
  return unless transaction
96
103
 
97
104
  transaction.set_http_status(status)
98
105
  transaction.finish
99
106
  end
107
+
108
+ def self.inject_trace_data(job)
109
+ # active job style is handled in the sentry-rails/active_job extension more generally
110
+ # if someone enqueues manually with some other job class, we cannot make assumptions unfortunately
111
+ payload_object = job.payload_object
112
+ return unless payload_object.is_a?(Delayed::PerformableMethod)
113
+
114
+ # we will add the trace data to args and remove it again
115
+ # this is hacky but it's the only reliable way to survive the YAML serialization/deserialization
116
+ payload_object.args << { sentry: Sentry.get_trace_propagation_headers }
117
+ job.payload_object = payload_object
118
+ end
119
+
120
+ def self.extract_trace_data(job)
121
+ payload_object = job.payload_object
122
+ return nil unless payload_object.is_a?(Delayed::PerformableMethod)
123
+
124
+ target_payload = payload_object.args.find { |a| a.is_a?(Hash) && a.key?(:sentry) }
125
+ return nil unless target_payload
126
+ payload_object.args.delete(target_payload)
127
+ target_payload[:sentry]
128
+ end
100
129
  end
101
130
  end
102
131
  end
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module DelayedJob
3
- VERSION = "5.16.1"
3
+ VERSION = "5.17.0"
4
4
  end
5
5
  end
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_dependency "sentry-ruby", "~> 5.16.1"
25
+ spec.add_dependency "sentry-ruby", "~> 5.17.0"
26
26
  spec.add_dependency "delayed_job", ">= 4.0"
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-delayed_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.16.1
4
+ version: 5.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-09 00:00:00.000000000 Z
11
+ date: 2024-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sentry-ruby
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 5.16.1
19
+ version: 5.17.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 5.16.1
26
+ version: 5.17.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: delayed_job
29
29
  requirement: !ruby/object:Gem::Requirement