ddtrace 0.39.0 → 0.40.0

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +56 -0
  3. data/.gitlab-ci.yml +1 -0
  4. data/.simplecov +38 -0
  5. data/Appraisals +87 -1
  6. data/CHANGELOG.md +63 -1
  7. data/Rakefile +500 -465
  8. data/ddtrace.gemspec +1 -0
  9. data/docs/DevelopmentGuide.md +16 -0
  10. data/docs/GettingStarted.md +49 -32
  11. data/lib/ddtrace.rb +1 -0
  12. data/lib/ddtrace/configuration.rb +36 -5
  13. data/lib/ddtrace/configuration/components.rb +4 -7
  14. data/lib/ddtrace/contrib/action_pack/action_controller/instrumentation.rb +0 -7
  15. data/lib/ddtrace/contrib/que/configuration/settings.rb +42 -0
  16. data/lib/ddtrace/contrib/que/ext.rb +30 -0
  17. data/lib/ddtrace/contrib/que/integration.rb +42 -0
  18. data/lib/ddtrace/contrib/que/patcher.rb +24 -0
  19. data/lib/ddtrace/contrib/que/tracer.rb +56 -0
  20. data/lib/ddtrace/contrib/racecar/events.rb +2 -0
  21. data/lib/ddtrace/contrib/racecar/events/consume.rb +27 -0
  22. data/lib/ddtrace/contrib/racecar/ext.rb +1 -0
  23. data/lib/ddtrace/contrib/rack/middlewares.rb +2 -0
  24. data/lib/ddtrace/contrib/rails/configuration/settings.rb +5 -0
  25. data/lib/ddtrace/contrib/rails/ext.rb +1 -0
  26. data/lib/ddtrace/contrib/rails/log_injection.rb +81 -0
  27. data/lib/ddtrace/contrib/rails/middlewares.rb +7 -2
  28. data/lib/ddtrace/contrib/rails/patcher.rb +15 -0
  29. data/lib/ddtrace/contrib/sinatra/env.rb +5 -4
  30. data/lib/ddtrace/contrib/sinatra/tracer.rb +21 -42
  31. data/lib/ddtrace/contrib/sinatra/tracer_middleware.rb +50 -23
  32. data/lib/ddtrace/version.rb +1 -1
  33. data/lib/ddtrace/workers/async.rb +2 -2
  34. data/lib/ddtrace/workers/loop.rb +1 -1
  35. data/lib/ddtrace/workers/polling.rb +1 -1
  36. metadata +67 -31
@@ -67,5 +67,6 @@ Gem::Specification.new do |spec|
67
67
  spec.add_development_dependency 'redcarpet', '~> 3.4' if RUBY_PLATFORM != 'java'
68
68
  spec.add_development_dependency 'pry', '~> 0.10.4'
69
69
  spec.add_development_dependency 'pry-stack_explorer', '~> 0.4.9.2'
70
+ spec.add_development_dependency 'simplecov', '~> 0.17'
70
71
  spec.add_development_dependency 'warning', '~> 1' if RUBY_VERSION >= '2.5.0'
71
72
  end
@@ -98,6 +98,22 @@ $ bundle exec appraisal contrib rake spec:redis'[--seed,1234]'
98
98
 
99
99
  This can be useful for replicating conditions from CI or isolating certain tests.
100
100
 
101
+ **Checking test coverage**
102
+
103
+ You can check test code coverage by creating a report _after_ running a test suite:
104
+ ```
105
+ # Run the desired test suite
106
+ $ bundle exec appraisal contrib rake spec:redis
107
+ # Generate report for the suite executed
108
+ $ bundle exec rake coverage:report
109
+ ```
110
+
111
+ A webpage will be generated at `coverage/report/index.html` with the resulting report.
112
+
113
+ Because you are likely not running all tests locally, your report will contain partial coverage results.
114
+ You *must* check the CI step `coverage` for the complete test coverage report, ensuring coverage is not
115
+ decreased.
116
+
101
117
  ### Checking code quality
102
118
 
103
119
  **Linting**
@@ -43,11 +43,12 @@ To contribute, check out the [contribution guidelines][contribution docs] and [d
43
43
  - [Grape](#grape)
44
44
  - [GraphQL](#graphql)
45
45
  - [gRPC](#grpc)
46
- - [http.rb](#http.rb)
46
+ - [http.rb](#http-rb)
47
47
  - [MongoDB](#mongodb)
48
48
  - [MySQL2](#mysql2)
49
49
  - [Net/HTTP](#net-http)
50
50
  - [Presto](#presto)
51
+ - [Que](#que)
51
52
  - [Racecar](#racecar)
52
53
  - [Rack](#rack)
53
54
  - [Rails](#rails)
@@ -92,8 +93,8 @@ To contribute, check out the [contribution guidelines][contribution docs] and [d
92
93
  | | | 2.2 | Full | Latest |
93
94
  | | | 2.1 | Full | Latest |
94
95
  | | | 2.0 | Full | Latest |
95
- | | | 1.9.3 | Maintenance (until August 6th, 2020) | < 0.27.0 |
96
- | | | 1.9.1 | Maintenance (until August 6th, 2020) | < 0.27.0 |
96
+ | | | 1.9.3 | EOL since August 6th, 2020 | < 0.27.0 |
97
+ | | | 1.9.1 | EOL since August 6th, 2020 | < 0.27.0 |
97
98
  | JRuby | https://www.jruby.org | 9.2 | Full | Latest |
98
99
 
99
100
  **Supported web servers**:
@@ -346,12 +347,13 @@ For a list of available integrations, and their configuration options, please re
346
347
  | Grape | `grape` | `>= 1.0` | `>= 1.0` | *[Link](#grape)* | *[Link](https://github.com/ruby-grape/grape)* |
347
348
  | GraphQL | `graphql` | `>= 1.7.9` | `>= 1.7.9` | *[Link](#graphql)* | *[Link](https://github.com/rmosolgo/graphql-ruby)* |
348
349
  | gRPC | `grpc` | `>= 1.7` | *gem not available* | *[Link](#grpc)* | *[Link](https://github.com/grpc/grpc/tree/master/src/rubyc)* |
349
- | http.rb | `httprb` | `>= 2.0` | `>= 2.0` | *[Link](#http.rb)* | *[Link](https://github.com/httprb/http)* |
350
+ | http.rb | `httprb` | `>= 2.0` | `>= 2.0` | *[Link](#http-rb)* | *[Link](https://github.com/httprb/http)* |
350
351
  | Kafka | `ruby-kafka` | `>= 0.7.10` | `>= 0.7.10` | *[Link](#kafka)* | *[Link](https://github.com/zendesk/ruby-kafka)* |
351
352
  | MongoDB | `mongo` | `>= 2.1` | `>= 2.1` | *[Link](#mongodb)* | *[Link](https://github.com/mongodb/mongo-ruby-driver)* |
352
353
  | MySQL2 | `mysql2` | `>= 0.3.21` | *gem not available* | *[Link](#mysql2)* | *[Link](https://github.com/brianmario/mysql2)* |
353
354
  | Net/HTTP | `http` | *(Any supported Ruby)* | *(Any supported Ruby)* | *[Link](#nethttp)* | *[Link](https://ruby-doc.org/stdlib-2.4.0/libdoc/net/http/rdoc/Net/HTTP.html)* |
354
355
  | Presto | `presto` | `>= 0.5.14` | `>= 0.5.14` | *[Link](#presto)* | *[Link](https://github.com/treasure-data/presto-client-ruby)* |
356
+ | Que | `que` | `>= 1.0.0.beta2` | `>= 1.0.0.beta2` | *[Link](#que)* | *[Link](https://github.com/que-rb/que)* |
355
357
  | Racecar | `racecar` | `>= 0.3.5` | `>= 0.3.5` | *[Link](#racecar)* | *[Link](https://github.com/zendesk/racecar)* |
356
358
  | Rack | `rack` | `>= 1.1` | `>= 1.1` | *[Link](#rack)* | *[Link](https://github.com/rack/rack)* |
357
359
  | Rails | `rails` | `>= 3.0` | `>= 3.0` | *[Link](#rails)* | *[Link](https://github.com/rails/rails)* |
@@ -1110,6 +1112,30 @@ Where `options` is an optional `Hash` that accepts the following parameters:
1110
1112
  | `analytics_enabled` | Enable analytics for spans produced by this integration. `true` for on, `nil` to defer to global setting, `false` for off. | `false` |
1111
1113
  | `service_name` | Service name used for `presto` instrumentation | `'presto'` |
1112
1114
 
1115
+ ### Que
1116
+
1117
+ The Que integration is a middleware which will trace job executions.
1118
+
1119
+ You can enable it through `Datadog.configure`:
1120
+
1121
+ ```ruby
1122
+ require 'ddtrace'
1123
+
1124
+ Datadog.configure do |c|
1125
+ c.use :que, options
1126
+ end
1127
+ ```
1128
+
1129
+ Where `options` is an optional `Hash` that accepts the following parameters:
1130
+
1131
+ | Key | Description | Default |
1132
+ | --- | ----------- | ------- |
1133
+ | `analytics_enabled` | Enable analytics for spans produced by this integration. `true` for on, `nil` to defer to global setting, `false` for off. | `false` |
1134
+ | `enabled` | Defines whether Que should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` |
1135
+ | `service_name` | Service name used for `que` instrumentation | `'que'` |
1136
+ | `tag_args` | Enable tagging of a job's args field. `true` for on, `false` for off. | `false` |
1137
+ | `tag_data` | Enable tagging of a job's data field. `true` for on, `false` for off. | `false` |
1138
+
1113
1139
  ### Racecar
1114
1140
 
1115
1141
  The Racecar integration provides tracing for Racecar jobs.
@@ -1172,7 +1198,6 @@ Where `options` is an optional `Hash` that accepts the following parameters:
1172
1198
  | `service_name` | Service name used for `rack` instrumentation | `'rack'` |
1173
1199
  | `web_service_name` | Service name for frontend server request queuing spans. (e.g. `'nginx'`) | `'web-server'` |
1174
1200
 
1175
-
1176
1201
  **Configuring URL quantization behavior**
1177
1202
 
1178
1203
  ```ruby
@@ -1232,6 +1257,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
1232
1257
  | `middleware_names` | Enables any short-circuited middleware requests to display the middleware name as a resource for the trace. | `false` |
1233
1258
  | `service_name` | Service name used when tracing application requests (on the `rack` level) | `'<app_name>'` (inferred from your Rails application namespace) |
1234
1259
  | `template_base_path` | Used when the template name is parsed. If you don't store your templates in the `views/` folder, you may need to change this value | `'views/'` |
1260
+ | `log_injection` | Automatically enables injection [Trace Correlation](#trace-correlation) information, such as `dd.trace_id`, into Rails logs. Supports the default logger (`ActiveSupport::TaggedLogging`) and `Lograge`. Details on the format of Trace Correlation information can be found in the [Trace Correlation](#trace-correlation) section. | `false` |
1235
1261
 
1236
1262
  **Supported versions**
1237
1263
 
@@ -1721,6 +1747,7 @@ Other Environment Variables:
1721
1747
  - `DD_TRACE_<INTEGRATION>_ENABLED`: Enables or disables an **activated** integration. Defaults to `true`.. e.g. `DD_TRACE_RAILS_ENABLED=false`. This option has no effects on integrations that have not been explicitly activated (e.g. `Datadog.configure{ |c| c.use :integration }`).on code. This environment variable can only be used to disable an integration.
1722
1748
  - `DD_TRACE_<INTEGRATION>_ANALYTICS_ENABLED`: Enables or disable App Analytics for a specific integration. Valid values are: true or false (default). e.g. `DD_TRACE_ACTION_CABLE_ANALYTICS_ENABLED=true`.
1723
1749
  - `DD_TRACE_<INTEGRATION>_ANALYTICS_SAMPLE_RATE`: Sets the App Analytics sampling rate for a specific integration. A floating number between 0.0 and 1.0 (default). e.g. `DD_TRACE_ACTION_CABLE_ANALYTICS_SAMPLE_RATE=0.5`.
1750
+ - `DD_LOGS_INJECTION`: Automatically enables injection [Trace Correlation](#trace-correlation) information, such as `dd.trace_id`, into Rails logs. Supports the default logger (`ActiveSupport::TaggedLogging`) and `Lograge`. Details on the format of Trace Correlation information can be found in the [Trace Correlation](#trace-correlation) section. Valid values are: `true` or `false`(default). e.g. `DD_LOGS_INJECTION=true`.
1724
1751
 
1725
1752
  ### Sampling
1726
1753
 
@@ -1887,7 +1914,7 @@ For more details on how to activate distributed tracing for integrations, see th
1887
1914
  - [Rack](#rack)
1888
1915
  - [Rails](#rails)
1889
1916
  - [Sinatra](#sinatra)
1890
- - [http.rb](#http.rb)
1917
+ - [http.rb](#http-rb)
1891
1918
 
1892
1919
  **Using the HTTP propagator**
1893
1920
 
@@ -2001,34 +2028,26 @@ Datadog::Pipeline.before_flush(
2001
2028
 
2002
2029
  ### Trace correlation
2003
2030
 
2004
- In many cases, such as logging, it may be useful to correlate trace IDs to other events or data streams, for easier cross-referencing. The tracer can produce a correlation identifier for the currently active trace via `active_correlation`, which can be used to decorate these other data sources.
2031
+ In many cases, such as logging, it may be useful to correlate trace IDs to other events or data streams, for easier cross-referencing.
2032
+
2033
+ #### For logging in Rails applications
2034
+
2035
+ ##### Automatic
2036
+
2037
+ For Rails applications using the default logger (`ActiveSupport::TaggedLogging`) or `lograge`, you can automatically enable trace correlation injection by setting the `rails` instrumentation configuration option `log_injection` to `true` or by setting environment variable `DD_LOGS_INJECTION=true`:
2005
2038
 
2006
2039
  ```ruby
2007
- # When a trace is active...
2008
- Datadog.tracer.trace('correlation.example') do
2009
- # Returns #<Datadog::Correlation::Identifier>
2010
- correlation = Datadog.tracer.active_correlation
2011
- correlation.trace_id # => 5963550561812073440
2012
- correlation.span_id # => 2232727802607726424
2013
- correlation.env # => 'production' (derived from DD_ENV)
2014
- correlation.service # => 'billing-api' (derived from DD_SERVICE)
2015
- correlation.version # => '2.5.17' (derived from DD_VERSION)
2016
- end
2040
+ # config/initializers/datadog.rb
2041
+ require 'ddtrace'
2017
2042
 
2018
- # When a trace isn't active...
2019
- correlation = Datadog.tracer.active_correlation
2020
- # Returns #<Datadog::Correlation::Identifier>
2021
- correlation = Datadog.tracer.active_correlation
2022
- correlation.trace_id # => 0
2023
- correlation.span_id # => 0
2024
- correlation.env # => 'production' (derived from DD_ENV)
2025
- correlation.service # => 'billing-api' (derived from DD_SERVICE)
2026
- correlation.version # => '2.5.17' (derived from DD_VERSION)
2043
+ Datadog.configure do |c|
2044
+ c.use :rails, log_injection: true
2045
+ end
2027
2046
  ```
2028
2047
 
2029
- #### For logging in Rails applications using Lograge (recommended)
2048
+ ##### Manual (Lograge)
2030
2049
 
2031
- After [setting up Lograge in a Rails application](https://docs.datadoghq.com/logs/log_collection/ruby/), modify the `custom_options` block in your environment configuration file (e.g. `config/environments/production.rb`) to add the trace IDs:
2050
+ After [setting up Lograge in a Rails application](https://docs.datadoghq.com/logs/log_collection/ruby/), manually modify the `custom_options` block in your environment configuration file (e.g. `config/environments/production.rb`) to add the trace IDs.
2032
2051
 
2033
2052
  ```ruby
2034
2053
  config.lograge.custom_options = lambda do |event|
@@ -2051,11 +2070,9 @@ config.lograge.custom_options = lambda do |event|
2051
2070
  end
2052
2071
  ```
2053
2072
 
2054
- #### For logging in Rails applications
2055
-
2056
- Rails applications which are configured with an `ActiveSupport::TaggedLogging` logger can append correlation IDs as tags to log output. The default Rails logger implements this tagged logging, making it easier to add correlation tags.
2073
+ ##### Manual (ActiveSupport::TaggedLogging)
2057
2074
 
2058
- In your Rails environment configuration file, add the following:
2075
+ Rails applications which are configured with the default `ActiveSupport::TaggedLogging` logger can append correlation IDs as tags to log output. To enable Trace Correlation with `ActiveSupport::TaggedLogging`, in your Rails environment configuration file, add the following:
2059
2076
 
2060
2077
  ```ruby
2061
2078
  Rails.application.configure do
@@ -59,6 +59,7 @@ require 'ddtrace/contrib/httprb/integration'
59
59
  require 'ddtrace/contrib/integration'
60
60
  require 'ddtrace/contrib/kafka/integration'
61
61
  require 'ddtrace/contrib/presto/integration'
62
+ require 'ddtrace/contrib/que/integration'
62
63
  require 'ddtrace/contrib/mysql2/integration'
63
64
  require 'ddtrace/contrib/mongodb/integration'
64
65
  require 'ddtrace/contrib/racecar/integration'
@@ -22,9 +22,9 @@ module Datadog
22
22
  # Build immutable components from settings
23
23
  @components ||= nil
24
24
  @components = if @components
25
- Components.replace!(@components, target)
25
+ replace_components!(target, @components)
26
26
  else
27
- Components.new(target)
27
+ build_components(target)
28
28
  end
29
29
 
30
30
  target
@@ -36,18 +36,49 @@ module Datadog
36
36
  def_delegators \
37
37
  :components,
38
38
  :health_metrics,
39
- :logger,
40
39
  :runtime_metrics,
41
40
  :tracer
42
41
 
42
+ def logger
43
+ if instance_variable_defined?(:@components) && @components
44
+ @temp_logger = nil
45
+ components.logger
46
+ else
47
+ # Use default logger without initializing components.
48
+ # This prevents recursive loops while initializing.
49
+ # e.g. Get logger --> Build components --> Log message --> Repeat...
50
+ @temp_logger ||= begin
51
+ logger = configuration.logger.instance || Datadog::Logger.new(STDOUT)
52
+ logger.level = configuration.diagnostics.debug ? ::Logger::DEBUG : configuration.logger.level
53
+ logger
54
+ end
55
+ end
56
+ end
57
+
43
58
  def shutdown!
44
- components.teardown! if @components
59
+ components.shutdown! if instance_variable_defined?(:@components) && @components
45
60
  end
46
61
 
47
62
  protected
48
63
 
49
64
  def components
50
- @components ||= Components.new(configuration)
65
+ @components ||= build_components(configuration)
66
+ end
67
+
68
+ private
69
+
70
+ def build_components(settings)
71
+ components = Components.new(settings)
72
+ components.startup!(settings)
73
+ components
74
+ end
75
+
76
+ def replace_components!(settings, old)
77
+ components = Components.new(settings)
78
+
79
+ old.shutdown!(components)
80
+ components.startup!(settings)
81
+ components
51
82
  end
52
83
  end
53
84
  end
@@ -10,12 +10,6 @@ module Datadog
10
10
  # rubocop:disable Metrics/LineLength
11
11
  class Components
12
12
  class << self
13
- def replace!(old, settings)
14
- replacement = new(settings)
15
- old.teardown!(replacement)
16
- replacement
17
- end
18
-
19
13
  def build_health_metrics(settings)
20
14
  settings = settings.diagnostics.health_metrics
21
15
  options = { enabled: settings.enabled }
@@ -118,10 +112,13 @@ module Datadog
118
112
  @health_metrics = self.class.build_health_metrics(settings)
119
113
  end
120
114
 
115
+ # Starts up components
116
+ def startup!(settings); end
117
+
121
118
  # Shuts down all the components in use.
122
119
  # If it has another instance to compare to, it will compare
123
120
  # and avoid tearing down parts still in use.
124
- def teardown!(replacement = nil)
121
+ def shutdown!(replacement = nil)
125
122
  # Shutdown the old tracer, unless it's still being used.
126
123
  # (e.g. a custom tracer instance passed in.)
127
124
  tracer.shutdown! unless replacement && tracer == replacement.tracer
@@ -66,13 +66,6 @@ module Datadog
66
66
  span.status = 1 if status.starts_with?('5')
67
67
  elsif Utils.exception_is_error?(exception)
68
68
  span.set_error(exception)
69
-
70
- # Some exception gets handled by Rails middleware before it can be set on Rack middleware
71
- # The rack span is the root span of the request and should make sure it has the full exception
72
- # set on it.
73
- if env[:datadog_rack_request_span]
74
- env[:datadog_rack_request_span].set_error(exception)
75
- end
76
69
  end
77
70
  ensure
78
71
  span.finish
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ddtrace/contrib/configuration/settings'
4
+
5
+ module Datadog
6
+ module Contrib
7
+ module Que
8
+ module Configuration
9
+ # Default settings for the Que integration
10
+ class Settings < Datadog::Contrib::Configuration::Settings
11
+ option :service_name, default: Ext::SERVICE_NAME
12
+ option :distributed_tracing, default: true
13
+
14
+ option :enabled do |o|
15
+ o.default { env_to_bool(Ext::ENV_ENABLED, true) }
16
+ o.lazy
17
+ end
18
+
19
+ option :analytics_enabled do |o|
20
+ o.default { env_to_bool([Ext::ENV_ANALYTICS_ENABLED, Ext::ENV_ANALYTICS_ENABLED_OLD], false) }
21
+ o.lazy
22
+ end
23
+
24
+ option :analytics_sample_rate do |o|
25
+ o.default { env_to_float([Ext::ENV_ANALYTICS_SAMPLE_RATE, Ext::ENV_ANALYTICS_SAMPLE_RATE_OLD], 1.0) }
26
+ o.lazy
27
+ end
28
+
29
+ option :tag_args do |o|
30
+ o.default { env_to_bool(Ext::ENV_TAG_ARGS_ENABLED, false) }
31
+ o.lazy
32
+ end
33
+
34
+ option :tag_data do |o|
35
+ o.default { env_to_bool(Ext::ENV_TAG_DATA_ENABLED, false) }
36
+ o.lazy
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datadog
4
+ module Contrib
5
+ module Que
6
+ # Que integration constants
7
+ module Ext
8
+ APP = 'que'.freeze
9
+ ENV_ANALYTICS_ENABLED = 'DD_TRACE_QUE_ANALYTICS_ENABLED'.freeze
10
+ ENV_ANALYTICS_ENABLED_OLD = 'DD_QUE_ANALYTICS_ENABLED'.freeze
11
+ ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_QUE_ANALYTICS_SAMPLE_RATE'.freeze
12
+ ENV_ANALYTICS_SAMPLE_RATE_OLD = 'DD_QUE_ANALYTICS_SAMPLE_RATE'.freeze
13
+ ENV_ENABLED = 'DD_TRACE_QUE_ENABLED'.freeze
14
+ ENV_TAG_ARGS_ENABLED = 'DD_TRACE_QUE_TAG_ARGS_ENABLED'.freeze
15
+ ENV_TAG_DATA_ENABLED = 'DD_TRACE_QUE_TAG_DATA_ENABLED'.freeze
16
+ SERVICE_NAME = 'que'.freeze
17
+ SPAN_JOB = 'que.job'.freeze
18
+ TAG_JOB_ARGS = 'que.job.args'.freeze
19
+ TAG_JOB_DATA = 'que.job.data'.freeze
20
+ TAG_JOB_ERROR_COUNT = 'que.job.error_count'.freeze
21
+ TAG_JOB_EXPIRED_AT = 'que.job.expired_at'.freeze
22
+ TAG_JOB_FINISHED_AT = 'que.job.finished_at'.freeze
23
+ TAG_JOB_ID = 'que.job.id'.freeze
24
+ TAG_JOB_PRIORITY = 'que.job.priority'.freeze
25
+ TAG_JOB_QUEUE = 'que.job.queue'.freeze
26
+ TAG_JOB_RUN_AT = 'que.job.run_at'.freeze
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ddtrace/contrib/integration'
4
+ require 'ddtrace/contrib/que/ext'
5
+ require 'ddtrace/contrib/que/configuration/settings'
6
+ require 'ddtrace/contrib/que/patcher'
7
+
8
+ module Datadog
9
+ module Contrib
10
+ module Que
11
+ # Description of Que integration
12
+ class Integration
13
+ include Datadog::Contrib::Integration
14
+
15
+ MINIMUM_VERSION = Gem::Version.new('1.0.0.beta2')
16
+
17
+ register_as :que, auto_patch: true
18
+
19
+ def self.version
20
+ Gem.loaded_specs[Datadog::Contrib::Que::Ext::APP] &&
21
+ Gem.loaded_specs[Datadog::Contrib::Que::Ext::APP].version
22
+ end
23
+
24
+ def self.loaded?
25
+ !defined?(::Que).nil?
26
+ end
27
+
28
+ def self.compatible?
29
+ super && version >= MINIMUM_VERSION
30
+ end
31
+
32
+ def default_configuration
33
+ Configuration::Settings.new
34
+ end
35
+
36
+ def patcher
37
+ Patcher
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ddtrace/contrib/que/tracer'
4
+
5
+ module Datadog
6
+ module Contrib
7
+ module Que
8
+ # Patcher enables patching of 'que' module.
9
+ module Patcher
10
+ include Datadog::Contrib::Patcher
11
+
12
+ module_function
13
+
14
+ def target_version
15
+ Integration.version
16
+ end
17
+
18
+ def patch
19
+ ::Que.job_middleware.push(Que::Tracer.new)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end