ddtrace 0.34.2 → 0.35.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 (103) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +58 -9
  3. data/.circleci/images/primary/Dockerfile-jruby-9.2 +77 -0
  4. data/Appraisals +1 -1
  5. data/CHANGELOG.md +33 -1
  6. data/Rakefile +1 -1
  7. data/ddtrace.gemspec +5 -3
  8. data/docs/DevelopmentGuide.md +1 -1
  9. data/docs/GettingStarted.md +89 -36
  10. data/lib/ddtrace.rb +1 -1
  11. data/lib/ddtrace/buffer.rb +9 -9
  12. data/lib/ddtrace/chunker.rb +34 -0
  13. data/lib/ddtrace/configuration.rb +28 -5
  14. data/lib/ddtrace/configuration/components.rb +154 -0
  15. data/lib/ddtrace/configuration/settings.rb +131 -63
  16. data/lib/ddtrace/context.rb +6 -6
  17. data/lib/ddtrace/context_flush.rb +1 -1
  18. data/lib/ddtrace/contrib/action_cable/instrumentation.rb +1 -1
  19. data/lib/ddtrace/contrib/action_pack/action_controller/instrumentation.rb +2 -2
  20. data/lib/ddtrace/contrib/action_view/events/render_partial.rb +1 -1
  21. data/lib/ddtrace/contrib/action_view/events/render_template.rb +1 -1
  22. data/lib/ddtrace/contrib/action_view/instrumentation/partial_renderer.rb +1 -1
  23. data/lib/ddtrace/contrib/action_view/instrumentation/template_renderer.rb +2 -2
  24. data/lib/ddtrace/contrib/action_view/patcher.rb +1 -1
  25. data/lib/ddtrace/contrib/active_record/events/instantiation.rb +1 -1
  26. data/lib/ddtrace/contrib/active_record/events/sql.rb +1 -1
  27. data/lib/ddtrace/contrib/active_support/cache/instrumentation.rb +2 -2
  28. data/lib/ddtrace/contrib/active_support/notifications/subscription.rb +2 -2
  29. data/lib/ddtrace/contrib/analytics.rb +1 -1
  30. data/lib/ddtrace/contrib/dalli/patcher.rb +1 -1
  31. data/lib/ddtrace/contrib/dalli/quantize.rb +1 -1
  32. data/lib/ddtrace/contrib/elasticsearch/patcher.rb +1 -1
  33. data/lib/ddtrace/contrib/excon/middleware.rb +2 -2
  34. data/lib/ddtrace/contrib/faraday/patcher.rb +1 -1
  35. data/lib/ddtrace/contrib/grape/endpoint.rb +5 -5
  36. data/lib/ddtrace/contrib/grape/patcher.rb +1 -1
  37. data/lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb +1 -1
  38. data/lib/ddtrace/contrib/grpc/datadog_interceptor/server.rb +2 -2
  39. data/lib/ddtrace/contrib/grpc/patcher.rb +1 -1
  40. data/lib/ddtrace/contrib/http/instrumentation.rb +1 -1
  41. data/lib/ddtrace/contrib/mongodb/subscribers.rb +2 -2
  42. data/lib/ddtrace/contrib/patchable.rb +1 -1
  43. data/lib/ddtrace/contrib/patcher.rb +3 -3
  44. data/lib/ddtrace/contrib/presto/instrumentation.rb +3 -3
  45. data/lib/ddtrace/contrib/presto/patcher.rb +1 -1
  46. data/lib/ddtrace/contrib/rack/middlewares.rb +2 -2
  47. data/lib/ddtrace/contrib/rack/patcher.rb +2 -2
  48. data/lib/ddtrace/contrib/rack/request_queue.rb +1 -1
  49. data/lib/ddtrace/contrib/rake/instrumentation.rb +2 -2
  50. data/lib/ddtrace/contrib/redis/quantize.rb +1 -1
  51. data/lib/ddtrace/contrib/resque/resque_job.rb +2 -2
  52. data/lib/ddtrace/contrib/sidekiq/tracing.rb +1 -1
  53. data/lib/ddtrace/contrib/sinatra/env.rb +20 -0
  54. data/lib/ddtrace/contrib/sinatra/ext.rb +6 -0
  55. data/lib/ddtrace/contrib/sinatra/patcher.rb +1 -0
  56. data/lib/ddtrace/contrib/sinatra/tracer.rb +98 -35
  57. data/lib/ddtrace/contrib/sinatra/tracer_middleware.rb +16 -13
  58. data/lib/ddtrace/correlation.rb +9 -6
  59. data/lib/ddtrace/diagnostics/health.rb +2 -6
  60. data/lib/ddtrace/encoding.rb +13 -39
  61. data/lib/ddtrace/event.rb +1 -1
  62. data/lib/ddtrace/ext/correlation.rb +1 -0
  63. data/lib/ddtrace/ext/diagnostics.rb +2 -0
  64. data/lib/ddtrace/ext/environment.rb +1 -0
  65. data/lib/ddtrace/ext/forced_tracing.rb +1 -1
  66. data/lib/ddtrace/logger.rb +3 -44
  67. data/lib/ddtrace/metrics.rb +5 -5
  68. data/lib/ddtrace/monkey.rb +1 -1
  69. data/lib/ddtrace/opentracer/global_tracer.rb +1 -1
  70. data/lib/ddtrace/pin.rb +1 -1
  71. data/lib/ddtrace/pipeline.rb +1 -1
  72. data/lib/ddtrace/propagation/http_propagator.rb +2 -2
  73. data/lib/ddtrace/runtime/cgroup.rb +1 -1
  74. data/lib/ddtrace/runtime/container.rb +1 -1
  75. data/lib/ddtrace/runtime/metrics.rb +5 -2
  76. data/lib/ddtrace/sampler.rb +2 -2
  77. data/lib/ddtrace/sampling/rule.rb +1 -1
  78. data/lib/ddtrace/sampling/rule_sampler.rb +1 -1
  79. data/lib/ddtrace/span.rb +4 -4
  80. data/lib/ddtrace/sync_writer.rb +3 -8
  81. data/lib/ddtrace/tracer.rb +26 -31
  82. data/lib/ddtrace/transport/http.rb +1 -1
  83. data/lib/ddtrace/transport/http/api/instance.rb +4 -0
  84. data/lib/ddtrace/transport/http/builder.rb +3 -5
  85. data/lib/ddtrace/transport/http/client.rb +7 -64
  86. data/lib/ddtrace/transport/http/response.rb +1 -1
  87. data/lib/ddtrace/transport/http/statistics.rb +1 -1
  88. data/lib/ddtrace/transport/http/traces.rb +10 -7
  89. data/lib/ddtrace/transport/io.rb +1 -1
  90. data/lib/ddtrace/transport/io/client.rb +2 -2
  91. data/lib/ddtrace/transport/io/response.rb +3 -1
  92. data/lib/ddtrace/transport/io/traces.rb +50 -3
  93. data/lib/ddtrace/transport/parcel.rb +0 -4
  94. data/lib/ddtrace/transport/statistics.rb +2 -2
  95. data/lib/ddtrace/transport/traces.rb +160 -10
  96. data/lib/ddtrace/utils.rb +1 -1
  97. data/lib/ddtrace/version.rb +2 -2
  98. data/lib/ddtrace/workers.rb +5 -13
  99. data/lib/ddtrace/workers/async.rb +2 -2
  100. data/lib/ddtrace/workers/runtime_metrics.rb +47 -0
  101. data/lib/ddtrace/workers/trace_writer.rb +199 -0
  102. data/lib/ddtrace/writer.rb +20 -27
  103. metadata +22 -32
@@ -34,7 +34,7 @@ module Datadog
34
34
  # Add shutdown hook:
35
35
  # Ensures the tracer has an opportunity to flush traces
36
36
  # and cleanup before terminating the process.
37
- at_exit { Datadog.tracer.shutdown! }
37
+ at_exit { Datadog.shutdown! }
38
38
  end
39
39
 
40
40
  require 'ddtrace/contrib/action_cable/integration'
@@ -83,7 +83,7 @@ module Datadog
83
83
  @buffer_accepted += 1
84
84
  @buffer_accepted_lengths += trace.length
85
85
  rescue StandardError => e
86
- Datadog::Logger.log.debug("Failed to measure queue accept. Cause: #{e.message} Source: #{e.backtrace.first}")
86
+ Datadog.logger.debug("Failed to measure queue accept. Cause: #{e.message} Source: #{e.backtrace.first}")
87
87
  end
88
88
 
89
89
  def measure_drop(trace)
@@ -91,21 +91,21 @@ module Datadog
91
91
  @buffer_spans -= trace.length
92
92
  @buffer_accepted_lengths -= trace.length
93
93
  rescue StandardError => e
94
- Datadog::Logger.log.debug("Failed to measure queue drop. Cause: #{e.message} Source: #{e.backtrace.first}")
94
+ Datadog.logger.debug("Failed to measure queue drop. Cause: #{e.message} Source: #{e.backtrace.first}")
95
95
  end
96
96
 
97
97
  def measure_pop(traces)
98
98
  # Accepted
99
- Diagnostics::Health.metrics.queue_accepted(@buffer_accepted)
100
- Diagnostics::Health.metrics.queue_accepted_lengths(@buffer_accepted_lengths)
99
+ Datadog.health_metrics.queue_accepted(@buffer_accepted)
100
+ Datadog.health_metrics.queue_accepted_lengths(@buffer_accepted_lengths)
101
101
 
102
102
  # Dropped
103
- Diagnostics::Health.metrics.queue_dropped(@buffer_dropped)
103
+ Datadog.health_metrics.queue_dropped(@buffer_dropped)
104
104
 
105
105
  # Queue gauges
106
- Diagnostics::Health.metrics.queue_max_length(@max_size)
107
- Diagnostics::Health.metrics.queue_spans(@buffer_spans)
108
- Diagnostics::Health.metrics.queue_length(traces.length)
106
+ Datadog.health_metrics.queue_max_length(@max_size)
107
+ Datadog.health_metrics.queue_spans(@buffer_spans)
108
+ Datadog.health_metrics.queue_length(traces.length)
109
109
 
110
110
  # Reset aggregated metrics
111
111
  @buffer_accepted = 0
@@ -113,7 +113,7 @@ module Datadog
113
113
  @buffer_dropped = 0
114
114
  @buffer_spans = 0
115
115
  rescue StandardError => e
116
- Datadog::Logger.log.debug("Failed to measure queue. Cause: #{e.message} Source: #{e.backtrace.first}")
116
+ Datadog.logger.debug("Failed to measure queue. Cause: #{e.message} Source: #{e.backtrace.first}")
117
117
  end
118
118
  end
119
119
  end
@@ -0,0 +1,34 @@
1
+ require 'json'
2
+ require 'msgpack'
3
+
4
+ module Datadog
5
+ # Chunks list of elements into batches
6
+ module Chunker
7
+ module_function
8
+
9
+ # Chunks a list into batches of at most +max_chunk_size+ elements each.
10
+ #
11
+ # An exception can occur if a single element is too large. That single
12
+ # element will be returned in its own chunk. You have to verify by yourself
13
+ # when such elements are returned.
14
+ #
15
+ # @param list [Enumerable] list of elements
16
+ # @param max_chunk_size [Numeric] maximum acceptable chunk size
17
+ # @return [Enumerable] lazy list of chunks
18
+ def chunk_by_size(list, max_chunk_size)
19
+ chunk_agg = 0
20
+ list.slice_before do |elem|
21
+ size = elem.size
22
+ chunk_agg += size
23
+ if chunk_agg > max_chunk_size
24
+ # Can't fit element in current chunk, start a new one.
25
+ chunk_agg = size
26
+ true
27
+ else
28
+ # Add to current chunk
29
+ false
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,9 +1,14 @@
1
+ require 'forwardable'
2
+
1
3
  require 'ddtrace/configuration/pin_setup'
2
4
  require 'ddtrace/configuration/settings'
5
+ require 'ddtrace/configuration/components'
3
6
 
4
7
  module Datadog
5
8
  # Configuration provides a unique access point for configurations
6
9
  module Configuration
10
+ extend Forwardable
11
+
7
12
  attr_writer :configuration
8
13
 
9
14
  def configuration
@@ -13,18 +18,36 @@ module Datadog
13
18
  def configure(target = configuration, opts = {})
14
19
  if target.is_a?(Settings)
15
20
  yield(target) if block_given?
21
+
22
+ # Build immutable components from settings
23
+ @components ||= nil
24
+ @components = if @components
25
+ Components.replace!(@components, target)
26
+ else
27
+ Components.new(target)
28
+ end
29
+
30
+ target
16
31
  else
17
32
  PinSetup.new(target, opts).call
18
33
  end
19
34
  end
20
35
 
21
- # Helper methods
22
- def tracer
23
- configuration.tracer
36
+ def_delegators \
37
+ :components,
38
+ :health_metrics,
39
+ :logger,
40
+ :runtime_metrics,
41
+ :tracer
42
+
43
+ def shutdown!
44
+ components.teardown! if @components
24
45
  end
25
46
 
26
- def runtime_metrics
27
- tracer.writer.runtime_metrics
47
+ protected
48
+
49
+ def components
50
+ @components ||= Components.new(configuration)
28
51
  end
29
52
  end
30
53
  end
@@ -0,0 +1,154 @@
1
+ require 'ddtrace/diagnostics/health'
2
+ require 'ddtrace/logger'
3
+ require 'ddtrace/runtime/metrics'
4
+ require 'ddtrace/tracer'
5
+ require 'ddtrace/workers/runtime_metrics'
6
+
7
+ module Datadog
8
+ module Configuration
9
+ # Global components for the trace library.
10
+ # rubocop:disable Metrics/LineLength
11
+ class Components
12
+ class << self
13
+ def replace!(old, settings)
14
+ replacement = new(settings)
15
+ old.teardown!(replacement)
16
+ replacement
17
+ end
18
+
19
+ def build_health_metrics(settings)
20
+ settings = settings.diagnostics.health_metrics
21
+ options = { enabled: settings.enabled }
22
+ options[:statsd] = settings.statsd unless settings.statsd.nil?
23
+
24
+ Datadog::Diagnostics::Health::Metrics.new(options)
25
+ end
26
+
27
+ def build_logger(settings)
28
+ logger = settings.logger.instance || Datadog::Logger.new(STDOUT)
29
+ logger.level = settings.diagnostics.debug ? ::Logger::DEBUG : settings.logger.level
30
+
31
+ logger
32
+ end
33
+
34
+ def build_runtime_metrics(settings)
35
+ options = { enabled: settings.runtime_metrics.enabled }
36
+ options[:statsd] = settings.runtime_metrics.statsd unless settings.runtime_metrics.statsd.nil?
37
+ options[:services] = [settings.service] unless settings.service.nil?
38
+
39
+ Datadog::Runtime::Metrics.new(options)
40
+ end
41
+
42
+ def build_runtime_metrics_worker(settings)
43
+ # NOTE: Should we just ignore building the worker if its not enabled?
44
+ options = settings.runtime_metrics.opts.merge(
45
+ enabled: settings.runtime_metrics.enabled,
46
+ metrics: build_runtime_metrics(settings)
47
+ )
48
+
49
+ Datadog::Workers::RuntimeMetrics.new(options)
50
+ end
51
+
52
+ def build_tracer(settings)
53
+ # If a custom tracer has been provided, use it instead.
54
+ # Ignore all other options (they should already be configured.)
55
+ tracer = settings.tracer.instance
56
+ return tracer unless tracer.nil?
57
+
58
+ tracer = Tracer.new(
59
+ default_service: settings.service,
60
+ enabled: settings.tracer.enabled,
61
+ partial_flush: settings.tracer.partial_flush.enabled,
62
+ tags: build_tracer_tags(settings)
63
+ )
64
+
65
+ # TODO: We reconfigure the tracer here because it has way too many
66
+ # options it allows to mutate, and it's overwhelming to rewrite
67
+ # tracer initialization for now. Just reconfigure using the
68
+ # existing mutable #configure function. Remove when these components
69
+ # are extracted.
70
+ tracer.configure(build_tracer_options(settings))
71
+
72
+ tracer
73
+ end
74
+
75
+ private
76
+
77
+ def build_tracer_tags(settings)
78
+ settings.tags.dup.tap do |tags|
79
+ tags['env'] = settings.env unless settings.env.nil?
80
+ tags['version'] = settings.version unless settings.version.nil?
81
+ end
82
+ end
83
+
84
+ def build_tracer_options(settings)
85
+ settings = settings.tracer
86
+
87
+ {}.tap do |opts|
88
+ opts[:hostname] = settings.hostname unless settings.hostname.nil?
89
+ opts[:min_spans_before_partial_flush] = settings.partial_flush.min_spans_threshold unless settings.partial_flush.min_spans_threshold.nil?
90
+ opts[:partial_flush] = settings.partial_flush.enabled unless settings.partial_flush.enabled.nil?
91
+ opts[:port] = settings.port unless settings.port.nil?
92
+ opts[:priority_sampling] = settings.priority_sampling unless settings.priority_sampling.nil?
93
+ opts[:sampler] = settings.sampler unless settings.sampler.nil?
94
+ opts[:transport_options] = settings.transport_options
95
+ opts[:writer] = settings.writer unless settings.writer.nil?
96
+ opts[:writer_options] = settings.writer_options if settings.writer.nil?
97
+ end
98
+ end
99
+ end
100
+
101
+ attr_reader \
102
+ :health_metrics,
103
+ :logger,
104
+ :runtime_metrics,
105
+ :tracer
106
+
107
+ def initialize(settings)
108
+ # Logger
109
+ @logger = self.class.build_logger(settings)
110
+
111
+ # Tracer
112
+ @tracer = self.class.build_tracer(settings)
113
+
114
+ # Runtime metrics
115
+ @runtime_metrics = self.class.build_runtime_metrics_worker(settings)
116
+
117
+ # Health metrics
118
+ @health_metrics = self.class.build_health_metrics(settings)
119
+ end
120
+
121
+ # Shuts down all the components in use.
122
+ # If it has another instance to compare to, it will compare
123
+ # and avoid tearing down parts still in use.
124
+ def teardown!(replacement = nil)
125
+ # Shutdown the old tracer, unless it's still being used.
126
+ # (e.g. a custom tracer instance passed in.)
127
+ tracer.shutdown! unless replacement && tracer == replacement.tracer
128
+
129
+ # Shutdown workers
130
+ runtime_metrics.enabled = false
131
+ runtime_metrics.stop(true)
132
+
133
+ # Shutdown the old metrics, unless they are still being used.
134
+ # (e.g. custom Statsd instances.)
135
+ old_statsd = [
136
+ runtime_metrics.metrics.statsd,
137
+ health_metrics.statsd
138
+ ].uniq
139
+
140
+ new_statsd = if replacement
141
+ [
142
+ replacement.runtime_metrics.metrics.statsd,
143
+ replacement.health_metrics.statsd
144
+ ].uniq
145
+ else
146
+ []
147
+ end
148
+
149
+ unused_statsd = (old_statsd - (old_statsd & new_statsd))
150
+ unused_statsd.each(&:close)
151
+ end
152
+ end
153
+ end
154
+ end
@@ -1,3 +1,4 @@
1
+ require 'logger'
1
2
  require 'ddtrace/configuration/base'
2
3
 
3
4
  require 'ddtrace/ext/analytics'
@@ -5,34 +6,41 @@ require 'ddtrace/ext/distributed'
5
6
  require 'ddtrace/ext/runtime'
6
7
  require 'ddtrace/ext/sampling'
7
8
 
8
- require 'ddtrace/tracer'
9
- require 'ddtrace/metrics'
10
- require 'ddtrace/diagnostics/health'
11
-
12
9
  module Datadog
13
10
  module Configuration
14
11
  # Global configuration settings for the trace library.
12
+ # rubocop:disable Metrics/ClassLength
15
13
  class Settings
16
14
  include Base
17
15
 
18
16
  #
19
17
  # Configuration options
20
18
  #
19
+ settings :analytics do
20
+ option :enabled do |o|
21
+ o.default { env_to_bool(Ext::Analytics::ENV_TRACE_ANALYTICS_ENABLED, nil) }
22
+ o.lazy
23
+ end
24
+ end
25
+
21
26
  option :analytics_enabled do |o|
22
- # TODO: Raise deprecation warning
23
- o.default { env_to_bool(Ext::Analytics::ENV_TRACE_ANALYTICS_ENABLED, nil) }
24
- o.lazy
27
+ o.delegate_to { get_option(:analytics).enabled }
28
+ o.on_set do |value|
29
+ # TODO: Raise deprecation warning
30
+ get_option(:analytics).enabled = value
31
+ end
25
32
  end
26
33
 
27
34
  settings :diagnostics do
28
- option :health_metrics do |o|
29
- o.default do
30
- Datadog::Diagnostics::Health::Metrics.new(
31
- enabled: env_to_bool(Datadog::Ext::Diagnostics::Health::Metrics::ENV_ENABLED, false)
32
- )
35
+ option :debug, default: false
36
+
37
+ settings :health_metrics do
38
+ option :enabled do |o|
39
+ o.default { env_to_bool(Datadog::Ext::Diagnostics::Health::Metrics::ENV_ENABLED, false) }
40
+ o.lazy
33
41
  end
34
42
 
35
- o.lazy
43
+ option :statsd
36
44
  end
37
45
  end
38
46
 
@@ -63,7 +71,19 @@ module Datadog
63
71
  option :env do |o|
64
72
  o.default { ENV.fetch(Ext::Environment::ENV_ENVIRONMENT, nil) }
65
73
  o.lazy
66
- o.on_set { |value| get_option(:tracer).set_tags('env' => value) }
74
+ end
75
+
76
+ settings :logger do
77
+ option :instance do |o|
78
+ o.setter { |value, old_value| value.is_a?(::Logger) ? value : old_value }
79
+ o.on_set { |value| set_option(:level, value.level) unless value.nil? }
80
+ end
81
+
82
+ option :level, default: ::Logger::WARN
83
+ end
84
+
85
+ def logger=(logger)
86
+ get_option(:logger).instance = logger
67
87
  end
68
88
 
69
89
  option :report_hostname do |o|
@@ -71,19 +91,34 @@ module Datadog
71
91
  o.lazy
72
92
  end
73
93
 
94
+ settings :runtime_metrics do
95
+ option :enabled do |o|
96
+ o.default { env_to_bool(Ext::Runtime::Metrics::ENV_ENABLED, false) }
97
+ o.lazy
98
+ end
99
+
100
+ option :opts, default: ->(_i) { {} }, lazy: true
101
+ option :statsd
102
+ end
103
+
74
104
  # Backwards compatibility for configuring runtime metrics e.g. `c.runtime_metrics enabled: true`
75
105
  def runtime_metrics(options = nil)
76
- runtime_metrics = get_option(:tracer).writer.runtime_metrics
77
- return runtime_metrics if options.nil?
106
+ settings = get_option(:runtime_metrics)
107
+ return settings if options.nil?
78
108
 
109
+ # If options were provided (old style) then raise warnings and apply them:
79
110
  # TODO: Raise deprecation warning
80
- runtime_metrics.configure(options)
111
+ settings.enabled = options[:enabled] if options.key?(:enabled)
112
+ settings.statsd = options[:statsd] if options.key?(:statsd)
113
+ settings
81
114
  end
82
115
 
83
116
  option :runtime_metrics_enabled do |o|
84
- # TODO: Raise deprecation warning
85
- o.default { env_to_bool(Ext::Runtime::Metrics::ENV_ENABLED, false) }
86
- o.lazy
117
+ o.delegate_to { get_option(:runtime_metrics).enabled }
118
+ o.on_set do |value|
119
+ # TODO: Raise deprecation warning
120
+ get_option(:runtime_metrics).enabled = value
121
+ end
87
122
  end
88
123
 
89
124
  settings :sampling do
@@ -101,7 +136,6 @@ module Datadog
101
136
  option :service do |o|
102
137
  o.default { ENV.fetch(Ext::Environment::ENV_SERVICE, nil) }
103
138
  o.lazy
104
- o.on_set { |value| get_option(:tracer).default_service = value }
105
139
  end
106
140
 
107
141
  option :tags do |o|
@@ -125,62 +159,96 @@ module Datadog
125
159
  # Coerce keys to strings
126
160
  string_tags = Hash[new_value.collect { |k, v| [k.to_s, v] }]
127
161
 
162
+ # Cross-populate tag values with other settings
163
+ if env.nil? && string_tags.key?(Ext::Environment::TAG_ENV)
164
+ self.env = string_tags[Ext::Environment::TAG_ENV]
165
+ end
166
+
167
+ if version.nil? && string_tags.key?(Ext::Environment::TAG_VERSION)
168
+ self.version = string_tags[Ext::Environment::TAG_VERSION]
169
+ end
170
+
171
+ if service.nil? && string_tags.key?(Ext::Environment::TAG_SERVICE)
172
+ self.service = string_tags[Ext::Environment::TAG_SERVICE]
173
+ end
174
+
128
175
  # Merge with previous tags
129
176
  (old_value || {}).merge(string_tags)
130
177
  end
131
178
 
132
- o.on_set { |value| get_option(:tracer).set_tags(value) }
133
-
134
179
  o.lazy
135
180
  end
136
181
 
137
- option :tracer do |o|
138
- o.default { Tracer.new }
139
- o.lazy
182
+ settings :tracer do
183
+ option :enabled, default: true
184
+ option :hostname # TODO: Deprecate
185
+ option :instance
140
186
 
141
- # On reset, shut down the old tracer,
142
- # then instantiate a new one.
143
- o.resetter do |tracer|
144
- tracer.shutdown!
145
- Tracer.new
146
- end
147
-
148
- # Backwards compatibility for configuring tracer e.g. `c.tracer debug: true`
149
- o.helper :tracer do |options = nil|
150
- tracer = options && options.key?(:instance) ? set_option(:tracer, options[:instance]) : get_option(:tracer)
151
-
152
- tracer.tap do |t|
153
- unless options.nil?
154
- t.configure(options)
155
-
156
- if options[:log]
157
- # TODO: Raise deprecation warning
158
- Datadog::Logger.log = options[:log]
159
- end
160
-
161
- if options[:tags]
162
- # TODO: Raise deprecation warning
163
- t.set_tags(options[:tags])
164
- end
165
-
166
- if options[:env]
167
- # TODO: Raise deprecation warning
168
- t.set_tags(env: options[:env])
169
- end
170
-
171
- if options.key?(:debug)
172
- # TODO: Raise deprecation warning
173
- Datadog::Logger.debug_logging = options[:debug]
174
- end
175
- end
176
- end
187
+ settings :partial_flush do
188
+ option :enabled, default: false
189
+ option :min_spans_threshold
177
190
  end
191
+
192
+ option :port # TODO: Deprecate
193
+ option :priority_sampling # TODO: Deprecate
194
+ option :sampler
195
+ option :transport_options, default: ->(_i) { {} }, lazy: true # TODO: Deprecate
196
+ option :writer # TODO: Deprecate
197
+ option :writer_options, default: ->(_i) { {} }, lazy: true # TODO: Deprecate
198
+ end
199
+
200
+ # Backwards compatibility for configuring tracer e.g. `c.tracer debug: true`
201
+ def tracer(options = nil)
202
+ settings = get_option(:tracer)
203
+ return settings if options.nil?
204
+
205
+ # If options were provided (old style) then raise warnings and apply them:
206
+ options = options.dup
207
+
208
+ if options.key?(:log)
209
+ # TODO: Raise deprecation warning
210
+ get_option(:logger).instance = options.delete(:log)
211
+ end
212
+
213
+ if options.key?(:tags)
214
+ # TODO: Raise deprecation warning
215
+ set_option(:tags, options.delete(:tags))
216
+ end
217
+
218
+ if options.key?(:env)
219
+ # TODO: Raise deprecation warning
220
+ set_option(:env, options.delete(:env))
221
+ end
222
+
223
+ if options.key?(:debug)
224
+ # TODO: Raise deprecation warning
225
+ get_option(:diagnostics).debug = options.delete(:debug)
226
+ end
227
+
228
+ if options.key?(:partial_flush)
229
+ # TODO: Raise deprecation warning
230
+ settings.partial_flush.enabled = options.delete(:partial_flush)
231
+ end
232
+
233
+ if options.key?(:min_spans_before_partial_flush)
234
+ # TODO: Raise deprecation warning
235
+ settings.partial_flush.min_spans_threshold = options.delete(:min_spans_before_partial_flush)
236
+ end
237
+
238
+ # Forward remaining options to settings
239
+ options.each do |key, value|
240
+ setter = :"#{key}="
241
+ settings.send(setter, value) if settings.respond_to?(setter)
242
+ end
243
+ end
244
+
245
+ def tracer=(tracer)
246
+ get_option(:tracer).instance = tracer
178
247
  end
179
248
 
180
249
  option :version do |o|
181
250
  o.default { ENV.fetch(Ext::Environment::ENV_VERSION, nil) }
182
251
  o.lazy
183
- o.on_set { |value| get_option(:tracer).set_tags('version' => value) }
184
252
  end
185
253
  end
186
254
  end