From 0f582ed896b37189bd6b709893c18c0a7f523adb Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Tue, 26 Jun 2018 13:43:40 +0200 Subject: [PATCH 1/2] Shutdown and flush on job finish instead of using SyncWriter. --- lib/ddtrace/contrib/resque/resque_job.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/ddtrace/contrib/resque/resque_job.rb b/lib/ddtrace/contrib/resque/resque_job.rb index e376535deca..340d3b7a29e 100644 --- a/lib/ddtrace/contrib/resque/resque_job.rb +++ b/lib/ddtrace/contrib/resque/resque_job.rb @@ -16,26 +16,18 @@ def around_perform(*args) yield span.service = pin.service end + ensure + Datadog.tracer.shutdown! end end end end end -Resque.before_first_fork do - pin = Datadog::Pin.get_from(Resque) - next unless pin && pin.tracer - - # Create SyncWriter instance before forking - sync_writer = Datadog::SyncWriter.new(transport: pin.tracer.writer.transport) - Datadog::Contrib::Resque.sync_writer = sync_writer -end - Resque.after_fork do # get the current tracer pin = Datadog::Pin.get_from(Resque) next unless pin && pin.tracer # clean the state so no CoW happens pin.tracer.provider.context = nil - pin.tracer.writer = Datadog::Contrib::Resque.sync_writer end From 1b5c5a8b15995335410af59754d05e58659a160f Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Tue, 26 Jun 2018 18:14:38 +0200 Subject: [PATCH 2/2] Use local tracer object instead of global one --- lib/ddtrace/contrib/resque/resque_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ddtrace/contrib/resque/resque_job.rb b/lib/ddtrace/contrib/resque/resque_job.rb index 340d3b7a29e..d3eac5bd4bb 100644 --- a/lib/ddtrace/contrib/resque/resque_job.rb +++ b/lib/ddtrace/contrib/resque/resque_job.rb @@ -17,7 +17,7 @@ def around_perform(*args) span.service = pin.service end ensure - Datadog.tracer.shutdown! + pin.tracer.shutdown! if pin && pin.tracer end end end