Skip to content

Commit 5df711a

Browse files
author
Emanuele Palazzetti
authored
Merge pull request #308 from pedro/add-error-handling-for-middleware-patching
Add error handling during middleware patch
2 parents 0aabde6 + d63687c commit 5df711a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/ddtrace/contrib/rack/patcher.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,24 @@ def patch
2222
require_relative 'middlewares'
2323
@patched = true
2424

25-
return unless get_option(:middleware_names)
26-
27-
top = get_option(:application) || rails_app
28-
retain_middleware_name(top)
25+
enable_middleware_names if get_option(:middleware_names)
2926
end
3027

3128
def patched?
3229
@patched ||= false
3330
end
3431

32+
def enable_middleware_names
33+
root = get_option(:application) || rails_app
34+
retain_middleware_name(root)
35+
rescue => e
36+
# We can safely ignore these exceptions since they happen only in the
37+
# context of middleware patching outside a Rails server process (eg. a
38+
# process that doesn't serve HTTP requests but has Rails environment
39+
# loaded such as a Resque master process)
40+
Tracer.log.debug("Error patching middleware stack: #{e}")
41+
end
42+
3543
def rails_app
3644
return unless Datadog.registry[:rails].compatible?
3745
::Rails.application.app

0 commit comments

Comments
 (0)