datadog 2.48.0 → 2.49.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 (277) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -1
  3. data/ext/datadog_profiling_native_extension/collectors_stack.c +1 -1
  4. data/ext/datadog_profiling_native_extension/collectors_stack.h +4 -2
  5. data/ext/datadog_profiling_native_extension/extconf.rb +3 -0
  6. data/ext/datadog_profiling_native_extension/private_vm_api_access.c +13 -21
  7. data/ext/libdatadog_api/extconf.rb +2 -0
  8. data/ext/libdatadog_api/feature_flags.c +137 -0
  9. data/ext/libdatadog_api/process_discovery.c +3 -3
  10. data/ext/libdatadog_extconf_helpers.rb +1 -1
  11. data/lib/datadog/ai_guard/contrib/rack/patcher.rb +3 -5
  12. data/lib/datadog/ai_guard/contrib/rails/patcher.rb +7 -9
  13. data/lib/datadog/ai_guard/contrib/ruby_llm/patcher.rb +3 -5
  14. data/lib/datadog/ai_guard/metrics/telemetry.rb +2 -4
  15. data/lib/datadog/appsec/actions_handler.rb +5 -7
  16. data/lib/datadog/appsec/api_security/endpoint_collection/grape_route_serializer.rb +1 -3
  17. data/lib/datadog/appsec/api_security/endpoint_collection/rails_route_serializer.rb +1 -3
  18. data/lib/datadog/appsec/api_security/endpoint_collection/sinatra_route_serializer.rb +1 -3
  19. data/lib/datadog/appsec/assets.rb +8 -10
  20. data/lib/datadog/appsec/configuration.rb +1 -1
  21. data/lib/datadog/appsec/context.rb +63 -6
  22. data/lib/datadog/appsec/contrib/active_record/instrumentation.rb +1 -3
  23. data/lib/datadog/appsec/contrib/active_record/patcher.rb +21 -24
  24. data/lib/datadog/appsec/contrib/aws_lambda/patcher.rb +3 -5
  25. data/lib/datadog/appsec/contrib/aws_lambda/waf_addresses.rb +9 -11
  26. data/lib/datadog/appsec/contrib/devise/configuration.rb +2 -4
  27. data/lib/datadog/appsec/contrib/devise/patcher.rb +3 -5
  28. data/lib/datadog/appsec/contrib/excon/patcher.rb +3 -5
  29. data/lib/datadog/appsec/contrib/faraday/patcher.rb +4 -6
  30. data/lib/datadog/appsec/contrib/graphql/patcher.rb +3 -5
  31. data/lib/datadog/appsec/contrib/rack/input_peeker.rb +3 -5
  32. data/lib/datadog/appsec/contrib/rack/patcher.rb +3 -5
  33. data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +5 -4
  34. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +6 -7
  35. data/lib/datadog/appsec/contrib/rails/patcher.rb +19 -16
  36. data/lib/datadog/appsec/contrib/rails/patches/live_thread_patch.rb +33 -0
  37. data/lib/datadog/appsec/contrib/rest_client/patcher.rb +3 -5
  38. data/lib/datadog/appsec/contrib/sinatra/patcher.rb +4 -6
  39. data/lib/datadog/appsec/default_header_tags.rb +2 -4
  40. data/lib/datadog/appsec/metrics/exporter.rb +4 -6
  41. data/lib/datadog/appsec/metrics/telemetry.rb +1 -3
  42. data/lib/datadog/appsec/metrics/telemetry_exporter.rb +2 -4
  43. data/lib/datadog/appsec/route_normalizer/route_text.rb +1 -3
  44. data/lib/datadog/appsec/route_normalizer.rb +4 -6
  45. data/lib/datadog/appsec/utils/http/body_reader.rb +3 -5
  46. data/lib/datadog/appsec/utils/http/url_encoded.rb +2 -4
  47. data/lib/datadog/core/borrowing_token_bucket.rb +60 -0
  48. data/lib/datadog/core/chunker.rb +1 -3
  49. data/lib/datadog/core/configuration/components.rb +48 -17
  50. data/lib/datadog/core/configuration/settings.rb +2 -1
  51. data/lib/datadog/core/configuration/supported_configurations.rb +2 -0
  52. data/lib/datadog/core/diagnostics/environment_logger.rb +1 -6
  53. data/lib/datadog/core/encoding.rb +8 -12
  54. data/lib/datadog/core/environment/cgroup.rb +3 -5
  55. data/lib/datadog/core/environment/container.rb +9 -11
  56. data/lib/datadog/core/environment/ext.rb +1 -6
  57. data/lib/datadog/core/environment/gc.rb +2 -4
  58. data/lib/datadog/core/environment/identity.rb +13 -15
  59. data/lib/datadog/core/environment/platform.rb +10 -12
  60. data/lib/datadog/core/environment/socket.rb +3 -5
  61. data/lib/datadog/core/environment/thread_count.rb +2 -4
  62. data/lib/datadog/core/environment/variable_helpers.rb +2 -6
  63. data/lib/datadog/core/environment/vm_cache.rb +5 -7
  64. data/lib/datadog/core/environment/yjit.rb +25 -24
  65. data/lib/datadog/core/logger.rb +5 -2
  66. data/lib/datadog/core/metrics/client.rb +8 -16
  67. data/lib/datadog/core/metrics/helpers.rb +3 -0
  68. data/lib/datadog/core/metrics/metric.rb +3 -1
  69. data/lib/datadog/core/rate_limiter.rb +9 -31
  70. data/lib/datadog/core/refillable_bucket.rb +72 -0
  71. data/lib/datadog/core/remote/client/capabilities.rb +4 -0
  72. data/lib/datadog/core/remote/client.rb +1 -5
  73. data/lib/datadog/core/remote/transport/http.rb +2 -4
  74. data/lib/datadog/core/tag_normalizer.rb +0 -2
  75. data/lib/datadog/core/telemetry/configuration_value.rb +1 -3
  76. data/lib/datadog/core/telemetry/transport/http.rb +2 -4
  77. data/lib/datadog/core/telemetry/worker.rb +30 -24
  78. data/lib/datadog/core/transport/http.rb +2 -4
  79. data/lib/datadog/core/utils/at_fork_monkey_patch.rb +2 -2
  80. data/lib/datadog/core/utils/forking.rb +1 -1
  81. data/lib/datadog/core/utils/lru_cache.rb +2 -2
  82. data/lib/datadog/core/utils/network.rb +1 -1
  83. data/lib/datadog/core/utils/time.rb +2 -2
  84. data/lib/datadog/core/utils/truncation.rb +1 -3
  85. data/lib/datadog/core/workers/async.rb +16 -14
  86. data/lib/datadog/core/workers/runtime_metrics.rb +1 -1
  87. data/lib/datadog/data_streams/transport/http.rb +1 -3
  88. data/lib/datadog/di/component.rb +14 -2
  89. data/lib/datadog/di/context.rb +50 -0
  90. data/lib/datadog/di/contrib.rb +2 -2
  91. data/lib/datadog/di/correlation_sampler/trace_budget.rb +75 -0
  92. data/lib/datadog/di/correlation_sampler/trace_budget_ledger/entry.rb +34 -0
  93. data/lib/datadog/di/correlation_sampler/trace_budget_ledger.rb +104 -0
  94. data/lib/datadog/di/correlation_sampler.rb +224 -0
  95. data/lib/datadog/di/guardrails_telemetry/reason.rb +8 -3
  96. data/lib/datadog/di/instrumenter.rb +294 -109
  97. data/lib/datadog/di/probe.rb +13 -2
  98. data/lib/datadog/di/probe_builder.rb +6 -8
  99. data/lib/datadog/di/probe_file_loader.rb +2 -2
  100. data/lib/datadog/di/probe_manager.rb +7 -30
  101. data/lib/datadog/di/probe_notification_builder.rb +42 -11
  102. data/lib/datadog/di/probe_notifier_worker.rb +11 -0
  103. data/lib/datadog/di/snapshot_pruner/node.rb +190 -0
  104. data/lib/datadog/di/snapshot_pruner/node_queue.rb +104 -0
  105. data/lib/datadog/di/snapshot_pruner/parser.rb +102 -0
  106. data/lib/datadog/di/snapshot_pruner.rb +128 -0
  107. data/lib/datadog/di/transport/input.rb +75 -15
  108. data/lib/datadog/di/utils.rb +3 -3
  109. data/lib/datadog/di.rb +29 -0
  110. data/lib/datadog/error_tracking/filters.rb +6 -8
  111. data/lib/datadog/open_feature/agentless/parser.rb +2 -4
  112. data/lib/datadog/open_feature/component.rb +24 -2
  113. data/lib/datadog/open_feature/configuration.rb +13 -0
  114. data/lib/datadog/open_feature/evaluation_engine.rb +5 -5
  115. data/lib/datadog/open_feature/exposure_hook.rb +146 -0
  116. data/lib/datadog/open_feature/exposures/event.rb +10 -8
  117. data/lib/datadog/open_feature/exposures/reporter.rb +34 -25
  118. data/lib/datadog/open_feature/ext.rb +12 -0
  119. data/lib/datadog/open_feature/flag_evaluation/aggregator.rb +10 -8
  120. data/lib/datadog/open_feature/flag_evaluation/writer.rb +9 -6
  121. data/lib/datadog/open_feature/hooks/exposure_logging_hook.rb +58 -0
  122. data/lib/datadog/open_feature/hooks/flag_eval_evp_hook.rb +4 -2
  123. data/lib/datadog/open_feature/hooks/flag_eval_metrics_hook.rb +3 -5
  124. data/lib/datadog/open_feature/hooks/span_enrichment_hook/codec.rb +3 -5
  125. data/lib/datadog/open_feature/native_evaluator.rb +30 -2
  126. data/lib/datadog/open_feature/noop_evaluator.rb +3 -1
  127. data/lib/datadog/open_feature/provider.rb +54 -4
  128. data/lib/datadog/open_feature/resolution_details.rb +1 -0
  129. data/lib/datadog/open_feature/split_features.rb +76 -0
  130. data/lib/datadog/opentelemetry/sdk/propagator.rb +5 -2
  131. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +28 -31
  132. data/lib/datadog/profiling/component.rb +31 -9
  133. data/lib/datadog/profiling/profiler.rb +6 -0
  134. data/lib/datadog/profiling/remote.rb +381 -0
  135. data/lib/datadog/profiling/worker_state.rb +65 -0
  136. data/lib/datadog/profiling.rb +1 -0
  137. data/lib/datadog/symbol_database/file_hash.rb +1 -3
  138. data/lib/datadog/tracing/component.rb +14 -16
  139. data/lib/datadog/tracing/configuration/settings.rb +2 -2
  140. data/lib/datadog/tracing/contrib/action_cable/events/broadcast.rb +4 -6
  141. data/lib/datadog/tracing/contrib/action_cable/events/perform_action.rb +4 -6
  142. data/lib/datadog/tracing/contrib/action_cable/events/transmit.rb +4 -6
  143. data/lib/datadog/tracing/contrib/action_cable/events.rb +3 -5
  144. data/lib/datadog/tracing/contrib/action_cable/patcher.rb +2 -4
  145. data/lib/datadog/tracing/contrib/action_mailer/events/deliver.rb +5 -7
  146. data/lib/datadog/tracing/contrib/action_mailer/events/process.rb +4 -6
  147. data/lib/datadog/tracing/contrib/action_mailer/events.rb +3 -5
  148. data/lib/datadog/tracing/contrib/action_mailer/patcher.rb +2 -4
  149. data/lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb +2 -4
  150. data/lib/datadog/tracing/contrib/action_pack/action_controller/patcher.rb +2 -4
  151. data/lib/datadog/tracing/contrib/action_pack/action_dispatch/instrumentation.rb +2 -4
  152. data/lib/datadog/tracing/contrib/action_pack/action_dispatch/patcher.rb +2 -4
  153. data/lib/datadog/tracing/contrib/action_pack/patcher.rb +2 -4
  154. data/lib/datadog/tracing/contrib/action_view/events/render_partial.rb +3 -5
  155. data/lib/datadog/tracing/contrib/action_view/events/render_template.rb +3 -5
  156. data/lib/datadog/tracing/contrib/action_view/events.rb +3 -5
  157. data/lib/datadog/tracing/contrib/action_view/patcher.rb +3 -5
  158. data/lib/datadog/tracing/contrib/action_view/utils.rb +1 -3
  159. data/lib/datadog/tracing/contrib/active_job/events/discard.rb +3 -5
  160. data/lib/datadog/tracing/contrib/active_job/events/enqueue.rb +3 -5
  161. data/lib/datadog/tracing/contrib/active_job/events/enqueue_at.rb +3 -5
  162. data/lib/datadog/tracing/contrib/active_job/events/enqueue_retry.rb +3 -5
  163. data/lib/datadog/tracing/contrib/active_job/events/perform.rb +3 -5
  164. data/lib/datadog/tracing/contrib/active_job/events/retry_stopped.rb +3 -5
  165. data/lib/datadog/tracing/contrib/active_job/events.rb +3 -5
  166. data/lib/datadog/tracing/contrib/active_job/patcher.rb +4 -6
  167. data/lib/datadog/tracing/contrib/active_model_serializers/events/render.rb +4 -6
  168. data/lib/datadog/tracing/contrib/active_model_serializers/events/serialize.rb +4 -6
  169. data/lib/datadog/tracing/contrib/active_model_serializers/events.rb +3 -5
  170. data/lib/datadog/tracing/contrib/active_model_serializers/patcher.rb +3 -5
  171. data/lib/datadog/tracing/contrib/active_record/events/instantiation.rb +4 -6
  172. data/lib/datadog/tracing/contrib/active_record/events/sql.rb +3 -5
  173. data/lib/datadog/tracing/contrib/active_record/events.rb +3 -5
  174. data/lib/datadog/tracing/contrib/active_record/patcher.rb +2 -4
  175. data/lib/datadog/tracing/contrib/active_support/cache/events/cache.rb +8 -10
  176. data/lib/datadog/tracing/contrib/active_support/cache/events.rb +3 -5
  177. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +5 -7
  178. data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +4 -6
  179. data/lib/datadog/tracing/contrib/active_support/patcher.rb +2 -4
  180. data/lib/datadog/tracing/contrib/analytics.rb +4 -6
  181. data/lib/datadog/tracing/contrib/aws/patcher.rb +5 -7
  182. data/lib/datadog/tracing/contrib/concurrent_ruby/patcher.rb +5 -7
  183. data/lib/datadog/tracing/contrib/configuration/settings.rb +17 -0
  184. data/lib/datadog/tracing/contrib/dalli/patcher.rb +2 -4
  185. data/lib/datadog/tracing/contrib/dalli/quantize.rb +1 -3
  186. data/lib/datadog/tracing/contrib/delayed_job/patcher.rb +4 -6
  187. data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +3 -5
  188. data/lib/datadog/tracing/contrib/elasticsearch/quantize.rb +6 -8
  189. data/lib/datadog/tracing/contrib/ethon/patcher.rb +2 -4
  190. data/lib/datadog/tracing/contrib/excon/patcher.rb +3 -5
  191. data/lib/datadog/tracing/contrib/faraday/patcher.rb +4 -6
  192. data/lib/datadog/tracing/contrib/grape/patcher.rb +2 -4
  193. data/lib/datadog/tracing/contrib/graphql/patcher.rb +4 -6
  194. data/lib/datadog/tracing/contrib/graphql/trace_patcher.rb +1 -3
  195. data/lib/datadog/tracing/contrib/graphql/tracing_patcher.rb +1 -3
  196. data/lib/datadog/tracing/contrib/graphql/unified_trace_patcher.rb +1 -3
  197. data/lib/datadog/tracing/contrib/grpc/patcher.rb +3 -5
  198. data/lib/datadog/tracing/contrib/hanami/patcher.rb +2 -4
  199. data/lib/datadog/tracing/contrib/http/patcher.rb +2 -4
  200. data/lib/datadog/tracing/contrib/httpclient/patcher.rb +2 -4
  201. data/lib/datadog/tracing/contrib/httprb/patcher.rb +2 -4
  202. data/lib/datadog/tracing/contrib/kafka/events/connection/request.rb +4 -6
  203. data/lib/datadog/tracing/contrib/kafka/events/consumer/process_batch.rb +3 -5
  204. data/lib/datadog/tracing/contrib/kafka/events/consumer/process_message.rb +3 -5
  205. data/lib/datadog/tracing/contrib/kafka/events/consumer_group/heartbeat.rb +3 -5
  206. data/lib/datadog/tracing/contrib/kafka/events/consumer_group/join_group.rb +2 -4
  207. data/lib/datadog/tracing/contrib/kafka/events/consumer_group/leave_group.rb +2 -4
  208. data/lib/datadog/tracing/contrib/kafka/events/consumer_group/sync_group.rb +2 -4
  209. data/lib/datadog/tracing/contrib/kafka/events/produce_operation/send_messages.rb +4 -6
  210. data/lib/datadog/tracing/contrib/kafka/events/producer/deliver_messages.rb +4 -6
  211. data/lib/datadog/tracing/contrib/kafka/events.rb +3 -5
  212. data/lib/datadog/tracing/contrib/kafka/patcher.rb +4 -6
  213. data/lib/datadog/tracing/contrib/karafka/patcher.rb +2 -4
  214. data/lib/datadog/tracing/contrib/lograge/patcher.rb +2 -4
  215. data/lib/datadog/tracing/contrib/mongodb/parsers.rb +5 -7
  216. data/lib/datadog/tracing/contrib/mongodb/patcher.rb +3 -5
  217. data/lib/datadog/tracing/contrib/mysql2/patcher.rb +3 -5
  218. data/lib/datadog/tracing/contrib/opensearch/patcher.rb +1 -3
  219. data/lib/datadog/tracing/contrib/opensearch/quantize.rb +5 -7
  220. data/lib/datadog/tracing/contrib/pg/patcher.rb +3 -5
  221. data/lib/datadog/tracing/contrib/presto/patcher.rb +1 -3
  222. data/lib/datadog/tracing/contrib/que/patcher.rb +2 -4
  223. data/lib/datadog/tracing/contrib/racecar/events/batch.rb +3 -5
  224. data/lib/datadog/tracing/contrib/racecar/events/consume.rb +3 -5
  225. data/lib/datadog/tracing/contrib/racecar/events/message.rb +3 -5
  226. data/lib/datadog/tracing/contrib/racecar/events.rb +3 -5
  227. data/lib/datadog/tracing/contrib/racecar/patcher.rb +2 -4
  228. data/lib/datadog/tracing/contrib/rack/patcher.rb +13 -19
  229. data/lib/datadog/tracing/contrib/rack/request_queue.rb +1 -3
  230. data/lib/datadog/tracing/contrib/rack/route_inference.rb +4 -6
  231. data/lib/datadog/tracing/contrib/rack/trace_proxy_middleware.rb +4 -6
  232. data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +4 -0
  233. data/lib/datadog/tracing/contrib/rails/ext.rb +2 -0
  234. data/lib/datadog/tracing/contrib/rails/framework.rb +6 -8
  235. data/lib/datadog/tracing/contrib/rails/log_injection.rb +1 -3
  236. data/lib/datadog/tracing/contrib/rails/patcher.rb +9 -11
  237. data/lib/datadog/tracing/contrib/rake/patcher.rb +3 -5
  238. data/lib/datadog/tracing/contrib/redis/patcher.rb +2 -4
  239. data/lib/datadog/tracing/contrib/redis/quantize.rb +7 -9
  240. data/lib/datadog/tracing/contrib/resque/patcher.rb +2 -4
  241. data/lib/datadog/tracing/contrib/rest_client/patcher.rb +2 -4
  242. data/lib/datadog/tracing/contrib/roda/patcher.rb +2 -4
  243. data/lib/datadog/tracing/contrib/semantic_logger/patcher.rb +2 -4
  244. data/lib/datadog/tracing/contrib/sequel/patcher.rb +4 -6
  245. data/lib/datadog/tracing/contrib/shoryuken/patcher.rb +2 -4
  246. data/lib/datadog/tracing/contrib/sidekiq/patcher.rb +7 -9
  247. data/lib/datadog/tracing/contrib/sinatra/env.rb +3 -5
  248. data/lib/datadog/tracing/contrib/sinatra/patcher.rb +5 -7
  249. data/lib/datadog/tracing/contrib/sneakers/patcher.rb +2 -4
  250. data/lib/datadog/tracing/contrib/stripe/patcher.rb +2 -4
  251. data/lib/datadog/tracing/contrib/stripe/request.rb +4 -6
  252. data/lib/datadog/tracing/contrib/sucker_punch/exception_handler.rb +1 -3
  253. data/lib/datadog/tracing/contrib/sucker_punch/instrumentation.rb +1 -3
  254. data/lib/datadog/tracing/contrib/sucker_punch/patcher.rb +3 -5
  255. data/lib/datadog/tracing/contrib/support.rb +1 -3
  256. data/lib/datadog/tracing/contrib/trilogy/configuration/settings.rb +4 -0
  257. data/lib/datadog/tracing/contrib/trilogy/instrumentation.rb +2 -1
  258. data/lib/datadog/tracing/contrib/trilogy/patcher.rb +3 -5
  259. data/lib/datadog/tracing/contrib/utils/database.rb +1 -3
  260. data/lib/datadog/tracing/contrib/utils/quantization/hash_formatter.rb +8 -10
  261. data/lib/datadog/tracing/contrib/utils/quantization/http.rb +11 -13
  262. data/lib/datadog/tracing/contrib/waterdrop/patcher.rb +3 -5
  263. data/lib/datadog/tracing/correlation.rb +3 -5
  264. data/lib/datadog/tracing/distributed/propagation.rb +2 -2
  265. data/lib/datadog/tracing/distributed/propagation_policy.rb +1 -3
  266. data/lib/datadog/tracing/distributed/trace_state/datadog.rb +5 -5
  267. data/lib/datadog/tracing/distributed/trace_state/open_telemetry.rb +2 -2
  268. data/lib/datadog/tracing/metadata/ext.rb +3 -9
  269. data/lib/datadog/tracing/remote.rb +1 -1
  270. data/lib/datadog/tracing/trace_operation.rb +11 -3
  271. data/lib/datadog/tracing/tracer.rb +9 -1
  272. data/lib/datadog/tracing/transport/http.rb +1 -3
  273. data/lib/datadog/tracing/transport/io.rb +2 -4
  274. data/lib/datadog/tracing/transport/traces.rb +1 -3
  275. data/lib/datadog/tracing/utils.rb +4 -6
  276. data/lib/datadog/version.rb +1 -1
  277. metadata +22 -6
@@ -11,27 +11,29 @@ module Datadog
11
11
  ALLOWED_FIELD_TYPES = [String, Integer, Float, TrueClass, FalseClass].freeze
12
12
 
13
13
  class << self
14
- def cache_key(result, flag_key:, context:)
15
- "#{flag_key}:#{context.targeting_key}"
14
+ def cache_key(flag_key:, targeting_key:)
15
+ "#{flag_key}:#{targeting_key}"
16
16
  end
17
17
 
18
18
  # NOTE: The serial id is part of the value because it can appear or change on a
19
19
  # configuration refresh while the allocation and the variant stay the same.
20
- def cache_value(result, flag_key:, context:)
21
- "#{result.allocation_key}:#{result.variant}:#{result.serial_id}"
20
+ def cache_value(allocation_key:, variant:, serial_id:)
21
+ "#{allocation_key}:#{variant}:#{serial_id}"
22
22
  end
23
23
 
24
- def build(result, flag_key:, context:)
24
+ # Features stay out of the cache value: a features change alone is not a new exposure.
25
+ def build(flag_key:, allocation_key:, variant:, serial_id:, context:, features:)
26
+ # @type var event: t
25
27
  event = {
26
28
  timestamp: current_timestamp_ms,
27
29
  allocation: {
28
- key: result.allocation_key,
30
+ key: allocation_key,
29
31
  },
30
32
  flag: {
31
33
  key: flag_key,
32
34
  },
33
35
  variant: {
34
- key: result.variant,
36
+ key: variant,
35
37
  },
36
38
  subject: {
37
39
  id: context.targeting_key,
@@ -39,8 +41,8 @@ module Datadog
39
41
  },
40
42
  }
41
43
 
42
- serial_id = result.serial_id
43
44
  event[:serial_id] = serial_id unless serial_id.nil?
45
+ event[:features] = features unless features.empty?
44
46
 
45
47
  event.freeze
46
48
  end
@@ -6,46 +6,55 @@ require_relative "deduplicator"
6
6
  module Datadog
7
7
  module OpenFeature
8
8
  module Exposures
9
- # This class is responsible for reporting exposures to the Agent
9
+ # Owns the exposure cache and sends new or changed exposures to the Agent
10
10
  class Reporter
11
- def initialize(worker, telemetry:, logger:)
11
+ def initialize(worker, logger:, datadog_logging_enabled: true)
12
12
  @worker = worker
13
13
  @logger = logger
14
- @telemetry = telemetry
14
+ @datadog_logging_enabled = datadog_logging_enabled
15
15
  @deduplicator = Deduplicator.new
16
16
  end
17
17
 
18
- # NOTE: Reporting expects evaluation context to be always present, but it
19
- # might be missing depending on the customer way of using flags evaluation API.
20
- # In addition to that the evaluation result must be marked for reporting.
21
- def report(result, flag_key:, context:)
22
- return skip(flag_key, "no evaluation context") if context.nil?
23
- return skip(flag_key, "the evaluation result is not marked for exposure logging") unless result.log?
24
-
25
- key = Event.cache_key(result, flag_key: flag_key, context: context)
26
- value = Event.cache_value(result, flag_key: flag_key, context: context)
27
- return skip(flag_key, "duplicate of the last exposure for this subject") if @deduplicator.duplicate?(key, value)
28
-
29
- event = Event.build(result, flag_key: flag_key, context: context)
30
- return false unless @worker.enqueue(event)
18
+ # Records the exposure in the cache and, when it is new or changed, sends it to Datadog.
19
+ # The cache records even when Datadog logging is off, so the verdict does not depend on it.
20
+ #
21
+ # @return [Boolean] true when this subject was already exposed to the same assignment
22
+ def record(flag_key:, allocation_key:, variant:, serial_id:, context:, features:)
23
+ key = Event.cache_key(flag_key: flag_key, targeting_key: context.targeting_key)
24
+ value = Event.cache_value(allocation_key: allocation_key, variant: variant, serial_id: serial_id)
25
+ if @deduplicator.duplicate?(key, value)
26
+ skip(flag_key, "duplicate of the last exposure for this subject")
27
+ return true
28
+ end
31
29
 
32
- @logger.debug do
33
- "Feature Flags: queued exposure for #{flag_key.inspect} (allocation=#{result.allocation_key.inspect}, " \
34
- "variant=#{result.variant.inspect}, targeting_key=#{context.targeting_key.inspect})"
30
+ unless @datadog_logging_enabled
31
+ skip(flag_key, "Datadog exposure logging is disabled")
32
+ return false
35
33
  end
36
- true
37
- rescue => e
38
- @logger.debug { "OpenFeature: Failed to report resolution details: #{e.class}: #{e.message}" }
39
- @telemetry.report(e, description: "OpenFeature: Failed to report resolution details")
40
34
 
35
+ enqueue(
36
+ Event.build(
37
+ flag_key: flag_key, allocation_key: allocation_key, variant: variant, serial_id: serial_id,
38
+ context: context, features: features,
39
+ ),
40
+ )
41
41
  false
42
42
  end
43
43
 
44
44
  private
45
45
 
46
+ def enqueue(event)
47
+ return unless @worker.enqueue(event)
48
+
49
+ @logger.debug do
50
+ "Feature Flags: queued exposure for #{event.dig(:flag, :key).inspect} " \
51
+ "(allocation=#{event.dig(:allocation, :key).inspect}, variant=#{event.dig(:variant, :key).inspect}, " \
52
+ "targeting_key=#{event.dig(:subject, :id).inspect})"
53
+ end
54
+ end
55
+
46
56
  def skip(flag_key, reason)
47
- @logger.debug { "Feature Flags: exposure for #{flag_key.inspect} not recorded: #{reason}" }
48
- false
57
+ @logger.debug { "Feature Flags: exposure for #{flag_key.inspect} not sent: #{reason}" }
49
58
  end
50
59
  end
51
60
  end
@@ -3,6 +3,8 @@
3
3
  module Datadog
4
4
  module OpenFeature
5
5
  module Ext
6
+ PROVIDER_NAME = "Datadog Feature Flagging Provider"
7
+
6
8
  ERROR = "ERROR"
7
9
  DEFAULT = "DEFAULT"
8
10
  INITIALIZING = "INITIALIZING"
@@ -35,6 +37,16 @@ module Datadog
35
37
  # Stamped from the UFC the evaluation ran against; the hook reads only this
36
38
  # key, never live config.
37
39
  METADATA_OBSERVE_FULL_EVALUATION_DATA = "__dd_observe_full_evaluation_data"
40
+
41
+ METADATA_DO_LOG = "__dd_do_log"
42
+ METADATA_SPLIT_SERIAL_ID = "__dd_split_serial_id"
43
+ METADATA_EXPOSURE_CACHE_HIT = "__dd_exposure_cache_hit"
44
+
45
+ # Split features are flattened into metadata as one entry per destination.
46
+ # `__dd_feature.` is the public prefix customers read; the others are internal.
47
+ METADATA_FEATURE_PREFIX = "__dd_feature."
48
+ METADATA_EXPOSURE_FEATURE_PREFIX = "__dd_exposure_feature."
49
+ METADATA_EVALUATION_FEATURE_PREFIX = "__dd_evaluation_feature."
38
50
  end
39
51
  end
40
52
  end
@@ -9,8 +9,8 @@ module Datadog
9
9
  #
10
10
  # Two-tier design:
11
11
  # - full-tier key: (flag_key, variant, allocation_key, runtime_default, error_message,
12
- # targeting_key, canonical_context_key, observe_full_evaluation_data)
13
- # - degraded-tier key: (flag_key, variant, allocation_key, runtime_default, error_message)
12
+ # targeting_key, canonical_context_key, observe_full_evaluation_data, features)
13
+ # - degraded-tier key: (flag_key, variant, allocation_key, runtime_default, error_message, features)
14
14
  # - Drop-and-count when degraded tier is full
15
15
  # - canonical_context_key: sorted type-tagged length-delimited encoding (no hash digest)
16
16
  # - Caps: global_cap=131_072 / per_flag_cap=10_000 / degraded_cap=32_768
@@ -63,6 +63,8 @@ module Datadog
63
63
  DEFAULT_PER_FLAG_CAP = EVAL_SCALE_PER_FLAG_BUCKET_TARGET
64
64
  DEFAULT_DEGRADED_CAP = 32_768
65
65
 
66
+ NO_FEATURES = {}.freeze
67
+
66
68
  attr_reader :dropped_degraded_overflow
67
69
 
68
70
  def initialize(
@@ -88,7 +90,7 @@ module Datadog
88
90
  # Record one evaluation event. Thread-safe. Called from the background writer.
89
91
  def record(
90
92
  flag_key:, variant:, allocation_key:, targeting_key:, eval_time_ms:, attrs:, error_message: nil,
91
- runtime_default: nil, observe_full_evaluation_data: false
93
+ runtime_default: nil, observe_full_evaluation_data: false, features: NO_FEATURES
92
94
  )
93
95
  runtime_default = variant.nil? if runtime_default.nil?
94
96
  runtime_default = !!runtime_default
@@ -109,7 +111,7 @@ module Datadog
109
111
  # @type var full_key: full_key
110
112
  full_key = [
111
113
  flag_key, variant, allocation_key, runtime_default, error_message,
112
- targeting_key, context_key, observe_full_evaluation_data,
114
+ targeting_key, context_key, observe_full_evaluation_data, features,
113
115
  ]
114
116
  evaluation_time_ms = eval_time_ms.to_i
115
117
 
@@ -124,7 +126,7 @@ module Datadog
124
126
  if per_flag_count >= @per_flag_cap
125
127
  add_to_degraded(
126
128
  flag_key, variant, allocation_key, runtime_default, error_message, evaluation_time_ms,
127
- observe_full_evaluation_data,
129
+ observe_full_evaluation_data, features,
128
130
  )
129
131
  return
130
132
  end
@@ -148,7 +150,7 @@ module Datadog
148
150
  # Route to degraded tier
149
151
  add_to_degraded(
150
152
  flag_key, variant, allocation_key, runtime_default, error_message, evaluation_time_ms,
151
- observe_full_evaluation_data,
153
+ observe_full_evaluation_data, features,
152
154
  )
153
155
  end
154
156
  end
@@ -411,10 +413,10 @@ module Datadog
411
413
 
412
414
  def add_to_degraded(
413
415
  flag_key, variant, allocation_key, runtime_default, error_message, evaluation_time_ms,
414
- observe_full_evaluation_data
416
+ observe_full_evaluation_data, features
415
417
  )
416
418
  # @type var degraded_key: degraded_key
417
- degraded_key = [flag_key, variant, allocation_key, runtime_default, error_message]
419
+ degraded_key = [flag_key, variant, allocation_key, runtime_default, error_message, features]
418
420
 
419
421
  if (entry = @degraded[degraded_key])
420
422
  observe(entry, evaluation_time_ms, observe_full_evaluation_data)
@@ -85,7 +85,7 @@ module Datadog
85
85
  def enqueue(
86
86
  flag_key:, eval_time_ms:, variant: nil, allocation_key: nil, error_message: nil,
87
87
  runtime_default: nil, targeting_key: nil, attrs: nil, observe_full_evaluation_data: false,
88
- **_event
88
+ features: Aggregator::NO_FEATURES, **_event
89
89
  )
90
90
  start_background_thread if forked?
91
91
 
@@ -107,6 +107,7 @@ module Datadog
107
107
  eval_time_ms: snapshot_integer(eval_time_ms),
108
108
  attrs: attrs,
109
109
  observe_full_evaluation_data: observe_full_evaluation_data,
110
+ features: features,
110
111
  }
111
112
  @queue.push(bounded_event, true)
112
113
  @stop_mutex.synchronize { @stop_cond.signal }
@@ -283,6 +284,7 @@ module Datadog
283
284
  error_message: event[:error_message],
284
285
  runtime_default: event[:runtime_default],
285
286
  observe_full_evaluation_data: event[:observe_full_evaluation_data],
287
+ features: event[:features],
286
288
  )
287
289
  drained += 1
288
290
  rescue ThreadError
@@ -359,9 +361,9 @@ module Datadog
359
361
  events = []
360
362
 
361
363
  snapshot[:full].each do |key, entry|
362
- flag_key, variant, allocation_key, _runtime_default, _error_message, targeting_key, _ctx_key, _observe_full_evaluation_data = key
364
+ flag_key, variant, allocation_key, _runtime_default, _error_message, targeting_key, _ctx_key, _observe_full_evaluation_data, features = key
363
365
  event = build_event(
364
- flag_key: flag_key, variant: variant, allocation_key: allocation_key,
366
+ flag_key: flag_key, variant: variant, allocation_key: allocation_key, features: features,
365
367
  targeting_key: targeting_key, entry: entry, flush_time_ms: flush_time_ms, tier: :full,
366
368
  )
367
369
  events << event
@@ -369,9 +371,9 @@ module Datadog
369
371
 
370
372
  # Degraded rows omit targeting_key and context, so the policy is not a key dimension.
371
373
  snapshot[:degraded].each do |key, entry|
372
- flag_key, variant, allocation_key, _runtime_default, _error_dimension = key
374
+ flag_key, variant, allocation_key, _runtime_default, _error_dimension, features = key
373
375
  event = build_event(
374
- flag_key: flag_key, variant: variant, allocation_key: allocation_key,
376
+ flag_key: flag_key, variant: variant, allocation_key: allocation_key, features: features,
375
377
  targeting_key: nil, entry: entry, flush_time_ms: flush_time_ms, tier: :degraded,
376
378
  )
377
379
  events << event
@@ -381,7 +383,7 @@ module Datadog
381
383
  end
382
384
 
383
385
  def build_event(
384
- flag_key:, variant:, allocation_key:, targeting_key:, entry:, flush_time_ms:, tier:
386
+ flag_key:, variant:, allocation_key:, features:, targeting_key:, entry:, flush_time_ms:, tier:
385
387
  )
386
388
  observe_full_evaluation_data = entry[:observe_full_evaluation_data]
387
389
  # @type var event: ::Hash[::String, any]
@@ -404,6 +406,7 @@ module Datadog
404
406
  # variant + allocation are present in both tiers (omitempty per schema).
405
407
  event["variant"] = {"key" => variant} if variant && !variant.empty?
406
408
  event["allocation"] = {"key" => allocation_key} if allocation_key && !allocation_key.empty?
409
+ event["features"] = features unless features.empty?
407
410
 
408
411
  # Full-tier additionally carries targeting_key and the truncated evaluation context;
409
412
  # the degraded tier omits both.
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../ext"
4
+ require_relative "../split_features"
5
+
6
+ module Datadog
7
+ module OpenFeature
8
+ module Hooks
9
+ # Makes the one exposure decision of an evaluation: records it in the exposure cache,
10
+ # sends new or changed exposures to Datadog, and stamps the verdict into the flag metadata
11
+ # as `__dd_exposure_cache_hit` for hooks that run after it.
12
+ #
13
+ # It runs at the finally stage because an application after hook can still raise and turn
14
+ # the result into the default value. The SDK runs provider finally hooks before application
15
+ # ones, so ExposureHook callbacks see the final verdict.
16
+ class ExposureLoggingHook
17
+ include ::OpenFeature::SDK::Hooks::Hook if defined?(::OpenFeature::SDK::Hooks::Hook)
18
+
19
+ def self.available?
20
+ !!defined?(::OpenFeature::SDK::Hooks::Hook)
21
+ end
22
+
23
+ def initialize(reporter, telemetry:, logger:)
24
+ @reporter = reporter
25
+ @telemetry = telemetry
26
+ @logger = logger
27
+ end
28
+
29
+ def finally(hook_context:, evaluation_details:, **_opts)
30
+ return if evaluation_details.error_code || evaluation_details.reason == Ext::ERROR
31
+
32
+ # The SDK may hand hooks frozen copies; the verdict goes into the details' own metadata.
33
+ metadata = evaluation_details.resolution_details[:flag_metadata]
34
+ return unless metadata.is_a?(Hash) && !metadata.frozen?
35
+ return unless metadata[Ext::METADATA_DO_LOG] == true
36
+
37
+ allocation_key = metadata[Ext::METADATA_ALLOCATION_KEY]
38
+ variant = evaluation_details.variant
39
+ context = hook_context.evaluation_context
40
+ return unless allocation_key.is_a?(String) && variant && context
41
+
42
+ metadata[Ext::METADATA_EXPOSURE_CACHE_HIT] = @reporter.record(
43
+ flag_key: hook_context.flag_key,
44
+ allocation_key: allocation_key,
45
+ variant: variant,
46
+ serial_id: metadata[Ext::METADATA_SPLIT_SERIAL_ID],
47
+ context: context,
48
+ features: SplitFeatures.read(metadata, Ext::METADATA_EXPOSURE_FEATURE_PREFIX),
49
+ )
50
+ rescue => e
51
+ # Exposure reporting must never change the evaluation result.
52
+ @logger.debug { "OpenFeature: Failed to report exposure: #{e.class}: #{e.message}" }
53
+ @telemetry.report(e, description: "OpenFeature: Failed to report exposure")
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "../ext"
4
+ require_relative "../split_features"
4
5
 
5
6
  module Datadog
6
7
  module OpenFeature
@@ -15,11 +16,11 @@ module Datadog
15
16
  # stay on the OTel path. This hook is registered as a provider hook so it receives
16
17
  # the SDK-final EvaluationDetails after hook failures and type validation.
17
18
  class FlagEvalEVPHook
18
- # Include the Hook module if available (SDK >= 0.5.0) for interface documentation
19
+ # Include the Hook module if available (SDK >= 0.5.1) for interface documentation
19
20
  # and default implementations of other hook methods (before, after, error)
20
21
  include ::OpenFeature::SDK::Hooks::Hook if defined?(::OpenFeature::SDK::Hooks::Hook)
21
22
 
22
- # Returns true if the OpenFeature SDK supports hooks (>= 0.5.0)
23
+ # Returns true if the OpenFeature SDK supports hooks (>= 0.5.1)
23
24
  def self.available?
24
25
  !!defined?(::OpenFeature::SDK::Hooks::Hook)
25
26
  end
@@ -65,6 +66,7 @@ module Datadog
65
66
  eval_time_ms: eval_time_ms,
66
67
  attrs: attrs,
67
68
  observe_full_evaluation_data: observe_full_evaluation_data,
69
+ features: SplitFeatures.read(metadata, Ext::METADATA_EVALUATION_FEATURE_PREFIX),
68
70
  )
69
71
  end
70
72
 
@@ -7,15 +7,13 @@ module Datadog
7
7
  module Hooks
8
8
  # Records flag evaluation metrics via OpenTelemetry hook
9
9
  #
10
- # Compatible with OpenFeature SDK >= 0.5.0 which provides the Hooks::Hook module,
11
- # but also works with older versions since the SDK uses respond_to?(:finally)
12
- # to detect hook capabilities.
10
+ # OpenFeature SDK 0.5.1 is the first release that defines Hooks::Hook and runs hooks.
13
11
  class FlagEvalMetricsHook
14
- # Include the Hook module if available (SDK >= 0.5.0) for interface documentation
12
+ # Include the Hook module if available (SDK >= 0.5.1) for interface documentation
15
13
  # and default implementations of other hook methods (before, after, error)
16
14
  include ::OpenFeature::SDK::Hooks::Hook if defined?(::OpenFeature::SDK::Hooks::Hook)
17
15
 
18
- # Returns true if the OpenFeature SDK supports hooks (>= 0.5.0)
16
+ # Returns true if the OpenFeature SDK supports hooks (>= 0.5.1)
19
17
  def self.available?
20
18
  !!defined?(::OpenFeature::SDK::Hooks::Hook)
21
19
  end
@@ -8,8 +8,6 @@ module Datadog
8
8
  class SpanEnrichmentHook
9
9
  # Encoding/crypto helpers implementing the fixed cross-SDK wire format.
10
10
  module Codec
11
- module_function
12
-
13
11
  # ULEB128 stores 7 bits per byte; the high bit flags that more bytes follow.
14
12
  LOW_7_BITS_MASK = 0x7F
15
13
  CONTINUATION_BIT = 0x80
@@ -19,7 +17,7 @@ module Datadog
19
17
  # byte >= 0x80 would be re-encoded as a 2-byte UTF-8 sequence and corrupt
20
18
  # the varint (e.g. serial 2312 -> bytes 88 12, but UTF-8 would emit
21
19
  # C2 88 12 = 296002 on decode). `(+'').b` gives a mutable binary string.
22
- def encode_varint(value)
20
+ def self.encode_varint(value)
23
21
  bytes = (+"").b
24
22
  while value > LOW_7_BITS_MASK
25
23
  bytes << ((value & LOW_7_BITS_MASK) | CONTINUATION_BIT)
@@ -31,7 +29,7 @@ module Datadog
31
29
 
32
30
  # Encode a Set of serial ids as base64(ULEB128 delta-varint).
33
31
  # Empty set -> empty string (the caller omits the tag).
34
- def encode_delta_varint(serial_ids)
32
+ def self.encode_delta_varint(serial_ids)
35
33
  sorted = serial_ids.to_a.sort
36
34
  return "" if sorted.empty?
37
35
 
@@ -48,7 +46,7 @@ module Datadog
48
46
 
49
47
  # Lowercase hex SHA256 of the targeting key: it is hashed before
50
48
  # emission so raw user identifiers never leave the process.
51
- def hash_targeting_key(targeting_key)
49
+ def self.hash_targeting_key(targeting_key)
52
50
  Digest::SHA256.hexdigest(targeting_key)
53
51
  end
54
52
  end
@@ -31,8 +31,28 @@ module Datadog
31
31
  # and other attributes
32
32
  #
33
33
  # @return [ResolutionDetails] The assignment for the flag
34
- def get_assignment(flag_key, default_value:, expected_type:, context:)
35
- result = @configuration.get_assignment(flag_key, expected_type, context)
34
+ def get_assignment(flag_key, default_value:, expected_type:, context:, experimentation_opt_out_mode: :disabled)
35
+ if experimentation_opt_out_mode != :disabled && context.key?("dd_experimentation_opt_out_at")
36
+ timestamp = context["dd_experimentation_opt_out_at"]
37
+ # The C binding drops nil and unsupported values, making them look absent, and truncates strings at NUL.
38
+ # Reject them before conversion can permit experimentation; libdatadog checks the timestamp grammar.
39
+ unless valid_native_timestamp?(timestamp)
40
+ return ResolutionDetails.build_error(
41
+ value: default_value, error_code: Ext::INVALID_CONTEXT,
42
+ error_message: "dd_experimentation_opt_out_at must be an RFC3339 timestamp string; " \
43
+ "supply a valid timestamp to opt out, or omit the attribute to permit experimentation",
44
+ )
45
+ end
46
+ end
47
+
48
+ result = case experimentation_opt_out_mode
49
+ when :immediate
50
+ @configuration.get_assignment_with_options(flag_key, expected_type, context, true)
51
+ when :future_experiments_only
52
+ @configuration.get_assignment_with_opt_out_mode(flag_key, expected_type, context, :future_experiments_only)
53
+ else
54
+ @configuration.get_assignment(flag_key, expected_type, context)
55
+ end
36
56
 
37
57
  return invalid_flag_configuration_error(default_value) if invalid_flag_configuration?(result)
38
58
 
@@ -41,6 +61,13 @@ module Datadog
41
61
 
42
62
  private
43
63
 
64
+ def valid_native_timestamp?(timestamp)
65
+ return false unless timestamp.is_a?(String)
66
+
67
+ native_timestamp = timestamp.dup.force_encoding(Encoding::UTF_8)
68
+ native_timestamp.valid_encoding? && !native_timestamp.include?("\0")
69
+ end
70
+
44
71
  def build_resolution_details(result, default_value)
45
72
  ResolutionDetails.new(
46
73
  value: result.variant.nil? ? default_value : result.value,
@@ -51,6 +78,7 @@ module Datadog
51
78
  flag_metadata: result.flag_metadata,
52
79
  allocation_key: result.allocation_key,
53
80
  serial_id: result.serial_id,
81
+ features: result.features,
54
82
  log?: result.log?,
55
83
  error?: result.error?,
56
84
  )
@@ -16,7 +16,9 @@ module Datadog
16
16
  # no-op
17
17
  end
18
18
 
19
- def get_assignment(_flag_key, default_value:, context:, expected_type:)
19
+ def get_assignment(
20
+ _flag_key, default_value:, context:, expected_type:, experimentation_opt_out_mode: :disabled
21
+ )
20
22
  ResolutionDetails.new(
21
23
  value: default_value,
22
24
  log?: false,
@@ -3,14 +3,18 @@
3
3
  require_relative "ext"
4
4
  require_relative "../open_feature"
5
5
  require_relative "../core/utils/time"
6
+ require_relative "../core/utils/only_once"
6
7
  require_relative "hooks/evaluation_telemetry_opt_out_hook"
8
+ require_relative "split_features"
9
+ require_relative "exposure_hook"
7
10
  require "open_feature/sdk"
8
11
 
9
12
  module Datadog
10
13
  module OpenFeature
11
14
  # OpenFeature feature flagging provider backed by Datadog configuration delivery.
12
15
  #
13
- # Requires openfeature-sdk >= 0.5.1 for flag evaluation metrics and EVP hook support.
16
+ # Requires openfeature-sdk >= 0.5.1: exposures, evaluation counts and metrics are sent from provider
17
+ # hooks, and earlier releases run no hooks.
14
18
  #
15
19
  # Hook lifecycle note: FlagEvalEVPHook is returned from #hooks so EVP uses the SDK-final
16
20
  # EvaluationDetails. This matches FlagEvalMetricsHook and records defaults/errors produced
@@ -63,12 +67,22 @@ module Datadog
63
67
  class Provider
64
68
  include ::OpenFeature::SDK::Provider::EventEmitter
65
69
 
66
- NAME = "Datadog Feature Flagging Provider"
70
+ NAME = Ext::PROVIDER_NAME
67
71
  INITIALIZATION_CANCELLED_MESSAGE = "Feature Flags provider initialization was cancelled by shutdown"
72
+ HOOKS_UNSUPPORTED_MESSAGE = "Feature Flags: the installed openfeature-sdk does not run provider hooks, " \
73
+ "so Datadog exposures and evaluation counts are not sent; upgrade openfeature-sdk to 0.5.1 or later"
74
+ HOOKS_UNSUPPORTED_WARNING = Core::Utils::OnlyOnce.new
68
75
 
69
76
  attr_reader :metadata
70
77
 
71
- def initialize(enable_evaluation_telemetry_opt_out_parameter: nil)
78
+ def initialize(experimentation_opt_out_mode: nil, enable_evaluation_telemetry_opt_out_parameter: nil)
79
+ mode = experimentation_opt_out_mode
80
+ mode = Datadog.configuration.feature_flags.experimentation_opt_out_mode if mode.nil?
81
+ # Preserve the requested policy if this provider is activated after configuration changes.
82
+ @requested_experimentation_opt_out_mode = mode.to_s.dup.freeze
83
+ @experimentation_opt_out_mode = if OpenFeature.enabled? && Core::LIBDATADOG_API_FAILURE.nil?
84
+ resolve_experimentation_opt_out_mode(@requested_experimentation_opt_out_mode)
85
+ end
72
86
  @enable_evaluation_telemetry_opt_out_parameter = case enable_evaluation_telemetry_opt_out_parameter
73
87
  when nil
74
88
  Datadog.configuration.feature_flags.evaluation_telemetry_per_subject_opt_out_enabled
@@ -95,6 +109,7 @@ module Datadog
95
109
  end
96
110
 
97
111
  def init
112
+ warn_if_hooks_unsupported
98
113
  @initialization_mutex.synchronize do
99
114
  raise INITIALIZATION_CANCELLED_MESSAGE if @shutdown
100
115
 
@@ -188,7 +203,7 @@ module Datadog
188
203
  telemetry_hooks = telemetry_hooks.map { |hook| Hooks::EvaluationTelemetryOptOutHook.new(hook) }
189
204
  end
190
205
 
191
- [*telemetry_hooks, component&.debug_logging_hook].compact
206
+ [component&.exposure_logging_hook, *telemetry_hooks, component&.debug_logging_hook].compact
192
207
  end
193
208
 
194
209
  def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil)
@@ -217,6 +232,12 @@ module Datadog
217
232
 
218
233
  private
219
234
 
235
+ def warn_if_hooks_unsupported
236
+ return if defined?(::OpenFeature::SDK::Hooks::HookExecutor)
237
+
238
+ HOOKS_UNSUPPORTED_WARNING.run { Datadog.logger.warn(HOOKS_UNSUPPORTED_MESSAGE) }
239
+ end
240
+
220
241
  def after_fork(component)
221
242
  handler = @initialization_mutex.synchronize do
222
243
  return if @shutdown || !@initializing || @initialization_thread&.alive?
@@ -467,14 +488,36 @@ module Datadog
467
488
  end
468
489
 
469
490
  def fetch_engine_value(engine, flag_key, default_value, expected_type, evaluation_context)
491
+ mode = @experimentation_opt_out_mode ||= resolve_experimentation_opt_out_mode(@requested_experimentation_opt_out_mode)
470
492
  engine.fetch_value(
471
493
  flag_key,
472
494
  default_value: default_value,
473
495
  expected_type: expected_type,
474
496
  evaluation_context: evaluation_context,
497
+ experimentation_opt_out_mode: mode,
475
498
  )
476
499
  end
477
500
 
501
+ def resolve_experimentation_opt_out_mode(mode)
502
+ normalized = mode.strip.downcase
503
+ return :disabled if normalized.empty? || normalized == "disabled"
504
+
505
+ case normalized
506
+ when "immediate"
507
+ unless Core::FeatureFlags::Configuration.method_defined?(:get_assignment_with_options)
508
+ raise ArgumentError, "Immediate experimentation opt-out requires a libdatadog build with evaluation options"
509
+ end
510
+ :immediate
511
+ when "future_experiments_only"
512
+ unless Core::FeatureFlags::Configuration.method_defined?(:get_assignment_with_opt_out_mode)
513
+ raise ArgumentError, "Future experimentation opt-out requires a libdatadog build with opt-out modes"
514
+ end
515
+ :future_experiments_only
516
+ else
517
+ raise ArgumentError, "Experimentation opt-out mode must be disabled, immediate, or future_experiments_only"
518
+ end
519
+ end
520
+
478
521
  def sdk_success_details(result, flag_meta)
479
522
  ::OpenFeature::SDK::Provider::ResolutionDetails.new(
480
523
  value: result.value,
@@ -500,6 +543,13 @@ module Datadog
500
543
  metadata[Ext::METADATA_OBSERVE_FULL_EVALUATION_DATA] == true
501
544
  allocation_key = result.allocation_key
502
545
  metadata[Ext::METADATA_ALLOCATION_KEY] = allocation_key if allocation_key && !allocation_key.empty?
546
+ if result.log?
547
+ metadata[Ext::METADATA_DO_LOG] = true
548
+ serial_id = result.serial_id
549
+ metadata[Ext::METADATA_SPLIT_SERIAL_ID] = serial_id unless serial_id.nil?
550
+ end
551
+ features = result.features
552
+ SplitFeatures.write(metadata, features) if features && !features.empty?
503
553
 
504
554
  # Eval-time stamped at provider entry; the EVP hook reads 'dd.eval.timestamp_ms' for
505
555
  # accurate first/last_evaluation bounds (it falls back to hook-fire time when absent).
@@ -17,6 +17,7 @@ module Datadog
17
17
  :allocation_key,
18
18
  :serial_id,
19
19
  :extra_logging,
20
+ :features,
20
21
  :log?,
21
22
  :error?,
22
23
  keyword_init: true,