ddtrace 1.12.1 → 1.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +129 -9
  3. data/ext/ddtrace_profiling_native_extension/collectors_thread_context.c +97 -14
  4. data/ext/ddtrace_profiling_native_extension/extconf.rb +6 -0
  5. data/ext/ddtrace_profiling_native_extension/http_transport.c +19 -6
  6. data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +1 -1
  7. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +41 -2
  8. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.h +6 -0
  9. data/ext/ddtrace_profiling_native_extension/stack_recorder.c +6 -10
  10. data/ext/ddtrace_profiling_native_extension/time_helpers.c +40 -4
  11. data/ext/ddtrace_profiling_native_extension/time_helpers.h +14 -0
  12. data/lib/datadog/appsec/component.rb +9 -0
  13. data/lib/datadog/appsec/configuration/settings.rb +104 -195
  14. data/lib/datadog/appsec/configuration.rb +0 -79
  15. data/lib/datadog/appsec/contrib/auto_instrument.rb +2 -4
  16. data/lib/datadog/appsec/contrib/devise/event.rb +57 -0
  17. data/lib/datadog/appsec/contrib/devise/ext.rb +13 -0
  18. data/lib/datadog/appsec/contrib/devise/integration.rb +42 -0
  19. data/lib/datadog/appsec/contrib/devise/patcher/authenticatable_patch.rb +76 -0
  20. data/lib/datadog/appsec/contrib/devise/patcher/registration_controller_patch.rb +52 -0
  21. data/lib/datadog/appsec/contrib/devise/patcher.rb +45 -0
  22. data/lib/datadog/appsec/contrib/devise/resource.rb +35 -0
  23. data/lib/datadog/appsec/contrib/devise/tracking.rb +49 -0
  24. data/lib/datadog/appsec/contrib/rack/ext.rb +2 -1
  25. data/lib/datadog/appsec/contrib/rack/reactive/request.rb +1 -1
  26. data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +1 -1
  27. data/lib/datadog/appsec/contrib/rack/reactive/response.rb +1 -1
  28. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +12 -7
  29. data/lib/datadog/appsec/contrib/rails/ext.rb +3 -2
  30. data/lib/datadog/appsec/contrib/rails/framework.rb +1 -3
  31. data/lib/datadog/appsec/contrib/rails/patcher.rb +8 -8
  32. data/lib/datadog/appsec/contrib/rails/reactive/action.rb +1 -1
  33. data/lib/datadog/appsec/contrib/sinatra/ext.rb +2 -1
  34. data/lib/datadog/appsec/contrib/sinatra/framework.rb +1 -3
  35. data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +1 -1
  36. data/lib/datadog/appsec/event.rb +1 -1
  37. data/lib/datadog/appsec/extensions.rb +1 -130
  38. data/lib/datadog/appsec/monitor/reactive/set_user.rb +1 -1
  39. data/lib/datadog/appsec/processor.rb +1 -1
  40. data/lib/datadog/appsec/rate_limiter.rb +1 -1
  41. data/lib/datadog/appsec/remote.rb +1 -1
  42. data/lib/datadog/appsec.rb +1 -2
  43. data/lib/datadog/ci/configuration/settings.rb +6 -8
  44. data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +7 -5
  45. data/lib/datadog/ci/contrib/cucumber/ext.rb +10 -8
  46. data/lib/datadog/ci/contrib/minitest/configuration/settings.rb +35 -0
  47. data/lib/datadog/ci/contrib/minitest/ext.rb +21 -0
  48. data/lib/datadog/ci/contrib/minitest/integration.rb +49 -0
  49. data/lib/datadog/ci/contrib/minitest/patcher.rb +27 -0
  50. data/lib/datadog/ci/contrib/minitest/test_helper.rb +68 -0
  51. data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +7 -5
  52. data/lib/datadog/ci/contrib/rspec/ext.rb +9 -7
  53. data/lib/datadog/ci.rb +1 -0
  54. data/lib/datadog/core/backport.rb +51 -0
  55. data/lib/datadog/core/configuration/agent_settings_resolver.rb +9 -5
  56. data/lib/datadog/core/configuration/base.rb +5 -5
  57. data/lib/datadog/core/configuration/components.rb +6 -1
  58. data/lib/datadog/core/configuration/ext.rb +7 -5
  59. data/lib/datadog/core/configuration/option.rb +269 -19
  60. data/lib/datadog/core/configuration/option_definition.rb +76 -11
  61. data/lib/datadog/core/configuration/options.rb +22 -10
  62. data/lib/datadog/core/configuration/settings.rb +139 -61
  63. data/lib/datadog/core/environment/execution.rb +55 -0
  64. data/lib/datadog/core/environment/ext.rb +13 -11
  65. data/lib/datadog/core/environment/yjit.rb +58 -0
  66. data/lib/datadog/core/git/ext.rb +24 -22
  67. data/lib/datadog/core/logging/ext.rb +3 -1
  68. data/lib/datadog/core/metrics/ext.rb +7 -5
  69. data/lib/datadog/core/remote/client/capabilities.rb +5 -0
  70. data/lib/datadog/core/remote/client.rb +3 -0
  71. data/lib/datadog/core/remote/component.rb +25 -34
  72. data/lib/datadog/core/remote/configuration/content.rb +28 -1
  73. data/lib/datadog/core/remote/configuration/repository.rb +3 -1
  74. data/lib/datadog/core/remote/ext.rb +1 -1
  75. data/lib/datadog/core/remote/negotiation.rb +17 -4
  76. data/lib/datadog/core/runtime/ext.rb +22 -12
  77. data/lib/datadog/core/runtime/metrics.rb +43 -0
  78. data/lib/datadog/core/telemetry/client.rb +12 -2
  79. data/lib/datadog/core/telemetry/emitter.rb +4 -2
  80. data/lib/datadog/core/telemetry/event.rb +19 -4
  81. data/lib/datadog/core/telemetry/ext.rb +4 -1
  82. data/lib/datadog/core/telemetry/heartbeat.rb +2 -4
  83. data/lib/datadog/core/telemetry/http/ext.rb +10 -8
  84. data/lib/datadog/core/telemetry/http/transport.rb +1 -0
  85. data/lib/datadog/core/telemetry/v2/app_client_configuration_change.rb +41 -0
  86. data/lib/datadog/core/telemetry/v2/request.rb +29 -0
  87. data/lib/datadog/core/transport/http/client.rb +1 -1
  88. data/lib/datadog/core/transport/http/config.rb +10 -0
  89. data/lib/datadog/core/utils/duration.rb +52 -0
  90. data/lib/datadog/core/utils/hash.rb +47 -0
  91. data/lib/datadog/core/utils/network.rb +1 -1
  92. data/lib/datadog/core/utils/safe_dup.rb +27 -20
  93. data/lib/datadog/core/utils.rb +1 -1
  94. data/lib/datadog/core/workers/async.rb +2 -2
  95. data/lib/datadog/kit/appsec/events.rb +139 -89
  96. data/lib/datadog/kit/identity.rb +80 -65
  97. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +3 -0
  98. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -0
  99. data/lib/datadog/profiling/collectors/thread_context.rb +9 -2
  100. data/lib/datadog/profiling/component.rb +41 -9
  101. data/lib/datadog/profiling/exporter.rb +5 -1
  102. data/lib/datadog/profiling/flush.rb +9 -2
  103. data/lib/datadog/profiling/http_transport.rb +13 -3
  104. data/lib/datadog/profiling/load_native_extension.rb +7 -1
  105. data/lib/datadog/profiling.rb +11 -1
  106. data/lib/datadog/tracing/component.rb +58 -6
  107. data/lib/datadog/tracing/configuration/dynamic/option.rb +71 -0
  108. data/lib/datadog/tracing/configuration/dynamic.rb +64 -0
  109. data/lib/datadog/tracing/configuration/ext.rb +35 -32
  110. data/lib/datadog/tracing/configuration/http.rb +74 -0
  111. data/lib/datadog/tracing/configuration/settings.rb +106 -92
  112. data/lib/datadog/tracing/contrib/action_cable/configuration/settings.rb +9 -6
  113. data/lib/datadog/tracing/contrib/action_cable/ext.rb +20 -18
  114. data/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb +9 -6
  115. data/lib/datadog/tracing/contrib/action_mailer/ext.rb +20 -18
  116. data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +8 -6
  117. data/lib/datadog/tracing/contrib/action_pack/ext.rb +10 -8
  118. data/lib/datadog/tracing/contrib/action_view/configuration/settings.rb +9 -6
  119. data/lib/datadog/tracing/contrib/action_view/ext.rb +12 -10
  120. data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +13 -7
  121. data/lib/datadog/tracing/contrib/active_job/ext.rb +25 -23
  122. data/lib/datadog/tracing/contrib/active_job/log_injection.rb +1 -1
  123. data/lib/datadog/tracing/contrib/active_job/patcher.rb +1 -1
  124. data/lib/datadog/tracing/contrib/active_model_serializers/configuration/settings.rb +9 -6
  125. data/lib/datadog/tracing/contrib/active_model_serializers/ext.rb +12 -10
  126. data/lib/datadog/tracing/contrib/active_record/configuration/settings.rb +9 -7
  127. data/lib/datadog/tracing/contrib/active_record/events/sql.rb +0 -8
  128. data/lib/datadog/tracing/contrib/active_record/ext.rb +17 -15
  129. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +0 -5
  130. data/lib/datadog/tracing/contrib/active_support/configuration/settings.rb +9 -7
  131. data/lib/datadog/tracing/contrib/active_support/ext.rb +18 -16
  132. data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +14 -7
  133. data/lib/datadog/tracing/contrib/aws/ext.rb +37 -24
  134. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +9 -5
  135. data/lib/datadog/tracing/contrib/concurrent_ruby/configuration/settings.rb +3 -2
  136. data/lib/datadog/tracing/contrib/concurrent_ruby/ext.rb +4 -2
  137. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +14 -7
  138. data/lib/datadog/tracing/contrib/dalli/ext.rb +19 -11
  139. data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +8 -6
  140. data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +13 -7
  141. data/lib/datadog/tracing/contrib/delayed_job/ext.rb +16 -14
  142. data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +14 -7
  143. data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +21 -15
  144. data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +8 -5
  145. data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +16 -9
  146. data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +43 -3
  147. data/lib/datadog/tracing/contrib/ethon/ext.rb +19 -11
  148. data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +0 -5
  149. data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +19 -10
  150. data/lib/datadog/tracing/contrib/excon/ext.rb +16 -8
  151. data/lib/datadog/tracing/contrib/excon/middleware.rb +20 -5
  152. data/lib/datadog/tracing/contrib/ext.rb +23 -1
  153. data/lib/datadog/tracing/contrib/extensions.rb +32 -0
  154. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +20 -10
  155. data/lib/datadog/tracing/contrib/faraday/ext.rb +16 -8
  156. data/lib/datadog/tracing/contrib/faraday/middleware.rb +16 -5
  157. data/lib/datadog/tracing/contrib/grape/configuration/settings.rb +8 -6
  158. data/lib/datadog/tracing/contrib/grape/ext.rb +16 -14
  159. data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +8 -6
  160. data/lib/datadog/tracing/contrib/graphql/ext.rb +7 -5
  161. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +19 -9
  162. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +29 -20
  163. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +21 -20
  164. data/lib/datadog/tracing/contrib/grpc/ext.rb +16 -13
  165. data/lib/datadog/tracing/contrib/grpc/formatting.rb +127 -0
  166. data/lib/datadog/tracing/contrib/hanami/configuration/settings.rb +3 -2
  167. data/lib/datadog/tracing/contrib/hanami/ext.rb +10 -8
  168. data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +4 -7
  169. data/lib/datadog/tracing/contrib/http/configuration/settings.rb +33 -11
  170. data/lib/datadog/tracing/contrib/http/ext.rb +16 -9
  171. data/lib/datadog/tracing/contrib/http/instrumentation.rb +22 -7
  172. data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +33 -11
  173. data/lib/datadog/tracing/contrib/httpclient/ext.rb +17 -9
  174. data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +17 -5
  175. data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +33 -11
  176. data/lib/datadog/tracing/contrib/httprb/ext.rb +16 -9
  177. data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +17 -5
  178. data/lib/datadog/tracing/contrib/kafka/configuration/settings.rb +9 -6
  179. data/lib/datadog/tracing/contrib/kafka/ext.rb +42 -39
  180. data/lib/datadog/tracing/contrib/lograge/configuration/settings.rb +3 -2
  181. data/lib/datadog/tracing/contrib/lograge/ext.rb +3 -1
  182. data/lib/datadog/tracing/contrib/lograge/instrumentation.rb +1 -0
  183. data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +14 -7
  184. data/lib/datadog/tracing/contrib/mongodb/ext.rb +20 -16
  185. data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +9 -5
  186. data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +17 -14
  187. data/lib/datadog/tracing/contrib/mysql2/ext.rb +15 -10
  188. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +9 -5
  189. data/lib/datadog/tracing/contrib/opensearch/configuration/settings.rb +52 -0
  190. data/lib/datadog/tracing/contrib/opensearch/ext.rb +37 -0
  191. data/lib/datadog/tracing/contrib/opensearch/integration.rb +44 -0
  192. data/lib/datadog/tracing/contrib/opensearch/patcher.rb +128 -0
  193. data/lib/datadog/tracing/contrib/opensearch/quantize.rb +81 -0
  194. data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +17 -14
  195. data/lib/datadog/tracing/contrib/pg/ext.rb +22 -19
  196. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +9 -5
  197. data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +14 -7
  198. data/lib/datadog/tracing/contrib/presto/ext.rb +25 -20
  199. data/lib/datadog/tracing/contrib/presto/instrumentation.rb +9 -5
  200. data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +12 -10
  201. data/lib/datadog/tracing/contrib/qless/configuration/settings.rb +12 -8
  202. data/lib/datadog/tracing/contrib/qless/ext.rb +14 -12
  203. data/lib/datadog/tracing/contrib/que/configuration/settings.rb +21 -12
  204. data/lib/datadog/tracing/contrib/racecar/configuration/settings.rb +9 -7
  205. data/lib/datadog/tracing/contrib/racecar/event.rb +0 -5
  206. data/lib/datadog/tracing/contrib/racecar/ext.rb +20 -18
  207. data/lib/datadog/tracing/contrib/rack/configuration/settings.rb +16 -12
  208. data/lib/datadog/tracing/contrib/rack/ext.rb +18 -16
  209. data/lib/datadog/tracing/contrib/rack/header_collection.rb +3 -0
  210. data/lib/datadog/tracing/contrib/rack/header_tagging.rb +53 -0
  211. data/lib/datadog/tracing/contrib/rack/middlewares.rb +8 -49
  212. data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +15 -11
  213. data/lib/datadog/tracing/contrib/rails/ext.rb +7 -5
  214. data/lib/datadog/tracing/contrib/rails/log_injection.rb +7 -10
  215. data/lib/datadog/tracing/contrib/rails/patcher.rb +10 -41
  216. data/lib/datadog/tracing/contrib/rails/railtie.rb +3 -3
  217. data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +12 -9
  218. data/lib/datadog/tracing/contrib/rake/ext.rb +14 -12
  219. data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +17 -9
  220. data/lib/datadog/tracing/contrib/redis/ext.rb +22 -15
  221. data/lib/datadog/tracing/contrib/redis/tags.rb +9 -5
  222. data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +13 -7
  223. data/lib/datadog/tracing/contrib/resque/ext.rb +9 -7
  224. data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +16 -9
  225. data/lib/datadog/tracing/contrib/rest_client/ext.rb +15 -8
  226. data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +20 -5
  227. data/lib/datadog/tracing/contrib/roda/configuration/settings.rb +9 -6
  228. data/lib/datadog/tracing/contrib/semantic_logger/configuration/settings.rb +3 -2
  229. data/lib/datadog/tracing/contrib/semantic_logger/ext.rb +3 -1
  230. data/lib/datadog/tracing/contrib/semantic_logger/instrumentation.rb +1 -0
  231. data/lib/datadog/tracing/contrib/sequel/configuration/settings.rb +9 -6
  232. data/lib/datadog/tracing/contrib/sequel/ext.rb +10 -8
  233. data/lib/datadog/tracing/contrib/sequel/utils.rb +2 -7
  234. data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +14 -8
  235. data/lib/datadog/tracing/contrib/shoryuken/ext.rb +14 -12
  236. data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +18 -11
  237. data/lib/datadog/tracing/contrib/sidekiq/ext.rb +32 -30
  238. data/lib/datadog/tracing/contrib/sinatra/configuration/settings.rb +11 -9
  239. data/lib/datadog/tracing/contrib/sinatra/env.rb +0 -17
  240. data/lib/datadog/tracing/contrib/sinatra/ext.rb +21 -19
  241. data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +3 -14
  242. data/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb +14 -8
  243. data/lib/datadog/tracing/contrib/sneakers/ext.rb +1 -0
  244. data/lib/datadog/tracing/contrib/sneakers/tracer.rb +1 -1
  245. data/lib/datadog/tracing/contrib/span_attribute_schema.rb +74 -10
  246. data/lib/datadog/tracing/contrib/stripe/configuration/settings.rb +9 -6
  247. data/lib/datadog/tracing/contrib/sucker_punch/configuration/settings.rb +9 -6
  248. data/lib/datadog/tracing/contrib/sucker_punch/ext.rb +15 -13
  249. data/lib/datadog/tracing/contrib/utils/database.rb +5 -3
  250. data/lib/datadog/tracing/contrib.rb +1 -0
  251. data/lib/datadog/tracing/correlation.rb +9 -12
  252. data/lib/datadog/tracing/diagnostics/ext.rb +21 -19
  253. data/lib/datadog/tracing/distributed/b3_multi.rb +2 -2
  254. data/lib/datadog/tracing/distributed/b3_single.rb +1 -1
  255. data/lib/datadog/tracing/distributed/trace_context.rb +52 -17
  256. data/lib/datadog/tracing/metadata/ext.rb +9 -6
  257. data/lib/datadog/tracing/remote.rb +78 -0
  258. data/lib/datadog/tracing/sampling/rule_sampler.rb +29 -0
  259. data/lib/datadog/tracing/span_operation.rb +3 -15
  260. data/lib/datadog/tracing/trace_operation.rb +16 -3
  261. data/lib/datadog/tracing/trace_segment.rb +5 -2
  262. data/lib/datadog/tracing/tracer.rb +10 -1
  263. data/lib/ddtrace/transport/ext.rb +15 -9
  264. data/lib/ddtrace/transport/trace_formatter.rb +9 -0
  265. data/lib/ddtrace/version.rb +8 -11
  266. metadata +36 -7
  267. data/lib/datadog/tracing/contrib/sinatra/headers.rb +0 -35
@@ -8,136 +8,7 @@ module Datadog
8
8
  module Extensions
9
9
  # Inject AppSec into global objects.
10
10
  def self.activate!
11
- Core::Configuration::Settings.include(Settings)
12
- end
13
-
14
- # Global Datadog configuration mixin
15
- module Settings
16
- # Exposes AppSec settings through the
17
- # `Datadog.configure {|c| c.appsec._option_ }`
18
- # configuration path.
19
- def appsec
20
- @appsec ||= AppSecAdapter.new(AppSec.settings)
21
- end
22
- end
23
-
24
- # Merges {Datadog::AppSec::Configuration::Settings} and {Datadog::AppSec::Configuration::DSL}
25
- # into a single read/write object.
26
- class AppSecAdapter
27
- def initialize(settings)
28
- @settings = settings
29
- end
30
-
31
- # Writer methods
32
-
33
- def instrument(name, _unused = {})
34
- dsl = AppSec::Configuration::DSL.new
35
- dsl.instrument(name)
36
- @settings.merge(dsl)
37
- end
38
-
39
- def enabled=(arg)
40
- dsl = AppSec::Configuration::DSL.new
41
- dsl.enabled = arg
42
- @settings.merge(dsl)
43
- end
44
-
45
- def ruleset=(arg)
46
- dsl = AppSec::Configuration::DSL.new
47
- dsl.ruleset = arg
48
- @settings.merge(dsl)
49
- end
50
-
51
- def ip_denylist=(arg)
52
- dsl = AppSec::Configuration::DSL.new
53
- dsl.ip_denylist = arg
54
- @settings.merge(dsl)
55
- end
56
-
57
- def user_id_denylist=(arg)
58
- dsl = AppSec::Configuration::DSL.new
59
- dsl.user_id_denylist = arg
60
- @settings.merge(dsl)
61
- end
62
-
63
- def waf_timeout=(arg)
64
- dsl = AppSec::Configuration::DSL.new
65
- dsl.waf_timeout = arg
66
- @settings.merge(dsl)
67
- end
68
-
69
- def waf_debug=(arg)
70
- dsl = AppSec::Configuration::DSL.new
71
- dsl.waf_debug = arg
72
- @settings.merge(dsl)
73
- end
74
-
75
- def trace_rate_limit=(arg)
76
- dsl = AppSec::Configuration::DSL.new
77
- dsl.trace_rate_limit = arg
78
- @settings.merge(dsl)
79
- end
80
-
81
- def obfuscator_key_regex=(arg)
82
- dsl = AppSec::Configuration::DSL.new
83
- dsl.obfuscator_key_regex = arg
84
- @settings.merge(dsl)
85
- end
86
-
87
- def obfuscator_value_regex=(arg)
88
- dsl = AppSec::Configuration::DSL.new
89
- dsl.obfuscator_value_regex = arg
90
- @settings.merge(dsl)
91
- end
92
-
93
- # Reader methods
94
-
95
- def enabled
96
- @settings.enabled
97
- end
98
-
99
- def ruleset
100
- @settings.ruleset
101
- end
102
-
103
- def ip_denylist
104
- @settings.ip_denylist
105
- end
106
-
107
- def user_id_denylist
108
- @settings.user_id_denylist
109
- end
110
-
111
- def waf_timeout
112
- @settings.waf_timeout
113
- end
114
-
115
- def waf_debug
116
- @settings.waf_debug
117
- end
118
-
119
- def trace_rate_limit
120
- @settings.trace_rate_limit
121
- end
122
-
123
- def obfuscator_key_regex
124
- @settings.obfuscator_key_regex
125
- end
126
-
127
- def obfuscator_value_regex
128
- @settings.obfuscator_key_regex
129
- end
130
-
131
- def merge(arg)
132
- @settings.merge(arg)
133
- end
134
-
135
- private
136
-
137
- # Restore to original state, for testing only.
138
- def reset!
139
- @settings.send(:reset!)
140
- end
11
+ Core::Configuration::Settings.extend(Configuration::Settings)
141
12
  end
142
13
  end
143
14
  end
@@ -29,7 +29,7 @@ module Datadog
29
29
  'usr.id' => user_id,
30
30
  }
31
31
 
32
- waf_timeout = Datadog::AppSec.settings.waf_timeout
32
+ waf_timeout = Datadog.configuration.appsec.waf_timeout
33
33
  result = waf_context.run(waf_args, waf_timeout)
34
34
 
35
35
  Datadog.logger.debug { "WAF TIMEOUT: #{result.inspect}" } if result.timeout
@@ -48,7 +48,7 @@ module Datadog
48
48
  def initialize(ruleset:)
49
49
  @ruleset_info = nil
50
50
  @addresses = []
51
- settings = Datadog::AppSec.settings
51
+ settings = Datadog.configuration.appsec
52
52
 
53
53
  unless load_libddwaf && create_waf_handle(settings, ruleset)
54
54
  Datadog.logger.warn { 'AppSec is disabled, see logged errors above' }
@@ -50,7 +50,7 @@ module Datadog
50
50
  end
51
51
 
52
52
  def trace_rate_limit
53
- Datadog::AppSec.settings.trace_rate_limit
53
+ Datadog.configuration.appsec.trace_rate_limit
54
54
  end
55
55
  end
56
56
  end
@@ -105,7 +105,7 @@ module Datadog
105
105
  private
106
106
 
107
107
  def remote_features_enabled?
108
- Datadog::AppSec.send(:default_setting?, :ruleset)
108
+ Datadog.configuration.appsec.using_default?(:ruleset)
109
109
  end
110
110
 
111
111
  def parse_content(content)
@@ -8,8 +8,6 @@ require_relative 'appsec/ext'
8
8
  module Datadog
9
9
  # Namespace for Datadog AppSec instrumentation
10
10
  module AppSec
11
- include Configuration
12
-
13
11
  class << self
14
12
  def enabled?
15
13
  Datadog.configuration.appsec.enabled
@@ -57,5 +55,6 @@ end
57
55
  require_relative 'appsec/contrib/rack/integration'
58
56
  require_relative 'appsec/contrib/sinatra/integration'
59
57
  require_relative 'appsec/contrib/rails/integration'
58
+ require_relative 'appsec/contrib/devise/integration'
60
59
 
61
60
  require_relative 'appsec/autoload'
@@ -16,8 +16,9 @@ module Datadog
16
16
  base.class_eval do
17
17
  settings :ci do
18
18
  option :enabled do |o|
19
- o.default { env_to_bool(CI::Ext::Settings::ENV_MODE_ENABLED, false) }
20
- o.lazy
19
+ o.type :bool
20
+ o.env CI::Ext::Settings::ENV_MODE_ENABLED
21
+ o.default false
21
22
  end
22
23
 
23
24
  # DEV: Alias to Datadog::Tracing::Contrib::Extensions::Configuration::Settings#instrument.
@@ -35,14 +36,11 @@ module Datadog
35
36
  # TODO: Deprecate in the next major version, as `instrument` better describes this method's purpose
36
37
  alias_method :use, :instrument
37
38
 
38
- option :trace_flush do |o|
39
- o.default { nil }
40
- o.lazy
41
- end
39
+ option :trace_flush
42
40
 
43
41
  option :writer_options do |o|
44
- o.default { {} }
45
- o.lazy
42
+ o.type :hash
43
+ o.default({})
46
44
  end
47
45
  end
48
46
  end
@@ -12,18 +12,20 @@ module Datadog
12
12
  # TODO: mark as `@public_api` when GA
13
13
  class Settings < Datadog::Tracing::Contrib::Configuration::Settings
14
14
  option :enabled do |o|
15
- o.default { env_to_bool(Ext::ENV_ENABLED, true) }
16
- o.lazy
15
+ o.type :bool
16
+ o.env Ext::ENV_ENABLED
17
+ o.default true
17
18
  end
18
19
 
19
20
  option :service_name do |o|
21
+ o.type :string
20
22
  o.default { Datadog.configuration.service_without_fallback || Ext::SERVICE_NAME }
21
- o.lazy
22
23
  end
23
24
 
24
25
  option :operation_name do |o|
25
- o.default { ENV.key?(Ext::ENV_OPERATION_NAME) ? ENV[Ext::ENV_OPERATION_NAME] : Ext::OPERATION_NAME }
26
- o.lazy
26
+ o.type :string
27
+ o.env Ext::ENV_OPERATION_NAME
28
+ o.default Ext::OPERATION_NAME
27
29
  end
28
30
  end
29
31
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module CI
3
5
  module Contrib
@@ -5,14 +7,14 @@ module Datadog
5
7
  # Cucumber integration constants
6
8
  # TODO: mark as `@public_api` when GA, to protect from resource and tag name changes.
7
9
  module Ext
8
- APP = 'cucumber'.freeze
9
- ENV_ENABLED = 'DD_TRACE_CUCUMBER_ENABLED'.freeze
10
- ENV_OPERATION_NAME = 'DD_TRACE_CUCUMBER_OPERATION_NAME'.freeze
11
- FRAMEWORK = 'cucumber'.freeze
12
- OPERATION_NAME = 'cucumber.test'.freeze
13
- SERVICE_NAME = 'cucumber'.freeze
14
- STEP_SPAN_TYPE = 'step'.freeze
15
- TEST_TYPE = 'test'.freeze
10
+ APP = 'cucumber'
11
+ ENV_ENABLED = 'DD_TRACE_CUCUMBER_ENABLED'
12
+ ENV_OPERATION_NAME = 'DD_TRACE_CUCUMBER_OPERATION_NAME'
13
+ FRAMEWORK = 'cucumber'
14
+ OPERATION_NAME = 'cucumber.test'
15
+ SERVICE_NAME = 'cucumber'
16
+ STEP_SPAN_TYPE = 'step'
17
+ TEST_TYPE = 'test'
16
18
  end
17
19
  end
18
20
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../tracing/contrib/configuration/settings'
4
+ require_relative '../ext'
5
+
6
+ module Datadog
7
+ module CI
8
+ module Contrib
9
+ module Minitest
10
+ module Configuration
11
+ # Custom settings for the Minitest integration
12
+ # TODO: mark as `@public_api` when GA
13
+ class Settings < Datadog::Tracing::Contrib::Configuration::Settings
14
+ option :enabled do |o|
15
+ o.type :bool
16
+ o.env Ext::ENV_ENABLED
17
+ o.default true
18
+ end
19
+
20
+ option :service_name do |o|
21
+ o.type :string
22
+ o.default { Datadog.configuration.service_without_fallback || Ext::SERVICE_NAME }
23
+ end
24
+
25
+ option :operation_name do |o|
26
+ o.type :string
27
+ o.env Ext::ENV_OPERATION_NAME
28
+ o.default Ext::OPERATION_NAME
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datadog
4
+ module CI
5
+ module Contrib
6
+ module Minitest
7
+ # Minitest integration constants
8
+ # TODO: mark as `@public_api` when GA, to protect from resource and tag name changes.
9
+ module Ext
10
+ APP = 'minitest'
11
+ ENV_ENABLED = 'DD_TRACE_MINITEST_ENABLED'
12
+ ENV_OPERATION_NAME = 'DD_TRACE_MINITEST_OPERATION_NAME'
13
+ FRAMEWORK = 'minitest'
14
+ OPERATION_NAME = 'minitest.test'
15
+ SERVICE_NAME = 'minitest'
16
+ TEST_TYPE = 'test'
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../tracing/contrib/integration'
4
+
5
+ require_relative 'configuration/settings'
6
+ require_relative 'patcher'
7
+
8
+ module Datadog
9
+ module CI
10
+ module Contrib
11
+ module Minitest
12
+ # Description of Minitest integration
13
+ class Integration
14
+ include Datadog::Tracing::Contrib::Integration
15
+
16
+ MINIMUM_VERSION = Gem::Version.new('5.0.0')
17
+
18
+ register_as :minitest, auto_patch: true
19
+
20
+ def self.version
21
+ Gem.loaded_specs['minitest'] \
22
+ && Gem.loaded_specs['minitest'].version
23
+ end
24
+
25
+ def self.loaded?
26
+ !defined?(::Minitest).nil?
27
+ end
28
+
29
+ def self.compatible?
30
+ super && version >= MINIMUM_VERSION
31
+ end
32
+
33
+ # test environments should not auto instrument test libraries
34
+ def auto_instrument?
35
+ false
36
+ end
37
+
38
+ def new_configuration
39
+ Configuration::Settings.new
40
+ end
41
+
42
+ def patcher
43
+ Patcher
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../tracing/contrib/patcher'
4
+ require_relative 'test_helper'
5
+
6
+ module Datadog
7
+ module CI
8
+ module Contrib
9
+ module Minitest
10
+ # Patcher enables patching of 'minitest' module.
11
+ module Patcher
12
+ include Datadog::Tracing::Contrib::Patcher
13
+
14
+ module_function
15
+
16
+ def target_version
17
+ Integration.version
18
+ end
19
+
20
+ def patch
21
+ ::Minitest::Test.include(TestHelper)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'ext'
4
+
5
+ module Datadog
6
+ module CI
7
+ module Contrib
8
+ module Minitest
9
+ # Instrument Minitest::Test
10
+ module TestHelper
11
+ def before_setup
12
+ super
13
+ return unless configuration[:enabled]
14
+
15
+ test_name = "#{class_name}##{name}"
16
+
17
+ path, = method(name).source_location
18
+ test_suite = Pathname.new(path).relative_path_from(Pathname.pwd).to_s
19
+
20
+ span = CI::Test.trace(
21
+ configuration[:operation_name],
22
+ {
23
+ span_options: {
24
+ resource: test_name,
25
+ service: configuration[:service_name],
26
+ },
27
+ framework: Ext::FRAMEWORK,
28
+ framework_version: CI::Contrib::Minitest::Integration.version.to_s,
29
+ test_name: test_name,
30
+ test_suite: test_suite,
31
+ test_type: Ext::TEST_TYPE,
32
+ },
33
+ )
34
+
35
+ Thread.current[:_datadog_test_span] = span
36
+ end
37
+
38
+ def after_teardown
39
+ span = Thread.current[:_datadog_test_span]
40
+ return super unless span
41
+
42
+ Thread.current[:_datadog_test_span] = nil
43
+
44
+ case result_code
45
+ when '.'
46
+ CI::Test.passed!(span)
47
+ when 'E', 'F'
48
+ CI::Test.failed!(span, failure)
49
+ when 'S'
50
+ CI::Test.skipped!(span)
51
+ span.set_tag(CI::Ext::Test::TAG_SKIP_REASON, failure.message)
52
+ end
53
+
54
+ span.finish
55
+
56
+ super
57
+ end
58
+
59
+ private
60
+
61
+ def configuration
62
+ ::Datadog.configuration.ci[:minitest]
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -12,18 +12,20 @@ module Datadog
12
12
  # TODO: mark as `@public_api` when GA
13
13
  class Settings < Datadog::Tracing::Contrib::Configuration::Settings
14
14
  option :enabled do |o|
15
- o.default { env_to_bool(Ext::ENV_ENABLED, true) }
16
- o.lazy
15
+ o.type :bool
16
+ o.env Ext::ENV_ENABLED
17
+ o.default true
17
18
  end
18
19
 
19
20
  option :service_name do |o|
21
+ o.type :string
20
22
  o.default { Datadog.configuration.service_without_fallback || Ext::SERVICE_NAME }
21
- o.lazy
22
23
  end
23
24
 
24
25
  option :operation_name do |o|
25
- o.default { ENV.key?(Ext::ENV_OPERATION_NAME) ? ENV[Ext::ENV_OPERATION_NAME] : Ext::OPERATION_NAME }
26
- o.lazy
26
+ o.type :string
27
+ o.env Ext::ENV_OPERATION_NAME
28
+ o.default Ext::OPERATION_NAME
27
29
  end
28
30
  end
29
31
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module CI
3
5
  module Contrib
@@ -5,13 +7,13 @@ module Datadog
5
7
  # RSpec integration constants
6
8
  # TODO: mark as `@public_api` when GA, to protect from resource and tag name changes.
7
9
  module Ext
8
- APP = 'rspec'.freeze
9
- ENV_ENABLED = 'DD_TRACE_RSPEC_ENABLED'.freeze
10
- ENV_OPERATION_NAME = 'DD_TRACE_RSPEC_OPERATION_NAME'.freeze
11
- FRAMEWORK = 'rspec'.freeze
12
- OPERATION_NAME = 'rspec.example'.freeze
13
- SERVICE_NAME = 'rspec'.freeze
14
- TEST_TYPE = 'test'.freeze
10
+ APP = 'rspec'
11
+ ENV_ENABLED = 'DD_TRACE_RSPEC_ENABLED'
12
+ ENV_OPERATION_NAME = 'DD_TRACE_RSPEC_OPERATION_NAME'
13
+ FRAMEWORK = 'rspec'
14
+ OPERATION_NAME = 'rspec.example'
15
+ SERVICE_NAME = 'rspec'
16
+ TEST_TYPE = 'test'
15
17
  end
16
18
  end
17
19
  end
data/lib/datadog/ci.rb CHANGED
@@ -14,6 +14,7 @@ end
14
14
  # Integrations
15
15
  require_relative 'ci/contrib/cucumber/integration'
16
16
  require_relative 'ci/contrib/rspec/integration'
17
+ require_relative 'ci/contrib/minitest/integration'
17
18
 
18
19
  # Extensions
19
20
  require_relative 'ci/extensions'
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datadog
4
+ module Core
5
+ # This module is used to provide features from Ruby 2.5+ to older Rubies
6
+ module BackportFrom25
7
+ if ::String.method_defined?(:delete_prefix)
8
+ def self.string_delete_prefix(string, prefix)
9
+ string.delete_prefix(prefix)
10
+ end
11
+ else
12
+ def self.string_delete_prefix(string, prefix)
13
+ prefix = prefix.to_s
14
+ if string.start_with?(prefix)
15
+ string[prefix.length..-1] || raise('rbs-guard: String#[] is non-nil as `prefix` is guaranteed present')
16
+ else
17
+ string.dup
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ # This module is used to provide features from Ruby 2.4+ to older Rubies
24
+ module BackportFrom24
25
+ if RUBY_VERSION < '2.4'
26
+ def self.dup(value)
27
+ case value
28
+ when NilClass, TrueClass, FalseClass, Numeric
29
+ value
30
+ else
31
+ value.dup
32
+ end
33
+ end
34
+ else
35
+ def self.dup(value)
36
+ value.dup
37
+ end
38
+ end
39
+
40
+ if ::Hash.method_defined?(:compact!)
41
+ def self.hash_compact!(hash)
42
+ hash.compact!
43
+ end
44
+ else
45
+ def self.hash_compact!(hash)
46
+ hash.reject! { |_key, value| value.nil? }
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -95,7 +95,7 @@ module Datadog
95
95
  end
96
96
 
97
97
  def adapter
98
- if should_use_uds? && !mixed_http_and_uds?
98
+ if should_use_uds?
99
99
  Datadog::Transport::Ext::UnixSocket::ADAPTER
100
100
  else
101
101
  Datadog::Transport::Ext::HTTP::ADAPTER
@@ -222,6 +222,10 @@ module Datadog
222
222
  end
223
223
 
224
224
  def should_use_uds?
225
+ can_use_uds? && !mixed_http_and_uds?
226
+ end
227
+
228
+ def can_use_uds?
225
229
  parsed_url && unix_scheme?(parsed_url) ||
226
230
  # If no agent settings have been provided, we try to connect using a local unix socket.
227
231
  # We only do so if the socket is present when `ddtrace` runs.
@@ -272,7 +276,7 @@ module Datadog
272
276
  'Configuration mismatch: values differ between ' \
273
277
  "#{detected_configurations_in_priority_order
274
278
  .map { |config| "#{config.friendly_name} (#{config.value.inspect})" }.join(' and ')}" \
275
- ". Using #{detected_configurations_in_priority_order.first.value.inspect}."
279
+ ". Using #{detected_configurations_in_priority_order.first.value.inspect} and ignoring other configuration."
276
280
  )
277
281
  end
278
282
 
@@ -297,18 +301,18 @@ module Datadog
297
301
  def mixed_http_and_uds?
298
302
  return @mixed_http_and_uds if defined?(@mixed_http_and_uds)
299
303
 
300
- @mixed_http_and_uds = (configured_hostname || configured_port) && should_use_uds?
304
+ @mixed_http_and_uds = (configured_hostname || configured_port) && can_use_uds?
301
305
 
302
306
  if @mixed_http_and_uds
303
307
  warn_if_configuration_mismatch(
304
308
  [
305
309
  DetectedConfiguration.new(
306
310
  friendly_name: 'configuration of hostname/port for http/https use',
307
- value: "hostname: '#{configured_hostname}', port: #{configured_port.inspect}",
311
+ value: "hostname: '#{hostname}', port: '#{port}'",
308
312
  ),
309
313
  DetectedConfiguration.new(
310
314
  friendly_name: 'configuration for unix domain socket',
311
- value: "unix://#{uds_path}",
315
+ value: parsed_url.to_s,
312
316
  ),
313
317
  ]
314
318
  )
@@ -25,25 +25,25 @@ module Datadog
25
25
  # e.g. `settings :foo { option :bar }` --> `config.foo.bar`
26
26
  # @param [Symbol] name option name. Methods will be created based on this name.
27
27
  def settings(name, &block)
28
- settings_class = new_settings_class(&block)
28
+ settings_class = new_settings_class(name, &block)
29
29
 
30
30
  option(name) do |o|
31
31
  o.default { settings_class.new }
32
- o.lazy
33
32
 
34
33
  o.resetter do |value|
35
34
  value.reset! if value.respond_to?(:reset!)
36
35
  value
37
36
  end
38
-
39
- o.type settings_class
40
37
  end
38
+
39
+ settings_class
41
40
  end
42
41
 
43
42
  private
44
43
 
45
- def new_settings_class(&block)
44
+ def new_settings_class(name, &block)
46
45
  Class.new { include Configuration::Base }.tap do |klass|
46
+ klass.instance_variable_set(:@settings_name, name)
47
47
  klass.instance_eval(&block) if block
48
48
  end
49
49
  end