ddtrace 0.11.2 → 0.11.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,8 +22,13 @@ module Datadog
22
22
  # SignalException::Interrupt would still bubble up.
23
23
  rescue Exception => e
24
24
  tracer = Datadog.configuration[:rails][:tracer]
25
- span = tracer.active_span()
26
- span.set_error(e) unless span.nil?
25
+ span = tracer.active_span
26
+ unless span.nil?
27
+ # Only set error if it's supposed to be flagged as such
28
+ # e.g. we don't want to flag 404s.
29
+ # You can add custom errors via `config.action_dispatch.rescue_responses`
30
+ span.set_error(e) if Utils.exception_is_error?(e)
31
+ end
27
32
  raise e
28
33
  end
29
34
  end
@@ -6,7 +6,10 @@ module Datadog
6
6
  # Railtie class initializes
7
7
  class Railtie < Rails::Railtie
8
8
  config.app_middleware.insert_before(0, Datadog::Contrib::Rack::TraceMiddleware)
9
- config.app_middleware.use(Datadog::Contrib::Rails::ExceptionMiddleware)
9
+ # Insert right after Rails exception handling middleware, because if it's before,
10
+ # it catches and swallows the error. If it's too far after, custom middleware can find itself
11
+ # between, and raise exceptions that don't end up getting tagged on the request properly (e.g lost stack trace.)
12
+ config.app_middleware.insert_after(ActionDispatch::ShowExceptions, Datadog::Contrib::Rails::ExceptionMiddleware)
10
13
 
11
14
  config.after_initialize do
12
15
  Datadog::Contrib::Rails::Framework.setup
@@ -72,6 +72,18 @@ module Datadog
72
72
  end
73
73
  end
74
74
 
75
+ def self.exception_is_error?(exception)
76
+ if defined?(::ActionDispatch::ExceptionWrapper)
77
+ # Gets the equivalent status code for the exception (not all are 5XX)
78
+ # You can add custom errors via `config.action_dispatch.rescue_responses`
79
+ status = ::ActionDispatch::ExceptionWrapper.status_code_for_exception(exception.class.name)
80
+ # Only 5XX exceptions are actually errors (e.g. don't flag 404s)
81
+ status.to_s.starts_with?('5')
82
+ else
83
+ true
84
+ end
85
+ end
86
+
75
87
  private_class_method :connection_config
76
88
  end
77
89
  end
@@ -6,6 +6,7 @@ module Datadog
6
6
  URL = 'http.url'.freeze
7
7
  BASE_URL = 'http.base_url'.freeze
8
8
  METHOD = 'http.method'.freeze
9
+ REQUEST_ID = 'http.request_id'.freeze
9
10
  STATUS_CODE = 'http.status_code'.freeze
10
11
  ERROR_RANGE = 500...600
11
12
  end
@@ -1,18 +1,40 @@
1
1
  module Datadog
2
2
  # Defines some useful patching methods for integrations
3
3
  module Patcher
4
- module_function
4
+ def self.included(base)
5
+ base.send(:extend, CommonMethods)
6
+ base.send(:include, CommonMethods)
7
+ end
5
8
 
6
- def without_warnings
7
- # This is typically used when monkey patching functions such as
8
- # intialize, which Ruby advices you not to. Use cautiously.
9
- v = $VERBOSE
10
- $VERBOSE = nil
11
- begin
12
- yield
13
- ensure
14
- $VERBOSE = v
9
+ # Defines some common methods for patching, that can be used
10
+ # at the instance, class, or module level.
11
+ module CommonMethods
12
+ def without_warnings
13
+ # This is typically used when monkey patching functions such as
14
+ # intialize, which Ruby advices you not to. Use cautiously.
15
+ v = $VERBOSE
16
+ $VERBOSE = nil
17
+ begin
18
+ yield
19
+ ensure
20
+ $VERBOSE = v
21
+ end
22
+ end
23
+
24
+ def do_once(key = nil)
25
+ # If already done, don't do again
26
+ @done_once ||= {}
27
+ return @done_once[key] if @done_once.key?(key)
28
+
29
+ # Otherwise 'do'
30
+ yield.tap do
31
+ # Then add the key so we don't do again.
32
+ @done_once[key] = true
33
+ end
15
34
  end
16
35
  end
36
+
37
+ # Extend the common methods so they're available as a module function.
38
+ extend(CommonMethods)
17
39
  end
18
40
  end
@@ -2,7 +2,7 @@ module Datadog
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 11
5
- PATCH = 2
5
+ PATCH = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddtrace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.11.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datadog, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-02 00:00:00.000000000 Z
11
+ date: 2018-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -222,6 +222,7 @@ files:
222
222
  - ".rubocop.yml"
223
223
  - ".yardopts"
224
224
  - Appraisals
225
+ - CHANGELOG.md
225
226
  - Gemfile
226
227
  - LICENSE
227
228
  - README.md