ddtrace 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32267c0f9a646b5c68fec68446808b0338aee9fe
4
- data.tar.gz: fe7fb33d51a89cc592aa83c6b52c0b5347d35d68
3
+ metadata.gz: 7416eda04ff6e9686b7409bc04a2208bf6b30a7f
4
+ data.tar.gz: 7293c060f6b3bf6d2c53eaadffcedac89faa20f0
5
5
  SHA512:
6
- metadata.gz: 477f468fb2959ad9d5e48485ec3688d8c2368ce11784903ae76c820748b1772df99f50b25818647320ae4cad7dc7811847616c551092daa18a0fdc9fae883320
7
- data.tar.gz: 777c16f17819d7d32f2c4d8544761690344ddac5473bd5ac0b2af45d6428d80c4db7bbbd7129a85780d1bb6fbb6cc60d9abe402dc60d8030fdaf2796643bc18f
6
+ metadata.gz: b6e80a1f921566158b2a6bb8efdfa79725c7a50876069ae74c1f1677eb4e424cdbf8c16d72eadad832ca9e25fd434f2dc17cfd23f5f19145bd09e1bbdbb97547
7
+ data.tar.gz: ed535d01f21d1aa1095feed91259809a74c35651ccda8821fd9b7dba8548f445ea1e93fa1e0c98aaf7b9ce0fee903cd36c4837e319d1220cdd40e4dbdeb7cc50
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ require 'rake/testtask'
5
5
  require 'appraisal'
6
6
  require 'yard'
7
7
 
8
+ # rubocop:disable Metrics/BlockLength
8
9
  namespace :test do
9
10
  task all: [:main,
10
11
  :rails, :railsredis, :railssidekiq, :railsactivejob,
@@ -25,7 +26,8 @@ namespace :test do
25
26
  t.test_files = FileList['test/contrib/rails/**/*_test.rb'].reject do |path|
26
27
  path.include?('redis') ||
27
28
  path.include?('sidekiq') ||
28
- path.include?('active_job')
29
+ path.include?('active_job') ||
30
+ path.include?('disable_env')
29
31
  end
30
32
  end
31
33
 
@@ -44,6 +46,11 @@ namespace :test do
44
46
  t.test_files = FileList['test/contrib/rails/**/*active_job*_test.rb']
45
47
  end
46
48
 
49
+ Rake::TestTask.new(:railsdisableenv) do |t|
50
+ t.libs << %w[test lib]
51
+ t.test_files = FileList['test/contrib/rails/**/*disable_env*_test.rb']
52
+ end
53
+
47
54
  [:elasticsearch, :http, :redis, :sinatra, :sidekiq, :rack, :grape].each do |contrib|
48
55
  Rake::TestTask.new(contrib) do |t|
49
56
  t.libs << %w[test lib]
@@ -142,12 +149,15 @@ task :ci do
142
149
  sh 'rvm $SIDEKIQ_OLD_VERSIONS --verbose do appraisal contrib-old rake test:sidekiq'
143
150
  when 2
144
151
  sh 'rvm $RAILS3_VERSIONS --verbose do appraisal rails30-postgres rake test:rails'
152
+ sh 'rvm $RAILS3_VERSIONS --verbose do appraisal rails30-postgres rake test:railsdisableenv'
145
153
  sh 'rvm $RAILS3_VERSIONS --verbose do appraisal rails32-mysql2 rake test:rails'
146
154
  sh 'rvm $RAILS3_VERSIONS --verbose do appraisal rails32-postgres rake test:rails'
147
155
  sh 'rvm $RAILS3_VERSIONS --verbose do appraisal rails32-postgres-redis rake test:railsredis'
156
+ sh 'rvm $RAILS3_VERSIONS --verbose do appraisal rails32-postgres rake test:railsdisableenv'
148
157
  sh 'rvm $RAILS4_VERSIONS --verbose do appraisal rails4-mysql2 rake test:rails'
149
158
  sh 'rvm $RAILS4_VERSIONS --verbose do appraisal rails4-postgres rake test:rails'
150
159
  sh 'rvm $RAILS4_VERSIONS --verbose do appraisal rails4-postgres-redis rake test:railsredis'
160
+ sh 'rvm $RAILS4_VERSIONS --verbose do appraisal rails4-postgres rake test:railsdisableenv'
151
161
  sh 'rvm $RAILS3_SIDEKIQ_VERSIONS --verbose do appraisal rails30-postgres-sidekiq rake test:railssidekiq'
152
162
  sh 'rvm $RAILS3_SIDEKIQ_VERSIONS --verbose do appraisal rails32-postgres-sidekiq rake test:railssidekiq'
153
163
  sh 'rvm $RAILS4_SIDEKIQ_VERSIONS --verbose do appraisal rails4-postgres-sidekiq rake test:railssidekiq'
@@ -157,6 +167,7 @@ task :ci do
157
167
  sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-postgres-redis rake test:railsredis'
158
168
  sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-postgres-sidekiq rake test:railssidekiq'
159
169
  sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-postgres-sidekiq rake test:railsactivejob'
170
+ sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-postgres rake test:railsdisableenv'
160
171
  else
161
172
  puts 'Too many workers than parallel tasks'
162
173
  end
@@ -106,6 +106,21 @@ Available settings are:
106
106
  * ``env``: set the environment. Rails users may set it to ``Rails.env`` to use their application settings.
107
107
  * ``tags``: set global tags that should be applied to all spans. Defaults to an empty hash
108
108
 
109
+ #### Disabling Rails auto-instrumentation
110
+
111
+ If you wish to disable all Rails auto-instrumentation, you need to set the env var ``DISABLE_DATADOG_RAILS``.
112
+
113
+ Eg, within Ruby:
114
+
115
+ ENV['DISABLE_DATADOG_RAILS'] = 1 # this must be done before ddtrace is included at all
116
+ require 'ddtrace'
117
+
118
+ Or, shell syntax, before launching Rails:
119
+
120
+ ```
121
+ export DISABLE_DATADOG_RAILS=1
122
+ ```
123
+
109
124
  ### Sinatra
110
125
 
111
126
  The Sinatra integration traces requests and template rendering. The integration is based on the
@@ -177,6 +192,12 @@ See [distributed tracing](#Distributed_Tracing) for details.
177
192
  To modify the default middleware configuration, you can use middleware options as follows:
178
193
 
179
194
  # config.ru example
195
+ Datadog.tracer.configure(
196
+ enabled: true,
197
+ hostname: localhost,
198
+ port: 8126
199
+ )
200
+
180
201
  use Datadog::Contrib::Rack::TraceMiddleware, default_service: 'rack-stack'
181
202
 
182
203
  app = proc do |env|
@@ -27,40 +27,46 @@ end
27
27
 
28
28
  # Datadog auto instrumentation for frameworks
29
29
  if defined?(Rails::VERSION)
30
- if Rails::VERSION::MAJOR.to_i >= 3
31
- require 'ddtrace/contrib/rails/framework'
30
+ if !ENV['DISABLE_DATADOG_RAILS']
31
+ if Rails::VERSION::MAJOR.to_i >= 3
32
+ require 'ddtrace/contrib/rails/framework'
33
+ require 'ddtrace/contrib/rails/middlewares'
32
34
 
33
- module Datadog
34
- # Railtie class initializes
35
- class Railtie < Rails::Railtie
36
- # auto instrument Rails and third party components after
37
- # the framework initialization
38
- options = {}
39
- config.after_initialize do |app|
40
- Datadog::Contrib::Rails::Framework.configure(config: app.config)
41
- Datadog::Contrib::Rails::Framework.auto_instrument()
42
- Datadog::Contrib::Rails::Framework.auto_instrument_redis()
43
- Datadog::Contrib::Rails::Framework.auto_instrument_grape()
35
+ module Datadog
36
+ # Railtie class initializes
37
+ class Railtie < Rails::Railtie
38
+ config.app_middleware.use(Datadog::Contrib::Rails::ExceptionMiddleware)
44
39
 
45
- # override Rack Middleware configurations with Rails
46
- options.update(::Rails.configuration.datadog_trace)
47
- end
40
+ # auto instrument Rails and third party components after
41
+ # the framework initialization
42
+ options = {}
43
+ config.after_initialize do |app|
44
+ Datadog::Contrib::Rails::Framework.configure(config: app.config)
45
+ Datadog::Contrib::Rails::Framework.auto_instrument()
46
+ Datadog::Contrib::Rails::Framework.auto_instrument_redis()
47
+ Datadog::Contrib::Rails::Framework.auto_instrument_grape()
48
+
49
+ # override Rack Middleware configurations with Rails
50
+ options.update(::Rails.configuration.datadog_trace)
51
+ end
48
52
 
49
- # Configure datadog settings before building the middleware stack.
50
- # This is required because the middleware stack is frozen after
51
- # the initialization and so it's too late to add our tracing
52
- # functionalities.
53
- initializer :datadog_config, before: :build_middleware_stack do |app|
54
- app.config.middleware.insert_before(
55
- 0, Datadog::Contrib::Rack::TraceMiddleware, options
56
- )
53
+ # Configure datadog settings before building the middleware stack.
54
+ # This is required because the middleware stack is frozen after
55
+ # the initialization and so it's too late to add our tracing
56
+ # functionalities.
57
+ initializer :datadog_config, before: :build_middleware_stack do |app|
58
+ app.config.middleware.insert_before(
59
+ 0, Datadog::Contrib::Rack::TraceMiddleware, options
60
+ )
61
+ end
57
62
  end
58
63
  end
64
+ else
65
+ Datadog::Tracer.log.warn 'Detected a Rails version < 3.x.'\
66
+ 'This version is not supported yet and the'\
67
+ 'auto-instrumentation for core components will be disabled.'
59
68
  end
60
69
  else
61
- logger = Logger.new(STDOUT)
62
- logger.warn 'Detected a Rails version < 3.x.'\
63
- 'This version is not supported yet and the'\
64
- 'auto-instrumentation for core components will be disabled.'
70
+ Datadog::Tracer.log.info 'Skipping Rails auto-instrumentation, DISABLE_DATADOG_RAILS is set.'
65
71
  end
66
72
  end
@@ -87,6 +87,7 @@ module Datadog
87
87
 
88
88
  # call the rest of the stack
89
89
  status, headers, response = @app.call(env)
90
+
90
91
  # rubocop:disable Lint/RescueException
91
92
  # Here we really want to catch *any* exception, not only StandardError,
92
93
  # as we really have no clue of what is in the block,
@@ -96,7 +97,7 @@ module Datadog
96
97
  rescue Exception => e
97
98
  # catch exceptions that may be raised in the middleware chain
98
99
  # Note: if a middleware catches an Exception without re raising,
99
- # the Exception cannot be recorded here
100
+ # the Exception cannot be recorded here.
100
101
  request_span.set_error(e)
101
102
  raise e
102
103
  ensure
@@ -128,10 +129,6 @@ module Datadog
128
129
  # unless it has been already set by the underlying framework
129
130
  if status.to_s.start_with?('5') && request_span.status.zero?
130
131
  request_span.status = 1
131
- # in any case we don't touch the stacktrace if it has been set
132
- if request_span.get_tag(Datadog::Ext::Errors::STACK).nil?
133
- request_span.set_tag(Datadog::Ext::Errors::STACK, caller().join("\n"))
134
- end
135
132
  end
136
133
 
137
134
  request_span.finish()
@@ -4,7 +4,7 @@ require 'ddtrace/ext/errors'
4
4
  module Datadog
5
5
  module Contrib
6
6
  module Rails
7
- # TODO[manu]: write docs
7
+ # Code used to create and handle 'rails.action_controller' spans.
8
8
  module ActionController
9
9
  KEY = 'datadog_actioncontroller'.freeze
10
10
 
@@ -33,7 +33,6 @@ module Datadog
33
33
  Datadog::Tracer.log.error(e.message)
34
34
  end
35
35
 
36
- # rubocop:disable Metrics/MethodLength
37
36
  def self.process_action(_name, start, finish, _id, payload)
38
37
  return unless Thread.current[KEY]
39
38
  Thread.current[KEY] = false
@@ -58,10 +57,7 @@ module Datadog
58
57
  # [christian] in some cases :status is not defined,
59
58
  # rather than firing an error, simply acknowledge we don't know it.
60
59
  status = payload.fetch(:status, '?').to_s
61
- if status.starts_with?('5')
62
- span.status = 1
63
- span.set_tag(Datadog::Ext::Errors::STACK, caller().join("\n"))
64
- end
60
+ span.status = 1 if status.starts_with?('5')
65
61
  else
66
62
  error = payload[:exception]
67
63
  if defined?(::ActionDispatch::ExceptionWrapper)
@@ -74,7 +70,6 @@ module Datadog
74
70
  span.status = 1
75
71
  span.set_tag(Datadog::Ext::Errors::TYPE, error[0])
76
72
  span.set_tag(Datadog::Ext::Errors::MSG, error[1])
77
- span.set_tag(Datadog::Ext::Errors::STACK, caller().join("\n"))
78
73
  end
79
74
  end
80
75
  ensure
@@ -3,7 +3,7 @@ require 'ddtrace/contrib/rails/utils'
3
3
  module Datadog
4
4
  module Contrib
5
5
  module Rails
6
- # TODO[manu]: write docs
6
+ # Code used to create and handle 'rails.render_template' and 'rails.render_partial' spans.
7
7
  module ActionView
8
8
  def self.instrument
9
9
  # patch Rails core components
@@ -5,7 +5,7 @@ require 'ddtrace/contrib/rails/utils'
5
5
  module Datadog
6
6
  module Contrib
7
7
  module Rails
8
- # TODO[manu]: write docs
8
+ # Code used to create and handle 'mysql.query', 'postgres.query', ... spans.
9
9
  module ActiveRecord
10
10
  def self.instrument
11
11
  # ActiveRecord is instrumented only if it's available
@@ -4,7 +4,7 @@ require 'ddtrace/ext/cache'
4
4
  module Datadog
5
5
  module Contrib
6
6
  module Rails
7
- # TODO[manu]: write docs
7
+ # Code used to create and handle 'rails.cache' spans.
8
8
  module ActiveSupport
9
9
  def self.instrument
10
10
  # patch Rails core components
@@ -12,7 +12,7 @@ require 'ddtrace/contrib/rails/active_support'
12
12
  require 'ddtrace/contrib/rails/utils'
13
13
 
14
14
  # Rails < 3.1
15
- unless defined?(ActiveRecord::Base.connection_config)
15
+ if defined?(::ActiveRecord) && !defined?(::ActiveRecord::Base.connection_config)
16
16
  ActiveRecord::Base.class_eval do
17
17
  class << self
18
18
  def connection_config
@@ -24,9 +24,11 @@ end
24
24
 
25
25
  module Datadog
26
26
  module Contrib
27
- # TODO[manu]: write docs
27
+ # Instrument Rails.
28
28
  module Rails
29
- # TODO[manu]: write docs
29
+ # Rails framework code, used to essentially:
30
+ # - handle configuration entries which are specific to Datadog tracing
31
+ # - instrument parts of the framework when needed
30
32
  module Framework
31
33
  # default configurations for the Rails integration; by default
32
34
  # the Datadog.tracer is enabled, while the Rails auto instrumentation
@@ -0,0 +1,32 @@
1
+ require 'ddtrace/ext/http'
2
+
3
+ module Datadog
4
+ module Contrib
5
+ # Rails module includes middlewares that are required for Rails to be properly instrumented.
6
+ module Rails
7
+ # This is only here to catch errors, the Rack module does something very similar, however,
8
+ # since it's not in the same place in the stack, when the Rack middleware is called,
9
+ # error is already swallowed and handled by Rails so we miss the call stack, for instance.
10
+ class ExceptionMiddleware
11
+ def initialize(app)
12
+ @app = app
13
+ end
14
+
15
+ def call(env)
16
+ @app.call(env)
17
+ # rubocop:disable Lint/RescueException
18
+ # Here we really want to catch *any* exception, not only StandardError,
19
+ # as we really have no clue of what is in the block,
20
+ # and it is user code which should be executed no matter what.
21
+ # It's not a problem since we re-raise it afterwards so for example a
22
+ # SignalException::Interrupt would still bubble up.
23
+ rescue Exception => e
24
+ tracer = ::Rails.configuration.datadog_trace.fetch(:tracer)
25
+ span = tracer.active_span()
26
+ span.set_error(e) unless span.nil?
27
+ raise e
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -2,6 +2,7 @@ require 'thread'
2
2
  require 'net/http'
3
3
 
4
4
  require 'ddtrace/encoding'
5
+ require 'ddtrace/version'
5
6
 
6
7
  module Datadog
7
8
  # Transport class that handles the spans delivery to the
@@ -16,6 +17,7 @@ module Datadog
16
17
 
17
18
  # header containing the number of traces in a payload
18
19
  TRACE_COUNT_HEADER = 'X-Datadog-Trace-Count'.freeze
20
+ RUBY_INTERPRETER = RUBY_VERSION > '1.9' ? RUBY_ENGINE + '-' + RUBY_PLATFORM : 'ruby-' + RUBY_PLATFORM
19
21
 
20
22
  def initialize(hostname, port, options = {})
21
23
  @hostname = hostname
@@ -28,6 +30,10 @@ module Datadog
28
30
  # overwrite the Content-type with the one chosen in the Encoder
29
31
  @headers = options.fetch(:headers, {})
30
32
  @headers['Content-Type'] = @encoder.content_type
33
+ @headers['Datadog-Meta-Lang'] = 'ruby'
34
+ @headers['Datadog-Meta-Lang-Version'] = RUBY_VERSION
35
+ @headers['Datadog-Meta-Lang-Interpreter'] = RUBY_INTERPRETER
36
+ @headers['Datadog-Meta-Tracer-Version'] = Datadog::VERSION::STRING
31
37
 
32
38
  # stats
33
39
  @mutex = Mutex.new
@@ -2,7 +2,7 @@ module Datadog
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 8
5
- PATCH = 0
5
+ PATCH = 1
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.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datadog, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-24 00:00:00.000000000 Z
11
+ date: 2017-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -149,6 +149,7 @@ files:
149
149
  - lib/ddtrace/contrib/rails/active_support.rb
150
150
  - lib/ddtrace/contrib/rails/core_extensions.rb
151
151
  - lib/ddtrace/contrib/rails/framework.rb
152
+ - lib/ddtrace/contrib/rails/middlewares.rb
152
153
  - lib/ddtrace/contrib/rails/utils.rb
153
154
  - lib/ddtrace/contrib/redis/patcher.rb
154
155
  - lib/ddtrace/contrib/redis/quantize.rb