17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/cosmo/sentry/job_processor_middleware.rb', line 17
def perform_job(job_instance, data:, message:, duration: nil)
unless ::Sentry.initialized?
super
return
end
scope = ::Sentry.get_current_scope
transaction_name = "#{NAME_PREFIX}/#{job_instance.class.name}"
scope.set_transaction_name(transaction_name, source: :task)
transaction = ::Sentry.start_transaction(
name: scope.transaction_name,
source: scope.transaction_source,
op: OP_NAME,
origin: SPAN_ORIGIN
)
transaction&.set_data("messaging.message.id", data[:jid])
transaction&.set_data("messaging.destination.name", "#{message.metadata.stream}:#{message.subject}")
transaction&.set_data("messaging.message.retry.count", data[:retry] || 0)
begin
super
transaction&.set_http_status(STATUS_OK)
transaction&.finish
rescue StandardError => e
::Sentry.capture_exception(
e,
contexts: {
cosmonats: data.merge(
nats_stream: message.metadata.stream,
nats_subject: message.subject,
timeout_duration: duration
)
},
hint: {
background: true,
integration: "cosmonats"
}
)
transaction&.set_http_status(STATUS_FAIL)
transaction&.finish
raise e
end
end
|