ddtrace 1.14.0 → 1.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (270) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +178 -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 +61 -2
  31. data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +8 -6
  32. data/lib/datadog/appsec/contrib/rack/reactive/request.rb +2 -7
  33. data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +2 -5
  34. data/lib/datadog/appsec/contrib/rack/reactive/response.rb +2 -5
  35. data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +3 -2
  36. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +23 -9
  37. data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +3 -2
  38. data/lib/datadog/appsec/contrib/rails/patcher.rb +9 -3
  39. data/lib/datadog/appsec/contrib/rails/reactive/action.rb +2 -5
  40. data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +6 -4
  41. data/lib/datadog/appsec/contrib/sinatra/patcher.rb +13 -7
  42. data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +2 -5
  43. data/lib/datadog/appsec/event.rb +106 -50
  44. data/lib/datadog/appsec/monitor/gateway/watcher.rb +3 -3
  45. data/lib/datadog/appsec/monitor/reactive/set_user.rb +2 -5
  46. data/lib/datadog/appsec/processor/actions.rb +49 -0
  47. data/lib/datadog/appsec/processor/rule_merger.rb +22 -2
  48. data/lib/datadog/appsec/processor.rb +34 -6
  49. data/lib/datadog/appsec/remote.rb +4 -1
  50. data/lib/datadog/appsec/response.rb +82 -4
  51. data/lib/datadog/appsec/sample_rate.rb +21 -0
  52. data/lib/datadog/appsec.rb +2 -2
  53. data/lib/datadog/core/configuration/agent_settings_resolver.rb +29 -24
  54. data/lib/datadog/core/configuration/base.rb +1 -11
  55. data/lib/datadog/core/configuration/components.rb +7 -2
  56. data/lib/datadog/core/configuration/ext.rb +21 -0
  57. data/lib/datadog/core/configuration/option.rb +2 -4
  58. data/lib/datadog/core/configuration/option_definition.rb +17 -41
  59. data/lib/datadog/core/configuration/options.rb +5 -5
  60. data/lib/datadog/core/configuration/settings.rb +47 -45
  61. data/lib/datadog/core/environment/execution.rb +47 -9
  62. data/lib/datadog/core/environment/variable_helpers.rb +0 -69
  63. data/lib/datadog/core/error.rb +1 -0
  64. data/lib/datadog/core/git/ext.rb +2 -0
  65. data/lib/datadog/core/remote/client/capabilities.rb +1 -1
  66. data/lib/datadog/core/remote/component.rb +2 -2
  67. data/lib/datadog/core/remote/negotiation.rb +2 -2
  68. data/lib/datadog/core/remote/transport/config.rb +60 -0
  69. data/lib/datadog/core/remote/transport/http/api/instance.rb +39 -0
  70. data/lib/datadog/core/remote/transport/http/api/spec.rb +21 -0
  71. data/lib/datadog/core/remote/transport/http/api.rb +58 -0
  72. data/lib/datadog/core/remote/transport/http/builder.rb +219 -0
  73. data/lib/datadog/core/remote/transport/http/client.rb +48 -0
  74. data/lib/datadog/core/remote/transport/http/config.rb +280 -0
  75. data/lib/datadog/core/remote/transport/http/negotiation.rb +146 -0
  76. data/lib/datadog/core/remote/transport/http.rb +179 -0
  77. data/lib/datadog/core/{transport → remote/transport}/negotiation.rb +25 -23
  78. data/lib/datadog/core/telemetry/collector.rb +3 -2
  79. data/lib/datadog/core/telemetry/http/transport.rb +2 -1
  80. data/lib/datadog/core/transport/ext.rb +47 -0
  81. data/lib/datadog/core/transport/http/adapters/net.rb +168 -0
  82. data/lib/datadog/core/transport/http/adapters/registry.rb +29 -0
  83. data/lib/datadog/core/transport/http/adapters/test.rb +89 -0
  84. data/lib/datadog/core/transport/http/adapters/unix_socket.rb +83 -0
  85. data/lib/datadog/core/transport/http/api/endpoint.rb +31 -0
  86. data/lib/datadog/core/transport/http/api/fallbacks.rb +26 -0
  87. data/lib/datadog/core/transport/http/api/map.rb +18 -0
  88. data/lib/datadog/core/transport/http/env.rb +62 -0
  89. data/lib/datadog/core/transport/http/response.rb +60 -0
  90. data/lib/datadog/core/transport/parcel.rb +22 -0
  91. data/lib/datadog/core/transport/request.rb +17 -0
  92. data/lib/datadog/core/transport/response.rb +64 -0
  93. data/lib/datadog/core/workers/polling.rb +2 -2
  94. data/lib/datadog/opentelemetry/api/context.rb +10 -3
  95. data/lib/datadog/opentelemetry/sdk/propagator.rb +2 -1
  96. data/lib/datadog/opentelemetry/sdk/span_processor.rb +14 -2
  97. data/lib/datadog/opentelemetry/sdk/trace/span.rb +68 -0
  98. data/lib/datadog/opentelemetry/trace.rb +58 -0
  99. data/lib/datadog/opentelemetry.rb +1 -0
  100. data/lib/datadog/opentracer.rb +9 -0
  101. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +12 -18
  102. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -1
  103. data/lib/datadog/profiling/collectors/thread_context.rb +9 -1
  104. data/lib/datadog/profiling/component.rb +24 -99
  105. data/lib/datadog/profiling/ext.rb +0 -12
  106. data/lib/datadog/profiling/flush.rb +0 -3
  107. data/lib/datadog/profiling/http_transport.rb +6 -3
  108. data/lib/datadog/profiling/native_extension.rb +0 -21
  109. data/lib/datadog/profiling/profiler.rb +11 -12
  110. data/lib/datadog/profiling.rb +8 -81
  111. data/lib/datadog/tracing/component.rb +10 -4
  112. data/lib/datadog/tracing/configuration/agent_settings_resolver.rb +13 -0
  113. data/lib/datadog/tracing/configuration/ext.rb +4 -2
  114. data/lib/datadog/tracing/configuration/settings.rb +14 -7
  115. data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +1 -1
  116. data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +1 -1
  117. data/lib/datadog/tracing/contrib/active_record/events/sql.rb +4 -0
  118. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +104 -197
  119. data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +3 -0
  120. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +7 -0
  121. data/lib/datadog/tracing/contrib/configuration/settings.rb +1 -1
  122. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +6 -0
  123. data/lib/datadog/tracing/contrib/dalli/ext.rb +7 -0
  124. data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +9 -2
  125. data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +1 -1
  126. data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +5 -0
  127. data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +5 -0
  128. data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +8 -0
  129. data/lib/datadog/tracing/contrib/excon/middleware.rb +5 -0
  130. data/lib/datadog/tracing/contrib/ext.rb +3 -0
  131. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +1 -1
  132. data/lib/datadog/tracing/contrib/faraday/middleware.rb +5 -0
  133. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +21 -1
  134. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +11 -1
  135. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +18 -0
  136. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor.rb +0 -4
  137. data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +3 -3
  138. data/lib/datadog/tracing/contrib/http/instrumentation.rb +5 -0
  139. data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +5 -0
  140. data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +5 -0
  141. data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +7 -0
  142. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +13 -3
  143. data/lib/datadog/tracing/contrib/opensearch/integration.rb +2 -2
  144. data/lib/datadog/tracing/contrib/opensearch/patcher.rb +7 -0
  145. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +5 -0
  146. data/lib/datadog/tracing/contrib/presto/instrumentation.rb +5 -0
  147. data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +1 -1
  148. data/lib/datadog/tracing/contrib/que/configuration/settings.rb +1 -1
  149. data/lib/datadog/tracing/contrib/racecar/event.rb +5 -0
  150. data/lib/datadog/tracing/contrib/rack/header_tagging.rb +14 -4
  151. data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +4 -4
  152. data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +1 -1
  153. data/lib/datadog/tracing/contrib/redis/tags.rb +5 -0
  154. data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +1 -1
  155. data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +5 -0
  156. data/lib/datadog/tracing/contrib/sequel/utils.rb +5 -0
  157. data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +1 -1
  158. data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +1 -1
  159. data/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb +1 -1
  160. data/lib/datadog/tracing/contrib/utils/quantization/http.rb +2 -2
  161. data/lib/datadog/tracing/distributed/propagation.rb +13 -33
  162. data/lib/datadog/tracing/metadata/tagging.rb +3 -3
  163. data/lib/datadog/tracing/sync_writer.rb +3 -3
  164. data/lib/datadog/tracing/tracer.rb +2 -0
  165. data/lib/datadog/{core → tracing}/transport/http/api/instance.rb +1 -1
  166. data/lib/datadog/{core → tracing}/transport/http/api/spec.rb +1 -1
  167. data/lib/datadog/tracing/transport/http/api.rb +43 -0
  168. data/lib/datadog/{core → tracing}/transport/http/builder.rb +13 -68
  169. data/lib/datadog/tracing/transport/http/client.rb +57 -0
  170. data/lib/datadog/tracing/transport/http/statistics.rb +47 -0
  171. data/lib/datadog/tracing/transport/http/traces.rb +152 -0
  172. data/lib/datadog/tracing/transport/http.rb +124 -0
  173. data/lib/datadog/tracing/transport/io/client.rb +89 -0
  174. data/lib/datadog/tracing/transport/io/response.rb +27 -0
  175. data/lib/datadog/tracing/transport/io/traces.rb +101 -0
  176. data/lib/datadog/tracing/transport/io.rb +30 -0
  177. data/lib/datadog/tracing/transport/serializable_trace.rb +126 -0
  178. data/lib/datadog/tracing/transport/statistics.rb +77 -0
  179. data/lib/datadog/tracing/transport/trace_formatter.rb +209 -0
  180. data/lib/datadog/tracing/transport/traces.rb +224 -0
  181. data/lib/datadog/tracing/workers/trace_writer.rb +5 -3
  182. data/lib/datadog/tracing/workers.rb +3 -2
  183. data/lib/datadog/tracing/writer.rb +5 -2
  184. data/lib/ddtrace/transport/ext.rb +17 -15
  185. data/lib/ddtrace/version.rb +1 -1
  186. data/lib/ddtrace.rb +1 -1
  187. metadata +72 -96
  188. data/lib/datadog/ci/configuration/components.rb +0 -32
  189. data/lib/datadog/ci/configuration/settings.rb +0 -51
  190. data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +0 -35
  191. data/lib/datadog/ci/contrib/cucumber/ext.rb +0 -22
  192. data/lib/datadog/ci/contrib/cucumber/formatter.rb +0 -94
  193. data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +0 -28
  194. data/lib/datadog/ci/contrib/cucumber/integration.rb +0 -47
  195. data/lib/datadog/ci/contrib/cucumber/patcher.rb +0 -27
  196. data/lib/datadog/ci/contrib/minitest/configuration/settings.rb +0 -35
  197. data/lib/datadog/ci/contrib/minitest/ext.rb +0 -21
  198. data/lib/datadog/ci/contrib/minitest/integration.rb +0 -49
  199. data/lib/datadog/ci/contrib/minitest/patcher.rb +0 -27
  200. data/lib/datadog/ci/contrib/minitest/test_helper.rb +0 -68
  201. data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +0 -35
  202. data/lib/datadog/ci/contrib/rspec/example.rb +0 -68
  203. data/lib/datadog/ci/contrib/rspec/ext.rb +0 -21
  204. data/lib/datadog/ci/contrib/rspec/integration.rb +0 -48
  205. data/lib/datadog/ci/contrib/rspec/patcher.rb +0 -27
  206. data/lib/datadog/ci/ext/app_types.rb +0 -9
  207. data/lib/datadog/ci/ext/environment.rb +0 -575
  208. data/lib/datadog/ci/ext/settings.rb +0 -10
  209. data/lib/datadog/ci/ext/test.rb +0 -35
  210. data/lib/datadog/ci/extensions.rb +0 -19
  211. data/lib/datadog/ci/flush.rb +0 -38
  212. data/lib/datadog/ci/test.rb +0 -81
  213. data/lib/datadog/ci.rb +0 -21
  214. data/lib/datadog/core/configuration/dependency_resolver.rb +0 -28
  215. data/lib/datadog/core/configuration/option_definition_set.rb +0 -22
  216. data/lib/datadog/core/configuration/option_set.rb +0 -10
  217. data/lib/datadog/core/transport/config.rb +0 -58
  218. data/lib/datadog/core/transport/http/api.rb +0 -57
  219. data/lib/datadog/core/transport/http/client.rb +0 -45
  220. data/lib/datadog/core/transport/http/config.rb +0 -278
  221. data/lib/datadog/core/transport/http/negotiation.rb +0 -144
  222. data/lib/datadog/core/transport/http.rb +0 -169
  223. data/lib/datadog/core/utils/object_set.rb +0 -43
  224. data/lib/datadog/core/utils/string_table.rb +0 -47
  225. data/lib/datadog/profiling/backtrace_location.rb +0 -34
  226. data/lib/datadog/profiling/buffer.rb +0 -43
  227. data/lib/datadog/profiling/collectors/old_stack.rb +0 -301
  228. data/lib/datadog/profiling/encoding/profile.rb +0 -41
  229. data/lib/datadog/profiling/event.rb +0 -15
  230. data/lib/datadog/profiling/events/stack.rb +0 -82
  231. data/lib/datadog/profiling/old_recorder.rb +0 -107
  232. data/lib/datadog/profiling/pprof/builder.rb +0 -125
  233. data/lib/datadog/profiling/pprof/converter.rb +0 -102
  234. data/lib/datadog/profiling/pprof/message_set.rb +0 -16
  235. data/lib/datadog/profiling/pprof/payload.rb +0 -20
  236. data/lib/datadog/profiling/pprof/pprof.proto +0 -212
  237. data/lib/datadog/profiling/pprof/pprof_pb.rb +0 -81
  238. data/lib/datadog/profiling/pprof/stack_sample.rb +0 -139
  239. data/lib/datadog/profiling/pprof/string_table.rb +0 -12
  240. data/lib/datadog/profiling/pprof/template.rb +0 -118
  241. data/lib/datadog/profiling/trace_identifiers/ddtrace.rb +0 -43
  242. data/lib/datadog/profiling/trace_identifiers/helper.rb +0 -45
  243. data/lib/ddtrace/transport/http/adapters/net.rb +0 -168
  244. data/lib/ddtrace/transport/http/adapters/registry.rb +0 -27
  245. data/lib/ddtrace/transport/http/adapters/test.rb +0 -85
  246. data/lib/ddtrace/transport/http/adapters/unix_socket.rb +0 -77
  247. data/lib/ddtrace/transport/http/api/endpoint.rb +0 -29
  248. data/lib/ddtrace/transport/http/api/fallbacks.rb +0 -24
  249. data/lib/ddtrace/transport/http/api/instance.rb +0 -35
  250. data/lib/ddtrace/transport/http/api/map.rb +0 -16
  251. data/lib/ddtrace/transport/http/api/spec.rb +0 -17
  252. data/lib/ddtrace/transport/http/api.rb +0 -39
  253. data/lib/ddtrace/transport/http/builder.rb +0 -176
  254. data/lib/ddtrace/transport/http/client.rb +0 -52
  255. data/lib/ddtrace/transport/http/env.rb +0 -58
  256. data/lib/ddtrace/transport/http/response.rb +0 -58
  257. data/lib/ddtrace/transport/http/statistics.rb +0 -43
  258. data/lib/ddtrace/transport/http/traces.rb +0 -144
  259. data/lib/ddtrace/transport/http.rb +0 -117
  260. data/lib/ddtrace/transport/io/client.rb +0 -85
  261. data/lib/ddtrace/transport/io/response.rb +0 -25
  262. data/lib/ddtrace/transport/io/traces.rb +0 -99
  263. data/lib/ddtrace/transport/io.rb +0 -28
  264. data/lib/ddtrace/transport/parcel.rb +0 -20
  265. data/lib/ddtrace/transport/request.rb +0 -15
  266. data/lib/ddtrace/transport/response.rb +0 -60
  267. data/lib/ddtrace/transport/serializable_trace.rb +0 -122
  268. data/lib/ddtrace/transport/statistics.rb +0 -75
  269. data/lib/ddtrace/transport/trace_formatter.rb +0 -207
  270. data/lib/ddtrace/transport/traces.rb +0 -216
@@ -1,85 +0,0 @@
1
- require_relative '../statistics'
2
- require_relative 'response'
3
-
4
- module Datadog
5
- module Transport
6
- module IO
7
- # Encodes and writes tracer data to IO
8
- class Client
9
- include Transport::Statistics
10
-
11
- attr_reader \
12
- :encoder,
13
- :out
14
-
15
- def initialize(out, encoder, options = {})
16
- @out = out
17
- @encoder = encoder
18
-
19
- @request_block = options.fetch(:request, method(:send_default_request))
20
- @encode_block = options.fetch(:encode, method(:encode_data))
21
- @write_block = options.fetch(:write, method(:write_data))
22
- @response_block = options.fetch(:response, method(:build_response))
23
- end
24
-
25
- def send_request(request)
26
- # Write data to IO
27
- # If block is given, allow it to handle writing
28
- # Otherwise do a standard encode/write/response.
29
- response = if block_given?
30
- yield(out, request)
31
- else
32
- @request_block.call(out, request)
33
- end
34
-
35
- # Update statistics
36
- update_stats_from_response!(response)
37
-
38
- # Return response
39
- response
40
- rescue StandardError => e
41
- message =
42
- "Internal error during IO transport request. Cause: #{e.class.name} #{e.message} " \
43
- "Location: #{Array(e.backtrace).first}"
44
-
45
- # Log error
46
- if stats.consecutive_errors > 0
47
- Datadog.logger.debug(message)
48
- else
49
- Datadog.logger.error(message)
50
- end
51
-
52
- # Update statistics
53
- update_stats_from_exception!(e)
54
-
55
- InternalErrorResponse.new(e)
56
- end
57
-
58
- def encode_data(encoder, request)
59
- request.parcel.encode_with(encoder)
60
- end
61
-
62
- def write_data(out, data)
63
- out.puts(data)
64
- end
65
-
66
- def build_response(_request, _data, result)
67
- IO::Response.new(result)
68
- end
69
-
70
- private
71
-
72
- def send_default_request(out, request)
73
- # Encode data
74
- data = @encode_block.call(encoder, request)
75
-
76
- # Write to IO
77
- result = @write_block.call(out, data)
78
-
79
- # Generate a response
80
- @response_block.call(request, data, result)
81
- end
82
- end
83
- end
84
- end
85
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../response'
4
-
5
- module Datadog
6
- module Transport
7
- module IO
8
- # Response from HTTP transport for traces
9
- class Response
10
- include Transport::Response
11
-
12
- attr_reader \
13
- :result
14
-
15
- def initialize(result)
16
- @result = result
17
- end
18
-
19
- def ok?
20
- true
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,99 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../traces'
4
-
5
- require_relative 'response'
6
- require_relative 'client'
7
-
8
- module Datadog
9
- module Transport
10
- module IO
11
- # IO transport behavior for traces
12
- module Traces
13
- # Response from HTTP transport for traces
14
- class Response < IO::Response
15
- include Transport::Traces::Response
16
-
17
- def initialize(result, trace_count = 1)
18
- super(result)
19
- @trace_count = trace_count
20
- end
21
- end
22
-
23
- # Extensions for HTTP client
24
- module Client
25
- def send_traces(traces)
26
- # Build a request
27
- req = Transport::Traces::Request.new(Parcel.new(traces))
28
-
29
- [send_request(req) do |out, request|
30
- # Encode trace data
31
- data = encode_data(encoder, request)
32
-
33
- # Write to IO
34
- result = if block_given?
35
- yield(out, data)
36
- else
37
- write_data(out, data)
38
- end
39
-
40
- # Generate response
41
- Traces::Response.new(result)
42
- end]
43
- end
44
- end
45
-
46
- # Encoder for IO-specific trace encoding
47
- # API compliant when used with {JSONEncoder}.
48
- module Encoder
49
- ENCODED_IDS = [
50
- :trace_id,
51
- :span_id,
52
- :parent_id
53
- ].freeze
54
-
55
- # Encodes a list of traces
56
- def encode_traces(encoder, traces)
57
- trace_hashes = traces.map do |trace|
58
- encode_trace(trace)
59
- end
60
-
61
- # Wrap traces & encode them
62
- encoder.encode(traces: trace_hashes)
63
- end
64
-
65
- private
66
-
67
- def encode_trace(trace)
68
- # Convert each trace to hash
69
- trace.spans.map(&:to_hash).tap do |spans|
70
- # Convert IDs to hexadecimal
71
- spans.each do |span|
72
- ENCODED_IDS.each do |id|
73
- span[id] = span[id].to_s(16) if span.key?(id)
74
- end
75
- end
76
- end
77
- end
78
- end
79
-
80
- # Transfer object for list of traces
81
- class Parcel
82
- include Transport::Parcel
83
- include Encoder
84
-
85
- def count
86
- data.length
87
- end
88
-
89
- def encode_with(encoder)
90
- encode_traces(encoder, data)
91
- end
92
- end
93
-
94
- # Add traces behavior to transport components
95
- IO::Client.include(Traces::Client)
96
- end
97
- end
98
- end
99
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../datadog/core/encoding'
4
- require_relative 'io/client'
5
- require_relative 'io/traces'
6
-
7
- module Datadog
8
- module Transport
9
- # Namespace for IO transport components
10
- module IO
11
- module_function
12
-
13
- # Builds a new Transport::IO::Client
14
- def new(out, encoder)
15
- Client.new(out, encoder)
16
- end
17
-
18
- # Builds a new Transport::IO::Client with default settings
19
- # Pass options to override any settings.
20
- def default(options = {})
21
- new(
22
- options.fetch(:out, $stdout),
23
- options.fetch(:encoder, Core::Encoding::JSONEncoder)
24
- )
25
- end
26
- end
27
- end
28
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Datadog
4
- module Transport
5
- # Data transfer object for generic data
6
- # @abstract
7
- module Parcel
8
- attr_reader \
9
- :data
10
-
11
- def initialize(data)
12
- @data = data
13
- end
14
-
15
- def encode_with(encoder)
16
- raise NotImplementedError
17
- end
18
- end
19
- end
20
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Datadog
4
- module Transport
5
- # Defines request for transport operations
6
- class Request
7
- attr_reader \
8
- :parcel
9
-
10
- def initialize(parcel = nil)
11
- @parcel = parcel
12
- end
13
- end
14
- end
15
- end
@@ -1,60 +0,0 @@
1
- module Datadog
2
- module Transport
3
- # Defines abstract response for transport operations
4
- module Response
5
- def payload
6
- nil
7
- end
8
-
9
- def ok?
10
- nil
11
- end
12
-
13
- def unsupported?
14
- nil
15
- end
16
-
17
- def not_found?
18
- nil
19
- end
20
-
21
- def client_error?
22
- nil
23
- end
24
-
25
- def server_error?
26
- nil
27
- end
28
-
29
- def internal_error?
30
- nil
31
- end
32
-
33
- def inspect
34
- "#{self.class} ok?:#{ok?} unsupported?:#{unsupported?}, " \
35
- "not_found?:#{not_found?}, client_error?:#{client_error?}, " \
36
- "server_error?:#{server_error?}, internal_error?:#{internal_error?}, " \
37
- "payload:#{payload}"
38
- end
39
- end
40
-
41
- # A generic error response for internal errors
42
- class InternalErrorResponse
43
- include Response
44
-
45
- attr_reader :error
46
-
47
- def initialize(error)
48
- @error = error
49
- end
50
-
51
- def internal_error?
52
- true
53
- end
54
-
55
- def inspect
56
- "#{super}, error_type:#{error.class} error:#{error}"
57
- end
58
- end
59
- end
60
- end
@@ -1,122 +0,0 @@
1
- require 'json'
2
- require 'msgpack'
3
- require 'datadog/tracing/utils'
4
-
5
- module Datadog
6
- module Transport
7
- # Adds serialization functions to a {Datadog::TraceSegment}
8
- class SerializableTrace
9
- attr_reader \
10
- :trace
11
-
12
- def initialize(trace)
13
- @trace = trace
14
- end
15
-
16
- # MessagePack serializer interface. Making this object
17
- # respond to `#to_msgpack` allows it to be automatically
18
- # serialized by MessagePack.
19
- #
20
- # This is more efficient than doing +MessagePack.pack(span.to_hash)+
21
- # as we don't have to create an intermediate Hash.
22
- #
23
- # @param packer [MessagePack::Packer] serialization buffer, can be +nil+ with JRuby
24
- def to_msgpack(packer = nil)
25
- # As of 1.3.3, JRuby implementation doesn't pass an existing packer
26
- trace.spans.map { |s| SerializableSpan.new(s) }.to_msgpack(packer)
27
- end
28
-
29
- # JSON serializer interface.
30
- # Used by older version of the transport.
31
- def to_json(*args)
32
- trace.spans.map { |s| SerializableSpan.new(s).to_hash }.to_json(*args)
33
- end
34
- end
35
-
36
- # Adds serialization functions to a {Datadog::Span}
37
- class SerializableSpan
38
- attr_reader \
39
- :span
40
-
41
- def initialize(span)
42
- @span = span
43
- @trace_id = Tracing::Utils::TraceId.to_low_order(span.trace_id)
44
- end
45
-
46
- # MessagePack serializer interface. Making this object
47
- # respond to `#to_msgpack` allows it to be automatically
48
- # serialized by MessagePack.
49
- #
50
- # This is more efficient than doing +MessagePack.pack(span.to_hash)+
51
- # as we don't have to create an intermediate Hash.
52
- #
53
- # @param packer [MessagePack::Packer] serialization buffer, can be +nil+ with JRuby
54
- # rubocop:disable Metrics/AbcSize
55
- def to_msgpack(packer = nil)
56
- packer ||= MessagePack::Packer.new
57
-
58
- number_of_elements_to_write = 10
59
-
60
- if span.stopped?
61
- packer.write_map_header(number_of_elements_to_write + 2) # Set header with how many elements in the map
62
-
63
- packer.write('start')
64
- packer.write(time_nano(span.start_time))
65
-
66
- packer.write('duration')
67
- packer.write(duration_nano(span.duration))
68
- else
69
- packer.write_map_header(number_of_elements_to_write) # Set header with how many elements in the map
70
- end
71
-
72
- # DEV: We use strings as keys here, instead of symbols, as
73
- # DEV: MessagePack will ultimately convert them to strings.
74
- # DEV: By providing strings directly, we skip this indirection operation.
75
- packer.write('span_id')
76
- packer.write(span.id)
77
- packer.write('parent_id')
78
- packer.write(span.parent_id)
79
- packer.write('trace_id')
80
- packer.write(@trace_id)
81
- packer.write('name')
82
- packer.write(span.name)
83
- packer.write('service')
84
- packer.write(span.service)
85
- packer.write('resource')
86
- packer.write(span.resource)
87
- packer.write('type')
88
- packer.write(span.type)
89
- packer.write('meta')
90
- packer.write(span.meta)
91
- packer.write('metrics')
92
- packer.write(span.metrics)
93
- packer.write('error')
94
- packer.write(span.status)
95
- packer
96
- end
97
- # rubocop:enable Metrics/AbcSize
98
-
99
- # JSON serializer interface.
100
- # Used by older version of the transport.
101
- def to_json(*args)
102
- to_hash.to_json(*args)
103
- end
104
-
105
- # Used for serialization
106
- # @return [Integer] in nanoseconds since Epoch
107
- def time_nano(time)
108
- time.to_i * 1000000000 + time.nsec
109
- end
110
-
111
- def to_hash
112
- span.to_hash.merge(trace_id: @trace_id)
113
- end
114
-
115
- # Used for serialization
116
- # @return [Integer] in nanoseconds since Epoch
117
- def duration_nano(duration)
118
- (duration * 1e9).to_i
119
- end
120
- end
121
- end
122
- end
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../datadog/core/metrics/metric'
4
- require_relative '../../datadog/core/diagnostics/health'
5
-
6
- module Datadog
7
- module Transport
8
- # Tracks statistics for transports
9
- module Statistics
10
- def stats
11
- @stats ||= Counts.new
12
- end
13
-
14
- def update_stats_from_response!(response)
15
- if response.ok?
16
- stats.success += 1
17
- stats.consecutive_errors = 0
18
- else
19
- stats.client_error += 1 if response.client_error?
20
- stats.server_error += 1 if response.server_error?
21
- stats.internal_error += 1 if response.internal_error?
22
- stats.consecutive_errors += 1
23
- end
24
-
25
- # Send health metrics
26
- Datadog.health_metrics.send_metrics(
27
- metrics_for_response(response).values
28
- )
29
- end
30
-
31
- def metrics_for_response(response)
32
- {}.tap do |metrics|
33
- metrics[:api_errors] = Core::Metrics::Metric.new(:api_errors, nil, 1) if response.internal_error?
34
- metrics[:api_responses] = Core::Metrics::Metric.new(:api_responses, nil, 1) unless response.internal_error?
35
- end
36
- end
37
-
38
- def update_stats_from_exception!(exception)
39
- stats.internal_error += 1
40
- stats.consecutive_errors += 1
41
-
42
- # Send health metrics
43
- Datadog.health_metrics.send_metrics(
44
- metrics_for_exception(exception).values
45
- )
46
- end
47
-
48
- def metrics_for_exception(_exception)
49
- { api_errors: Core::Metrics::Metric.new(:api_errors, nil, 1) }
50
- end
51
-
52
- # Stat counts
53
- class Counts
54
- attr_accessor \
55
- :success,
56
- :client_error,
57
- :server_error,
58
- :internal_error,
59
- :consecutive_errors
60
-
61
- def initialize
62
- reset!
63
- end
64
-
65
- def reset!
66
- @success = 0
67
- @client_error = 0
68
- @server_error = 0
69
- @internal_error = 0
70
- @consecutive_errors = 0
71
- end
72
- end
73
- end
74
- end
75
- end