ddtrace 1.14.0 → 1.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (283) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +146 -2
  3. data/ext/ddtrace_profiling_native_extension/NativeExtensionDesign.md +3 -5
  4. data/ext/ddtrace_profiling_native_extension/clock_id.h +0 -3
  5. data/ext/ddtrace_profiling_native_extension/clock_id_from_pthread.c +0 -22
  6. data/ext/ddtrace_profiling_native_extension/clock_id_noop.c +0 -1
  7. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +41 -6
  8. data/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.c +3 -0
  9. data/ext/ddtrace_profiling_native_extension/collectors_stack.c +76 -24
  10. data/ext/ddtrace_profiling_native_extension/collectors_stack.h +1 -1
  11. data/ext/ddtrace_profiling_native_extension/collectors_thread_context.c +207 -32
  12. data/ext/ddtrace_profiling_native_extension/collectors_thread_context.h +1 -1
  13. data/ext/ddtrace_profiling_native_extension/extconf.rb +8 -2
  14. data/ext/ddtrace_profiling_native_extension/http_transport.c +26 -10
  15. data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.c +42 -0
  16. data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.h +6 -0
  17. data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +1 -16
  18. data/ext/ddtrace_profiling_native_extension/pid_controller.c +57 -0
  19. data/ext/ddtrace_profiling_native_extension/pid_controller.h +45 -0
  20. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +17 -12
  21. data/ext/ddtrace_profiling_native_extension/profiling.c +0 -2
  22. data/ext/ddtrace_profiling_native_extension/stack_recorder.c +74 -37
  23. data/ext/ddtrace_profiling_native_extension/stack_recorder.h +13 -3
  24. data/lib/datadog/appsec/assets/waf_rules/processors.json +92 -0
  25. data/lib/datadog/appsec/assets/waf_rules/recommended.json +698 -75
  26. data/lib/datadog/appsec/assets/waf_rules/scanners.json +114 -0
  27. data/lib/datadog/appsec/assets/waf_rules/strict.json +98 -8
  28. data/lib/datadog/appsec/assets.rb +8 -0
  29. data/lib/datadog/appsec/component.rb +9 -2
  30. data/lib/datadog/appsec/configuration/settings.rb +67 -2
  31. data/lib/datadog/appsec/contrib/rack/gateway/request.rb +6 -2
  32. data/lib/datadog/appsec/contrib/rack/gateway/response.rb +46 -0
  33. data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +8 -6
  34. data/lib/datadog/appsec/contrib/rack/reactive/request.rb +2 -7
  35. data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +2 -5
  36. data/lib/datadog/appsec/contrib/rack/reactive/response.rb +7 -5
  37. data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +3 -2
  38. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +34 -10
  39. data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +3 -2
  40. data/lib/datadog/appsec/contrib/rails/patcher.rb +9 -3
  41. data/lib/datadog/appsec/contrib/rails/reactive/action.rb +2 -5
  42. data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +6 -4
  43. data/lib/datadog/appsec/contrib/sinatra/patcher.rb +13 -7
  44. data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +2 -5
  45. data/lib/datadog/appsec/event.rb +106 -50
  46. data/lib/datadog/appsec/monitor/gateway/watcher.rb +3 -3
  47. data/lib/datadog/appsec/monitor/reactive/set_user.rb +2 -5
  48. data/lib/datadog/appsec/processor/actions.rb +49 -0
  49. data/lib/datadog/appsec/processor/rule_merger.rb +22 -2
  50. data/lib/datadog/appsec/processor.rb +34 -6
  51. data/lib/datadog/appsec/remote.rb +4 -1
  52. data/lib/datadog/appsec/response.rb +82 -4
  53. data/lib/datadog/appsec/sample_rate.rb +21 -0
  54. data/lib/datadog/appsec.rb +2 -2
  55. data/lib/datadog/core/configuration/agent_settings_resolver.rb +29 -24
  56. data/lib/datadog/core/configuration/base.rb +1 -11
  57. data/lib/datadog/core/configuration/components.rb +7 -2
  58. data/lib/datadog/core/configuration/ext.rb +21 -0
  59. data/lib/datadog/core/configuration/option.rb +2 -4
  60. data/lib/datadog/core/configuration/option_definition.rb +17 -41
  61. data/lib/datadog/core/configuration/options.rb +5 -5
  62. data/lib/datadog/core/configuration/settings.rb +47 -45
  63. data/lib/datadog/core/environment/execution.rb +47 -9
  64. data/lib/datadog/core/environment/variable_helpers.rb +0 -69
  65. data/lib/datadog/core/error.rb +1 -0
  66. data/lib/datadog/core/git/ext.rb +2 -0
  67. data/lib/datadog/core/remote/client/capabilities.rb +1 -1
  68. data/lib/datadog/core/remote/component.rb +2 -2
  69. data/lib/datadog/core/remote/negotiation.rb +2 -2
  70. data/lib/datadog/core/remote/transport/config.rb +60 -0
  71. data/lib/datadog/core/remote/transport/http/api/instance.rb +39 -0
  72. data/lib/datadog/core/remote/transport/http/api/spec.rb +21 -0
  73. data/lib/datadog/core/remote/transport/http/api.rb +58 -0
  74. data/lib/datadog/core/remote/transport/http/builder.rb +219 -0
  75. data/lib/datadog/core/remote/transport/http/client.rb +48 -0
  76. data/lib/datadog/core/remote/transport/http/config.rb +280 -0
  77. data/lib/datadog/core/remote/transport/http/negotiation.rb +146 -0
  78. data/lib/datadog/core/remote/transport/http.rb +179 -0
  79. data/lib/datadog/core/{transport → remote/transport}/negotiation.rb +25 -23
  80. data/lib/datadog/core/remote/worker.rb +3 -1
  81. data/lib/datadog/core/telemetry/collector.rb +3 -2
  82. data/lib/datadog/core/telemetry/http/transport.rb +2 -1
  83. data/lib/datadog/core/transport/ext.rb +47 -0
  84. data/lib/datadog/core/transport/http/adapters/net.rb +168 -0
  85. data/lib/datadog/core/transport/http/adapters/registry.rb +29 -0
  86. data/lib/datadog/core/transport/http/adapters/test.rb +89 -0
  87. data/lib/datadog/core/transport/http/adapters/unix_socket.rb +83 -0
  88. data/lib/datadog/core/transport/http/api/endpoint.rb +31 -0
  89. data/lib/datadog/core/transport/http/api/fallbacks.rb +26 -0
  90. data/lib/datadog/core/transport/http/api/map.rb +18 -0
  91. data/lib/datadog/core/transport/http/env.rb +62 -0
  92. data/lib/datadog/core/transport/http/response.rb +60 -0
  93. data/lib/datadog/core/transport/parcel.rb +22 -0
  94. data/lib/datadog/core/transport/request.rb +17 -0
  95. data/lib/datadog/core/transport/response.rb +64 -0
  96. data/lib/datadog/core/workers/polling.rb +2 -2
  97. data/lib/datadog/opentelemetry/api/context.rb +10 -3
  98. data/lib/datadog/opentelemetry/sdk/propagator.rb +2 -1
  99. data/lib/datadog/opentelemetry/sdk/span_processor.rb +14 -2
  100. data/lib/datadog/opentelemetry/sdk/trace/span.rb +68 -0
  101. data/lib/datadog/opentelemetry/trace.rb +58 -0
  102. data/lib/datadog/opentelemetry.rb +1 -0
  103. data/lib/datadog/opentracer.rb +9 -0
  104. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +14 -19
  105. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -1
  106. data/lib/datadog/profiling/collectors/thread_context.rb +9 -1
  107. data/lib/datadog/profiling/component.rb +24 -99
  108. data/lib/datadog/profiling/ext.rb +0 -12
  109. data/lib/datadog/profiling/flush.rb +0 -3
  110. data/lib/datadog/profiling/http_transport.rb +6 -3
  111. data/lib/datadog/profiling/native_extension.rb +0 -21
  112. data/lib/datadog/profiling/profiler.rb +36 -13
  113. data/lib/datadog/profiling/scheduler.rb +16 -9
  114. data/lib/datadog/profiling.rb +8 -81
  115. data/lib/datadog/tracing/component.rb +10 -4
  116. data/lib/datadog/tracing/configuration/agent_settings_resolver.rb +13 -0
  117. data/lib/datadog/tracing/configuration/ext.rb +4 -2
  118. data/lib/datadog/tracing/configuration/settings.rb +14 -7
  119. data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +1 -1
  120. data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +1 -1
  121. data/lib/datadog/tracing/contrib/active_record/events/sql.rb +4 -0
  122. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +106 -197
  123. data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +3 -0
  124. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +7 -0
  125. data/lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb +14 -14
  126. data/lib/datadog/tracing/contrib/concurrent_ruby/future_patch.rb +3 -10
  127. data/lib/datadog/tracing/contrib/concurrent_ruby/integration.rb +2 -1
  128. data/lib/datadog/tracing/contrib/concurrent_ruby/patcher.rb +8 -1
  129. data/lib/datadog/tracing/contrib/concurrent_ruby/promises_future_patch.rb +22 -0
  130. data/lib/datadog/tracing/contrib/configuration/settings.rb +1 -1
  131. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +6 -0
  132. data/lib/datadog/tracing/contrib/dalli/ext.rb +7 -0
  133. data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +9 -2
  134. data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +1 -1
  135. data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +5 -0
  136. data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +5 -0
  137. data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +8 -0
  138. data/lib/datadog/tracing/contrib/excon/middleware.rb +5 -0
  139. data/lib/datadog/tracing/contrib/ext.rb +3 -0
  140. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +1 -1
  141. data/lib/datadog/tracing/contrib/faraday/middleware.rb +5 -0
  142. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +21 -1
  143. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +11 -1
  144. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +18 -0
  145. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor.rb +0 -4
  146. data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +3 -3
  147. data/lib/datadog/tracing/contrib/http/instrumentation.rb +5 -0
  148. data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +5 -0
  149. data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +5 -0
  150. data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +7 -0
  151. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +13 -3
  152. data/lib/datadog/tracing/contrib/opensearch/integration.rb +2 -2
  153. data/lib/datadog/tracing/contrib/opensearch/patcher.rb +7 -0
  154. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +5 -0
  155. data/lib/datadog/tracing/contrib/presto/instrumentation.rb +5 -0
  156. data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +1 -1
  157. data/lib/datadog/tracing/contrib/que/configuration/settings.rb +1 -1
  158. data/lib/datadog/tracing/contrib/racecar/event.rb +5 -0
  159. data/lib/datadog/tracing/contrib/rack/header_tagging.rb +14 -4
  160. data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +4 -4
  161. data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +1 -1
  162. data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +1 -1
  163. data/lib/datadog/tracing/contrib/redis/instrumentation.rb +3 -38
  164. data/lib/datadog/tracing/contrib/redis/tags.rb +7 -2
  165. data/lib/datadog/tracing/contrib/redis/trace_middleware.rb +46 -33
  166. data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +1 -1
  167. data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +5 -0
  168. data/lib/datadog/tracing/contrib/sequel/utils.rb +5 -0
  169. data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +1 -1
  170. data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +1 -1
  171. data/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb +1 -1
  172. data/lib/datadog/tracing/contrib/utils/quantization/http.rb +2 -2
  173. data/lib/datadog/tracing/diagnostics/environment_logger.rb +6 -0
  174. data/lib/datadog/tracing/distributed/propagation.rb +13 -33
  175. data/lib/datadog/tracing/metadata/tagging.rb +3 -3
  176. data/lib/datadog/tracing/sync_writer.rb +3 -3
  177. data/lib/datadog/tracing/tracer.rb +2 -0
  178. data/lib/datadog/{core → tracing}/transport/http/api/instance.rb +1 -1
  179. data/lib/datadog/{core → tracing}/transport/http/api/spec.rb +1 -1
  180. data/lib/datadog/tracing/transport/http/api.rb +43 -0
  181. data/lib/datadog/{core → tracing}/transport/http/builder.rb +13 -68
  182. data/lib/datadog/tracing/transport/http/client.rb +57 -0
  183. data/lib/datadog/tracing/transport/http/statistics.rb +47 -0
  184. data/lib/datadog/tracing/transport/http/traces.rb +152 -0
  185. data/lib/datadog/tracing/transport/http.rb +124 -0
  186. data/lib/datadog/tracing/transport/io/client.rb +89 -0
  187. data/lib/datadog/tracing/transport/io/response.rb +27 -0
  188. data/lib/datadog/tracing/transport/io/traces.rb +101 -0
  189. data/lib/datadog/tracing/transport/io.rb +30 -0
  190. data/lib/datadog/tracing/transport/serializable_trace.rb +126 -0
  191. data/lib/datadog/tracing/transport/statistics.rb +77 -0
  192. data/lib/datadog/tracing/transport/trace_formatter.rb +209 -0
  193. data/lib/datadog/tracing/transport/traces.rb +224 -0
  194. data/lib/datadog/tracing/workers/trace_writer.rb +5 -3
  195. data/lib/datadog/tracing/workers.rb +3 -2
  196. data/lib/datadog/tracing/writer.rb +5 -2
  197. data/lib/ddtrace/transport/ext.rb +17 -15
  198. data/lib/ddtrace/version.rb +1 -1
  199. data/lib/ddtrace.rb +1 -1
  200. metadata +73 -96
  201. data/lib/datadog/ci/configuration/components.rb +0 -32
  202. data/lib/datadog/ci/configuration/settings.rb +0 -51
  203. data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +0 -35
  204. data/lib/datadog/ci/contrib/cucumber/ext.rb +0 -22
  205. data/lib/datadog/ci/contrib/cucumber/formatter.rb +0 -94
  206. data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +0 -28
  207. data/lib/datadog/ci/contrib/cucumber/integration.rb +0 -47
  208. data/lib/datadog/ci/contrib/cucumber/patcher.rb +0 -27
  209. data/lib/datadog/ci/contrib/minitest/configuration/settings.rb +0 -35
  210. data/lib/datadog/ci/contrib/minitest/ext.rb +0 -21
  211. data/lib/datadog/ci/contrib/minitest/integration.rb +0 -49
  212. data/lib/datadog/ci/contrib/minitest/patcher.rb +0 -27
  213. data/lib/datadog/ci/contrib/minitest/test_helper.rb +0 -68
  214. data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +0 -35
  215. data/lib/datadog/ci/contrib/rspec/example.rb +0 -68
  216. data/lib/datadog/ci/contrib/rspec/ext.rb +0 -21
  217. data/lib/datadog/ci/contrib/rspec/integration.rb +0 -48
  218. data/lib/datadog/ci/contrib/rspec/patcher.rb +0 -27
  219. data/lib/datadog/ci/ext/app_types.rb +0 -9
  220. data/lib/datadog/ci/ext/environment.rb +0 -575
  221. data/lib/datadog/ci/ext/settings.rb +0 -10
  222. data/lib/datadog/ci/ext/test.rb +0 -35
  223. data/lib/datadog/ci/extensions.rb +0 -19
  224. data/lib/datadog/ci/flush.rb +0 -38
  225. data/lib/datadog/ci/test.rb +0 -81
  226. data/lib/datadog/ci.rb +0 -21
  227. data/lib/datadog/core/configuration/dependency_resolver.rb +0 -28
  228. data/lib/datadog/core/configuration/option_definition_set.rb +0 -22
  229. data/lib/datadog/core/configuration/option_set.rb +0 -10
  230. data/lib/datadog/core/transport/config.rb +0 -58
  231. data/lib/datadog/core/transport/http/api.rb +0 -57
  232. data/lib/datadog/core/transport/http/client.rb +0 -45
  233. data/lib/datadog/core/transport/http/config.rb +0 -278
  234. data/lib/datadog/core/transport/http/negotiation.rb +0 -144
  235. data/lib/datadog/core/transport/http.rb +0 -169
  236. data/lib/datadog/core/utils/object_set.rb +0 -43
  237. data/lib/datadog/core/utils/string_table.rb +0 -47
  238. data/lib/datadog/profiling/backtrace_location.rb +0 -34
  239. data/lib/datadog/profiling/buffer.rb +0 -43
  240. data/lib/datadog/profiling/collectors/old_stack.rb +0 -301
  241. data/lib/datadog/profiling/encoding/profile.rb +0 -41
  242. data/lib/datadog/profiling/event.rb +0 -15
  243. data/lib/datadog/profiling/events/stack.rb +0 -82
  244. data/lib/datadog/profiling/old_recorder.rb +0 -107
  245. data/lib/datadog/profiling/pprof/builder.rb +0 -125
  246. data/lib/datadog/profiling/pprof/converter.rb +0 -102
  247. data/lib/datadog/profiling/pprof/message_set.rb +0 -16
  248. data/lib/datadog/profiling/pprof/payload.rb +0 -20
  249. data/lib/datadog/profiling/pprof/pprof.proto +0 -212
  250. data/lib/datadog/profiling/pprof/pprof_pb.rb +0 -81
  251. data/lib/datadog/profiling/pprof/stack_sample.rb +0 -139
  252. data/lib/datadog/profiling/pprof/string_table.rb +0 -12
  253. data/lib/datadog/profiling/pprof/template.rb +0 -118
  254. data/lib/datadog/profiling/trace_identifiers/ddtrace.rb +0 -43
  255. data/lib/datadog/profiling/trace_identifiers/helper.rb +0 -45
  256. data/lib/ddtrace/transport/http/adapters/net.rb +0 -168
  257. data/lib/ddtrace/transport/http/adapters/registry.rb +0 -27
  258. data/lib/ddtrace/transport/http/adapters/test.rb +0 -85
  259. data/lib/ddtrace/transport/http/adapters/unix_socket.rb +0 -77
  260. data/lib/ddtrace/transport/http/api/endpoint.rb +0 -29
  261. data/lib/ddtrace/transport/http/api/fallbacks.rb +0 -24
  262. data/lib/ddtrace/transport/http/api/instance.rb +0 -35
  263. data/lib/ddtrace/transport/http/api/map.rb +0 -16
  264. data/lib/ddtrace/transport/http/api/spec.rb +0 -17
  265. data/lib/ddtrace/transport/http/api.rb +0 -39
  266. data/lib/ddtrace/transport/http/builder.rb +0 -176
  267. data/lib/ddtrace/transport/http/client.rb +0 -52
  268. data/lib/ddtrace/transport/http/env.rb +0 -58
  269. data/lib/ddtrace/transport/http/response.rb +0 -58
  270. data/lib/ddtrace/transport/http/statistics.rb +0 -43
  271. data/lib/ddtrace/transport/http/traces.rb +0 -144
  272. data/lib/ddtrace/transport/http.rb +0 -117
  273. data/lib/ddtrace/transport/io/client.rb +0 -85
  274. data/lib/ddtrace/transport/io/response.rb +0 -25
  275. data/lib/ddtrace/transport/io/traces.rb +0 -99
  276. data/lib/ddtrace/transport/io.rb +0 -28
  277. data/lib/ddtrace/transport/parcel.rb +0 -20
  278. data/lib/ddtrace/transport/request.rb +0 -15
  279. data/lib/ddtrace/transport/response.rb +0 -60
  280. data/lib/ddtrace/transport/serializable_trace.rb +0 -122
  281. data/lib/ddtrace/transport/statistics.rb +0 -75
  282. data/lib/ddtrace/transport/trace_formatter.rb +0 -207
  283. data/lib/ddtrace/transport/traces.rb +0 -216
@@ -1,102 +0,0 @@
1
- require_relative '../ext'
2
-
3
- module Datadog
4
- module Profiling
5
- module Pprof
6
- # Base class for converters that convert profiling events to pprof
7
- class Converter
8
- attr_reader \
9
- :builder
10
-
11
- # Override in child class to define sample types
12
- # this converter uses when building samples.
13
- def self.sample_value_types
14
- raise NotImplementedError
15
- end
16
-
17
- def initialize(builder, sample_type_mappings)
18
- @builder = builder
19
- @sample_type_mappings = sample_type_mappings
20
- end
21
-
22
- def group_events(events)
23
- # Event grouping in format:
24
- # [key, EventGroup]
25
- event_groups = {}
26
-
27
- # Aggregate each event into a group
28
- # with identical properties, but different values.
29
- events.each do |event|
30
- key = yield(event)
31
- values = build_event_values(event)
32
-
33
- unless key.nil?
34
- if event_groups.key?(key)
35
- # Update existing group from event
36
- update_group(event_groups[key], event, values)
37
- else
38
- # Add new group
39
- event_groups[key] = new_group(event, values)
40
- end
41
- end
42
- end
43
-
44
- event_groups
45
- end
46
-
47
- def add_events!(events)
48
- raise NotImplementedError
49
- end
50
-
51
- def sample_value_index(type)
52
- index = @sample_type_mappings[type]
53
- raise UnknownSampleTypeMappingError, type unless index
54
-
55
- index
56
- end
57
-
58
- def build_event_values(event)
59
- # Build a value array that matches the length of the sample types
60
- # Populate all values with "no value" by default
61
- Array.new(@sample_type_mappings.length, Profiling::Ext::Pprof::SAMPLE_VALUE_NO_VALUE)
62
- end
63
-
64
- def debug_statistics
65
- # Empty; can be used by subclasses to report a string containing debug statistics to be logged
66
- end
67
-
68
- # Represents a grouped event
69
- # 'sample' is an example event object from the group.
70
- # 'values' is the summation of the group's sample values
71
- EventGroup = Struct.new(:sample, :values)
72
-
73
- # Error when the mapping of a sample type to value index is unknown
74
- class UnknownSampleTypeMappingError < StandardError
75
- attr_reader :type
76
-
77
- def initialize(type)
78
- @type = type
79
- end
80
-
81
- def message
82
- "Mapping for sample value type '#{type}' to index is unknown."
83
- end
84
- end
85
-
86
- protected
87
-
88
- def new_group(event, values)
89
- EventGroup.new(event, values)
90
- end
91
-
92
- def update_group(event_group, event, values)
93
- # Update values for group
94
- group_values = event_group.values
95
- group_values.each_with_index do |group_value, i|
96
- group_values[i] = group_value + values[i]
97
- end
98
- end
99
- end
100
- end
101
- end
102
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../core/utils/object_set'
4
-
5
- module Datadog
6
- module Profiling
7
- module Pprof
8
- # Acts as a unique dictionary of protobuf messages
9
- class MessageSet < Core::Utils::ObjectSet
10
- def messages
11
- objects
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Datadog
4
- module Profiling
5
- module Pprof
6
- # Pprof output data.
7
- # Includes encoded data and list of types.
8
- Payload = Struct.new(:data, :types) do
9
- def initialize(data, types)
10
- super
11
- self.types = types || []
12
- end
13
-
14
- def to_s
15
- data
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,212 +0,0 @@
1
- // Copyright 2016 Google Inc. All Rights Reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- // Profile is a common stacktrace profile format.
16
- //
17
- // Measurements represented with this format should follow the
18
- // following conventions:
19
- //
20
- // - Consumers should treat unset optional fields as if they had been
21
- // set with their default value.
22
- //
23
- // - When possible, measurements should be stored in "unsampled" form
24
- // that is most useful to humans. There should be enough
25
- // information present to determine the original sampled values.
26
- //
27
- // - On-disk, the serialized proto must be gzip-compressed.
28
- //
29
- // - The profile is represented as a set of samples, where each sample
30
- // references a sequence of locations, and where each location belongs
31
- // to a mapping.
32
- // - There is a N->1 relationship from sample.location_id entries to
33
- // locations. For every sample.location_id entry there must be a
34
- // unique Location with that id.
35
- // - There is an optional N->1 relationship from locations to
36
- // mappings. For every nonzero Location.mapping_id there must be a
37
- // unique Mapping with that id.
38
-
39
- syntax = "proto3";
40
-
41
- package perftools.profiles;
42
-
43
- option java_package = "com.google.perftools.profiles";
44
- option java_outer_classname = "ProfileProto";
45
-
46
- message Profile {
47
- // A description of the samples associated with each Sample.value.
48
- // For a cpu profile this might be:
49
- // [["cpu","nanoseconds"]] or [["wall","seconds"]] or [["syscall","count"]]
50
- // For a heap profile, this might be:
51
- // [["allocations","count"], ["space","bytes"]],
52
- // If one of the values represents the number of events represented
53
- // by the sample, by convention it should be at index 0 and use
54
- // sample_type.unit == "count".
55
- repeated ValueType sample_type = 1;
56
- // The set of samples recorded in this profile.
57
- repeated Sample sample = 2;
58
- // Mapping from address ranges to the image/binary/library mapped
59
- // into that address range. mapping[0] will be the main binary.
60
- repeated Mapping mapping = 3;
61
- // Useful program location
62
- repeated Location location = 4;
63
- // Functions referenced by locations
64
- repeated Function function = 5;
65
- // A common table for strings referenced by various messages.
66
- // string_table[0] must always be "".
67
- repeated string string_table = 6;
68
- // frames with Function.function_name fully matching the following
69
- // regexp will be dropped from the samples, along with their successors.
70
- int64 drop_frames = 7; // Index into string table.
71
- // frames with Function.function_name fully matching the following
72
- // regexp will be kept, even if it matches drop_functions.
73
- int64 keep_frames = 8; // Index into string table.
74
-
75
- // The following fields are informational, do not affect
76
- // interpretation of results.
77
-
78
- // Time of collection (UTC) represented as nanoseconds past the epoch.
79
- int64 time_nanos = 9;
80
- // Duration of the profile, if a duration makes sense.
81
- int64 duration_nanos = 10;
82
- // The kind of events between sampled ocurrences.
83
- // e.g [ "cpu","cycles" ] or [ "heap","bytes" ]
84
- ValueType period_type = 11;
85
- // The number of events between sampled occurrences.
86
- int64 period = 12;
87
- // Freeform text associated to the profile.
88
- repeated int64 comment = 13; // Indices into string table.
89
- // Index into the string table of the type of the preferred sample
90
- // value. If unset, clients should default to the last sample value.
91
- int64 default_sample_type = 14;
92
- }
93
-
94
- // ValueType describes the semantics and measurement units of a value.
95
- message ValueType {
96
- int64 type = 1; // Index into string table.
97
- int64 unit = 2; // Index into string table.
98
- }
99
-
100
- // Each Sample records values encountered in some program
101
- // context. The program context is typically a stack trace, perhaps
102
- // augmented with auxiliary information like the thread-id, some
103
- // indicator of a higher level request being handled etc.
104
- message Sample {
105
- // The ids recorded here correspond to a Profile.location.id.
106
- // The leaf is at location_id[0].
107
- repeated uint64 location_id = 1;
108
- // The type and unit of each value is defined by the corresponding
109
- // entry in Profile.sample_type. All samples must have the same
110
- // number of values, the same as the length of Profile.sample_type.
111
- // When aggregating multiple samples into a single sample, the
112
- // result has a list of values that is the elemntwise sum of the
113
- // lists of the originals.
114
- repeated int64 value = 2;
115
- // label includes additional context for this sample. It can include
116
- // things like a thread id, allocation size, etc
117
- repeated Label label = 3;
118
- }
119
-
120
- message Label {
121
- int64 key = 1; // Index into string table
122
-
123
- // At most one of the following must be present
124
- int64 str = 2; // Index into string table
125
- int64 num = 3;
126
-
127
- // Should only be present when num is present.
128
- // Specifies the units of num.
129
- // Use arbitrary string (for example, "requests") as a custom count unit.
130
- // If no unit is specified, consumer may apply heuristic to deduce the unit.
131
- // Consumers may also interpret units like "bytes" and "kilobytes" as memory
132
- // units and units like "seconds" and "nanoseconds" as time units,
133
- // and apply appropriate unit conversions to these.
134
- int64 num_unit = 4; // Index into string table
135
- }
136
-
137
- message Mapping {
138
- // Unique nonzero id for the mapping.
139
- uint64 id = 1;
140
- // Address at which the binary (or DLL) is loaded into memory.
141
- uint64 memory_start = 2;
142
- // The limit of the address range occupied by this mapping.
143
- uint64 memory_limit = 3;
144
- // Offset in the binary that corresponds to the first mapped address.
145
- uint64 file_offset = 4;
146
- // The object this entry is loaded from. This can be a filename on
147
- // disk for the main binary and shared libraries, or virtual
148
- // abstractions like "[vdso]".
149
- int64 filename = 5; // Index into string table
150
- // A string that uniquely identifies a particular program version
151
- // with high probability. E.g., for binaries generated by GNU tools,
152
- // it could be the contents of the .note.gnu.build-id field.
153
- int64 build_id = 6; // Index into string table
154
-
155
- // The following fields indicate the resolution of symbolic info.
156
- bool has_functions = 7;
157
- bool has_filenames = 8;
158
- bool has_line_numbers = 9;
159
- bool has_inline_frames = 10;
160
- }
161
-
162
- // Describes function and line table debug information.
163
- message Location {
164
- // Unique nonzero id for the location. A profile could use
165
- // instruction addresses or any integer sequence as ids.
166
- uint64 id = 1;
167
- // The id of the corresponding profile.Mapping for this location.
168
- // It can be unset if the mapping is unknown or not applicable for
169
- // this profile type.
170
- uint64 mapping_id = 2;
171
- // The instruction address for this location, if available. It
172
- // should be within [Mapping.memory_start...Mapping.memory_limit]
173
- // for the corresponding mapping. A non-leaf address may be in the
174
- // middle of a call instruction. It is up to display tools to find
175
- // the beginning of the instruction if necessary.
176
- uint64 address = 3;
177
- // Multiple line indicates this location has inlined functions,
178
- // where the last entry represents the caller into which the
179
- // preceding entries were inlined.
180
- //
181
- // E.g., if memcpy() is inlined into printf:
182
- // line[0].function_name == "memcpy"
183
- // line[1].function_name == "printf"
184
- repeated Line line = 4;
185
- // Provides an indication that multiple symbols map to this location's
186
- // address, for example due to identical code folding by the linker. In that
187
- // case the line information above represents one of the multiple
188
- // symbols. This field must be recomputed when the symbolization state of the
189
- // profile changes.
190
- bool is_folded = 5;
191
- }
192
-
193
- message Line {
194
- // The id of the corresponding profile.Function for this line.
195
- uint64 function_id = 1;
196
- // Line number in source code.
197
- int64 line = 2;
198
- }
199
-
200
- message Function {
201
- // Unique nonzero id for the function.
202
- uint64 id = 1;
203
- // Name of the function, in human-readable form if available.
204
- int64 name = 2; // Index into string table
205
- // Name of the function, as identified by the system.
206
- // For instance, it can be a C++ mangled name.
207
- int64 system_name = 3; // Index into string table
208
- // Source file containing the function.
209
- int64 filename = 4; // Index into string table
210
- // Line number in source file.
211
- int64 start_line = 5;
212
- }
@@ -1,81 +0,0 @@
1
- # Generated by the protocol buffer compiler. DO NOT EDIT!
2
- # source: lib/datadog/profiling/pprof/pprof.proto
3
-
4
- require 'google/protobuf'
5
-
6
- Google::Protobuf::DescriptorPool.generated_pool.build do
7
- add_message "perftools.profiles.Profile" do
8
- repeated :sample_type, :message, 1, "perftools.profiles.ValueType"
9
- repeated :sample, :message, 2, "perftools.profiles.Sample"
10
- repeated :mapping, :message, 3, "perftools.profiles.Mapping"
11
- repeated :location, :message, 4, "perftools.profiles.Location"
12
- repeated :function, :message, 5, "perftools.profiles.Function"
13
- repeated :string_table, :string, 6
14
- optional :drop_frames, :int64, 7
15
- optional :keep_frames, :int64, 8
16
- optional :time_nanos, :int64, 9
17
- optional :duration_nanos, :int64, 10
18
- optional :period_type, :message, 11, "perftools.profiles.ValueType"
19
- optional :period, :int64, 12
20
- repeated :comment, :int64, 13
21
- optional :default_sample_type, :int64, 14
22
- end
23
- add_message "perftools.profiles.ValueType" do
24
- optional :type, :int64, 1
25
- optional :unit, :int64, 2
26
- end
27
- add_message "perftools.profiles.Sample" do
28
- repeated :location_id, :uint64, 1
29
- repeated :value, :int64, 2
30
- repeated :label, :message, 3, "perftools.profiles.Label"
31
- end
32
- add_message "perftools.profiles.Label" do
33
- optional :key, :int64, 1
34
- optional :str, :int64, 2
35
- optional :num, :int64, 3
36
- optional :num_unit, :int64, 4
37
- end
38
- add_message "perftools.profiles.Mapping" do
39
- optional :id, :uint64, 1
40
- optional :memory_start, :uint64, 2
41
- optional :memory_limit, :uint64, 3
42
- optional :file_offset, :uint64, 4
43
- optional :filename, :int64, 5
44
- optional :build_id, :int64, 6
45
- optional :has_functions, :bool, 7
46
- optional :has_filenames, :bool, 8
47
- optional :has_line_numbers, :bool, 9
48
- optional :has_inline_frames, :bool, 10
49
- end
50
- add_message "perftools.profiles.Location" do
51
- optional :id, :uint64, 1
52
- optional :mapping_id, :uint64, 2
53
- optional :address, :uint64, 3
54
- repeated :line, :message, 4, "perftools.profiles.Line"
55
- optional :is_folded, :bool, 5
56
- end
57
- add_message "perftools.profiles.Line" do
58
- optional :function_id, :uint64, 1
59
- optional :line, :int64, 2
60
- end
61
- add_message "perftools.profiles.Function" do
62
- optional :id, :uint64, 1
63
- optional :name, :int64, 2
64
- optional :system_name, :int64, 3
65
- optional :filename, :int64, 4
66
- optional :start_line, :int64, 5
67
- end
68
- end
69
-
70
- module Perftools
71
- module Profiles
72
- Profile = Google::Protobuf::DescriptorPool.generated_pool.lookup("perftools.profiles.Profile").msgclass
73
- ValueType = Google::Protobuf::DescriptorPool.generated_pool.lookup("perftools.profiles.ValueType").msgclass
74
- Sample = Google::Protobuf::DescriptorPool.generated_pool.lookup("perftools.profiles.Sample").msgclass
75
- Label = Google::Protobuf::DescriptorPool.generated_pool.lookup("perftools.profiles.Label").msgclass
76
- Mapping = Google::Protobuf::DescriptorPool.generated_pool.lookup("perftools.profiles.Mapping").msgclass
77
- Location = Google::Protobuf::DescriptorPool.generated_pool.lookup("perftools.profiles.Location").msgclass
78
- Line = Google::Protobuf::DescriptorPool.generated_pool.lookup("perftools.profiles.Line").msgclass
79
- Function = Google::Protobuf::DescriptorPool.generated_pool.lookup("perftools.profiles.Function").msgclass
80
- end
81
- end
@@ -1,139 +0,0 @@
1
- require_relative '../ext'
2
- require_relative '../events/stack'
3
- require_relative 'builder'
4
- require_relative 'converter'
5
-
6
- module Datadog
7
- module Profiling
8
- module Pprof
9
- # Builds a profile from a StackSample
10
- #
11
- # NOTE: This class may appear stateless but is in fact stateful; a new instance should be created for every
12
- # encoded profile.
13
- class StackSample < Converter
14
- SAMPLE_TYPES = {
15
- cpu_time_ns: [
16
- Profiling::Ext::Pprof::VALUE_TYPE_CPU,
17
- Profiling::Ext::Pprof::VALUE_UNIT_NANOSECONDS
18
- ],
19
- wall_time_ns: [
20
- Profiling::Ext::Pprof::VALUE_TYPE_WALL,
21
- Profiling::Ext::Pprof::VALUE_UNIT_NANOSECONDS
22
- ]
23
- }.freeze
24
-
25
- def self.sample_value_types
26
- SAMPLE_TYPES
27
- end
28
-
29
- def initialize(*_)
30
- super
31
-
32
- @most_recent_trace_samples = {}
33
- @processed_unique_stacks = 0
34
- @processed_with_trace = 0
35
- end
36
-
37
- def add_events!(stack_samples)
38
- new_samples = build_samples(stack_samples)
39
- builder.samples.concat(new_samples)
40
- end
41
-
42
- def stack_sample_group_key(stack_sample)
43
- # We want to make sure we have the most recent sample for any trace.
44
- # (This is done here to save an iteration over all samples.)
45
- update_most_recent_trace_sample(stack_sample)
46
-
47
- stack_sample.hash
48
- end
49
-
50
- # Track the most recent sample for each trace (identified by root span id)
51
- def update_most_recent_trace_sample(stack_sample)
52
- return unless stack_sample.root_span_id && stack_sample.trace_resource
53
-
54
- # Update trace resource with most recent value
55
- if (most_recent_trace_sample = @most_recent_trace_samples[stack_sample.root_span_id])
56
- if most_recent_trace_sample.timestamp < stack_sample.timestamp
57
- @most_recent_trace_samples[stack_sample.root_span_id] = stack_sample
58
- end
59
- else
60
- # Add trace resource
61
- @most_recent_trace_samples[stack_sample.root_span_id] = stack_sample
62
- end
63
- end
64
-
65
- def build_samples(stack_samples)
66
- groups = group_events(stack_samples, &method(:stack_sample_group_key))
67
- groups.collect do |_group_key, group|
68
- @processed_unique_stacks += 1
69
- build_sample(group.sample, group.values)
70
- end
71
- end
72
-
73
- def build_sample(stack_sample, values)
74
- locations = builder.build_locations(
75
- stack_sample.frames,
76
- stack_sample.total_frame_count
77
- )
78
-
79
- Perftools::Profiles::Sample.new(
80
- location_id: locations.collect { |location| location['id'.freeze] },
81
- value: values,
82
- label: build_sample_labels(stack_sample)
83
- )
84
- end
85
-
86
- def build_event_values(stack_sample)
87
- no_value = Profiling::Ext::Pprof::SAMPLE_VALUE_NO_VALUE
88
- values = super(stack_sample)
89
- values[sample_value_index(:cpu_time_ns)] = stack_sample.cpu_time_interval_ns || no_value
90
- values[sample_value_index(:wall_time_ns)] = stack_sample.wall_time_interval_ns || no_value
91
- values
92
- end
93
-
94
- def build_sample_labels(stack_sample)
95
- labels = [
96
- Perftools::Profiles::Label.new(
97
- key: builder.string_table.fetch(Profiling::Ext::Pprof::LABEL_KEY_THREAD_ID),
98
- str: builder.string_table.fetch(stack_sample.thread_id.to_s)
99
- )
100
- ]
101
-
102
- root_span_id = stack_sample.root_span_id || 0
103
- span_id = stack_sample.span_id || 0
104
-
105
- if root_span_id != 0 && span_id != 0
106
- @processed_with_trace += 1
107
-
108
- labels << Perftools::Profiles::Label.new(
109
- key: builder.string_table.fetch(Profiling::Ext::Pprof::LABEL_KEY_LOCAL_ROOT_SPAN_ID),
110
- str: builder.string_table.fetch(root_span_id.to_s)
111
- )
112
-
113
- labels << Perftools::Profiles::Label.new(
114
- key: builder.string_table.fetch(Profiling::Ext::Pprof::LABEL_KEY_SPAN_ID),
115
- str: builder.string_table.fetch(span_id.to_s)
116
- )
117
-
118
- # Use most up-to-date trace resource, if available.
119
- # Otherwise, use the trace resource provided.
120
- trace_resource = @most_recent_trace_samples.fetch(stack_sample.root_span_id, stack_sample).trace_resource
121
-
122
- if trace_resource && !trace_resource.empty?
123
- labels << Perftools::Profiles::Label.new(
124
- key: builder.string_table.fetch(Profiling::Ext::Pprof::LABEL_KEY_TRACE_ENDPOINT),
125
- str: builder.string_table.fetch(trace_resource)
126
- )
127
- end
128
- end
129
-
130
- labels
131
- end
132
-
133
- def debug_statistics
134
- "unique stacks: #{@processed_unique_stacks}, of which had active traces: #{@processed_with_trace}"
135
- end
136
- end
137
- end
138
- end
139
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../core/utils/string_table'
4
-
5
- module Datadog
6
- module Profiling
7
- module Pprof
8
- # Tracks strings and returns IDs
9
- class StringTable < Core::Utils::StringTable; end
10
- end
11
- end
12
- end