datadog 2.15.0 → 2.17.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 (194) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +74 -2
  3. data/ext/datadog_profiling_native_extension/datadog_ruby_common.c +1 -4
  4. data/ext/datadog_profiling_native_extension/datadog_ruby_common.h +7 -0
  5. data/ext/datadog_profiling_native_extension/encoded_profile.c +22 -12
  6. data/ext/datadog_profiling_native_extension/encoded_profile.h +1 -0
  7. data/ext/datadog_profiling_native_extension/extconf.rb +3 -0
  8. data/ext/datadog_profiling_native_extension/heap_recorder.c +8 -1
  9. data/ext/datadog_profiling_native_extension/http_transport.c +45 -72
  10. data/ext/datadog_profiling_native_extension/stack_recorder.c +4 -5
  11. data/ext/libdatadog_api/crashtracker.c +11 -12
  12. data/ext/libdatadog_api/crashtracker.h +5 -0
  13. data/ext/libdatadog_api/datadog_ruby_common.c +1 -4
  14. data/ext/libdatadog_api/datadog_ruby_common.h +7 -0
  15. data/ext/libdatadog_api/init.c +15 -0
  16. data/ext/libdatadog_api/library_config.c +122 -0
  17. data/ext/libdatadog_api/library_config.h +19 -0
  18. data/ext/libdatadog_api/macos_development.md +3 -3
  19. data/ext/libdatadog_api/process_discovery.c +117 -0
  20. data/ext/libdatadog_api/process_discovery.h +5 -0
  21. data/ext/libdatadog_extconf_helpers.rb +1 -1
  22. data/lib/datadog/appsec/actions_handler.rb +3 -2
  23. data/lib/datadog/appsec/api_security/lru_cache.rb +49 -0
  24. data/lib/datadog/appsec/api_security.rb +9 -0
  25. data/lib/datadog/appsec/assets/waf_rules/recommended.json +1344 -0
  26. data/lib/datadog/appsec/assets/waf_rules/strict.json +1344 -0
  27. data/lib/datadog/appsec/autoload.rb +1 -1
  28. data/lib/datadog/appsec/component.rb +11 -4
  29. data/lib/datadog/appsec/configuration/settings.rb +31 -18
  30. data/lib/datadog/appsec/context.rb +1 -1
  31. data/lib/datadog/appsec/contrib/active_record/instrumentation.rb +10 -12
  32. data/lib/datadog/appsec/contrib/active_record/integration.rb +1 -1
  33. data/lib/datadog/appsec/contrib/active_record/patcher.rb +22 -22
  34. data/lib/datadog/appsec/contrib/devise/data_extractor.rb +2 -3
  35. data/lib/datadog/appsec/contrib/devise/ext.rb +1 -0
  36. data/lib/datadog/appsec/contrib/devise/integration.rb +1 -1
  37. data/lib/datadog/appsec/contrib/devise/patcher.rb +3 -5
  38. data/lib/datadog/appsec/contrib/devise/tracking_middleware.rb +17 -4
  39. data/lib/datadog/appsec/contrib/excon/integration.rb +1 -1
  40. data/lib/datadog/appsec/contrib/excon/ssrf_detection_middleware.rb +9 -10
  41. data/lib/datadog/appsec/contrib/faraday/integration.rb +1 -1
  42. data/lib/datadog/appsec/contrib/faraday/ssrf_detection_middleware.rb +8 -9
  43. data/lib/datadog/appsec/contrib/graphql/gateway/watcher.rb +8 -9
  44. data/lib/datadog/appsec/contrib/graphql/integration.rb +1 -1
  45. data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +22 -32
  46. data/lib/datadog/appsec/contrib/rack/integration.rb +1 -1
  47. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +16 -16
  48. data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +11 -13
  49. data/lib/datadog/appsec/contrib/rails/integration.rb +1 -1
  50. data/lib/datadog/appsec/contrib/rails/patcher.rb +21 -21
  51. data/lib/datadog/appsec/contrib/rest_client/integration.rb +1 -1
  52. data/lib/datadog/appsec/contrib/rest_client/request_ssrf_detection_patch.rb +10 -11
  53. data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +17 -23
  54. data/lib/datadog/appsec/contrib/sinatra/integration.rb +1 -1
  55. data/lib/datadog/appsec/event.rb +85 -95
  56. data/lib/datadog/appsec/instrumentation/gateway/argument.rb +5 -2
  57. data/lib/datadog/appsec/metrics/telemetry.rb +1 -1
  58. data/lib/datadog/appsec/monitor/gateway/watcher.rb +42 -12
  59. data/lib/datadog/appsec/processor/rule_loader.rb +26 -28
  60. data/lib/datadog/appsec/processor/rule_merger.rb +5 -5
  61. data/lib/datadog/appsec/processor.rb +1 -1
  62. data/lib/datadog/appsec/remote.rb +14 -13
  63. data/lib/datadog/appsec/response.rb +6 -6
  64. data/lib/datadog/appsec/security_engine/runner.rb +1 -1
  65. data/lib/datadog/appsec/security_event.rb +39 -0
  66. data/lib/datadog/appsec.rb +1 -1
  67. data/lib/datadog/core/buffer/random.rb +18 -2
  68. data/lib/datadog/core/configuration/agent_settings_resolver.rb +5 -5
  69. data/lib/datadog/core/configuration/agentless_settings_resolver.rb +176 -0
  70. data/lib/datadog/core/configuration/components.rb +48 -30
  71. data/lib/datadog/core/configuration/components_state.rb +23 -0
  72. data/lib/datadog/core/configuration/option.rb +79 -43
  73. data/lib/datadog/core/configuration/option_definition.rb +4 -4
  74. data/lib/datadog/core/configuration/options.rb +1 -1
  75. data/lib/datadog/core/configuration/settings.rb +20 -10
  76. data/lib/datadog/core/configuration/stable_config.rb +23 -0
  77. data/lib/datadog/core/configuration.rb +40 -16
  78. data/lib/datadog/core/crashtracking/component.rb +3 -10
  79. data/lib/datadog/core/encoding.rb +1 -1
  80. data/lib/datadog/core/environment/cgroup.rb +10 -12
  81. data/lib/datadog/core/environment/container.rb +38 -40
  82. data/lib/datadog/core/environment/ext.rb +6 -6
  83. data/lib/datadog/core/environment/git.rb +1 -0
  84. data/lib/datadog/core/environment/identity.rb +3 -3
  85. data/lib/datadog/core/environment/platform.rb +3 -3
  86. data/lib/datadog/core/environment/variable_helpers.rb +1 -1
  87. data/lib/datadog/core/error.rb +11 -9
  88. data/lib/datadog/core/logger.rb +2 -2
  89. data/lib/datadog/core/metrics/client.rb +20 -21
  90. data/lib/datadog/core/metrics/logging.rb +5 -5
  91. data/lib/datadog/core/process_discovery.rb +32 -0
  92. data/lib/datadog/core/rate_limiter.rb +4 -2
  93. data/lib/datadog/core/remote/client.rb +39 -31
  94. data/lib/datadog/core/remote/component.rb +3 -3
  95. data/lib/datadog/core/remote/configuration/digest.rb +7 -7
  96. data/lib/datadog/core/remote/configuration/path.rb +1 -1
  97. data/lib/datadog/core/remote/transport/http/client.rb +1 -1
  98. data/lib/datadog/core/remote/transport/http/config.rb +21 -5
  99. data/lib/datadog/core/remote/transport/http/negotiation.rb +1 -1
  100. data/lib/datadog/core/runtime/metrics.rb +4 -4
  101. data/lib/datadog/core/telemetry/component.rb +78 -53
  102. data/lib/datadog/core/telemetry/emitter.rb +23 -11
  103. data/lib/datadog/core/telemetry/event/app_client_configuration_change.rb +65 -0
  104. data/lib/datadog/core/telemetry/event/app_closing.rb +18 -0
  105. data/lib/datadog/core/telemetry/event/app_dependencies_loaded.rb +33 -0
  106. data/lib/datadog/core/telemetry/event/app_heartbeat.rb +18 -0
  107. data/lib/datadog/core/telemetry/event/app_integrations_change.rb +58 -0
  108. data/lib/datadog/core/telemetry/event/app_started.rb +179 -0
  109. data/lib/datadog/core/telemetry/event/base.rb +40 -0
  110. data/lib/datadog/core/telemetry/event/distributions.rb +18 -0
  111. data/lib/datadog/core/telemetry/event/generate_metrics.rb +43 -0
  112. data/lib/datadog/core/telemetry/event/log.rb +76 -0
  113. data/lib/datadog/core/telemetry/event/message_batch.rb +42 -0
  114. data/lib/datadog/core/telemetry/event/synth_app_client_configuration_change.rb +43 -0
  115. data/lib/datadog/core/telemetry/event.rb +17 -472
  116. data/lib/datadog/core/telemetry/http/adapters/net.rb +12 -97
  117. data/lib/datadog/core/telemetry/logger.rb +1 -1
  118. data/lib/datadog/core/telemetry/metric.rb +3 -3
  119. data/lib/datadog/core/telemetry/request.rb +3 -3
  120. data/lib/datadog/core/telemetry/transport/http/api.rb +43 -0
  121. data/lib/datadog/core/telemetry/transport/http/client.rb +49 -0
  122. data/lib/datadog/core/telemetry/transport/http/telemetry.rb +92 -0
  123. data/lib/datadog/core/telemetry/transport/http.rb +63 -0
  124. data/lib/datadog/core/telemetry/transport/telemetry.rb +51 -0
  125. data/lib/datadog/core/telemetry/worker.rb +90 -24
  126. data/lib/datadog/core/transport/http/adapters/test.rb +2 -1
  127. data/lib/datadog/core/transport/http/builder.rb +13 -13
  128. data/lib/datadog/core/utils/at_fork_monkey_patch.rb +6 -6
  129. data/lib/datadog/core/utils/duration.rb +32 -32
  130. data/lib/datadog/core/utils/forking.rb +2 -2
  131. data/lib/datadog/core/utils/network.rb +6 -6
  132. data/lib/datadog/core/utils/only_once_successful.rb +16 -5
  133. data/lib/datadog/core/utils/time.rb +20 -0
  134. data/lib/datadog/core/utils/truncation.rb +21 -0
  135. data/lib/datadog/core/vendor/multipart-post/multipart/post/composite_read_io.rb +1 -1
  136. data/lib/datadog/core/vendor/multipart-post/multipart/post/multipartable.rb +8 -8
  137. data/lib/datadog/core/vendor/multipart-post/multipart/post/parts.rb +7 -7
  138. data/lib/datadog/core/worker.rb +1 -1
  139. data/lib/datadog/core/workers/async.rb +29 -12
  140. data/lib/datadog/core/workers/interval_loop.rb +12 -1
  141. data/lib/datadog/core/workers/runtime_metrics.rb +2 -2
  142. data/lib/datadog/core.rb +8 -0
  143. data/lib/datadog/di/boot.rb +34 -0
  144. data/lib/datadog/di/remote.rb +2 -0
  145. data/lib/datadog/di.rb +5 -32
  146. data/lib/datadog/error_tracking/collector.rb +87 -0
  147. data/lib/datadog/error_tracking/component.rb +167 -0
  148. data/lib/datadog/error_tracking/configuration/settings.rb +63 -0
  149. data/lib/datadog/error_tracking/configuration.rb +11 -0
  150. data/lib/datadog/error_tracking/ext.rb +18 -0
  151. data/lib/datadog/error_tracking/extensions.rb +16 -0
  152. data/lib/datadog/error_tracking/filters.rb +77 -0
  153. data/lib/datadog/error_tracking.rb +18 -0
  154. data/lib/datadog/kit/identity.rb +1 -1
  155. data/lib/datadog/profiling/collectors/code_provenance.rb +1 -1
  156. data/lib/datadog/profiling/exporter.rb +1 -1
  157. data/lib/datadog/profiling/ext.rb +0 -1
  158. data/lib/datadog/profiling/flush.rb +1 -1
  159. data/lib/datadog/profiling/http_transport.rb +1 -6
  160. data/lib/datadog/profiling/scheduler.rb +8 -1
  161. data/lib/datadog/profiling/tag_builder.rb +1 -5
  162. data/lib/datadog/tracing/analytics.rb +1 -1
  163. data/lib/datadog/tracing/contrib/active_support/cache/events/cache.rb +4 -1
  164. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +33 -0
  165. data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +4 -0
  166. data/lib/datadog/tracing/contrib/active_support/cache/redis.rb +2 -4
  167. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +10 -0
  168. data/lib/datadog/tracing/contrib/aws/parsed_context.rb +5 -1
  169. data/lib/datadog/tracing/contrib/http/instrumentation.rb +1 -5
  170. data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +1 -5
  171. data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +1 -5
  172. data/lib/datadog/tracing/contrib/karafka/distributed/propagation.rb +2 -0
  173. data/lib/datadog/tracing/contrib/karafka/monitor.rb +1 -1
  174. data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +8 -0
  175. data/lib/datadog/tracing/contrib/mongodb/ext.rb +1 -0
  176. data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +18 -1
  177. data/lib/datadog/tracing/contrib/patcher.rb +5 -2
  178. data/lib/datadog/tracing/contrib/support.rb +28 -0
  179. data/lib/datadog/tracing/distributed/b3_multi.rb +1 -1
  180. data/lib/datadog/tracing/distributed/b3_single.rb +1 -1
  181. data/lib/datadog/tracing/distributed/datadog.rb +2 -2
  182. data/lib/datadog/tracing/metadata/errors.rb +4 -4
  183. data/lib/datadog/tracing/sampling/rate_sampler.rb +2 -1
  184. data/lib/datadog/tracing/span_operation.rb +38 -14
  185. data/lib/datadog/tracing/trace_operation.rb +15 -7
  186. data/lib/datadog/tracing/tracer.rb +7 -3
  187. data/lib/datadog/tracing/utils.rb +1 -1
  188. data/lib/datadog/version.rb +1 -1
  189. data/lib/datadog.rb +2 -3
  190. metadata +53 -10
  191. data/lib/datadog/core/telemetry/http/env.rb +0 -20
  192. data/lib/datadog/core/telemetry/http/ext.rb +0 -28
  193. data/lib/datadog/core/telemetry/http/response.rb +0 -70
  194. data/lib/datadog/core/telemetry/http/transport.rb +0 -90
@@ -6,8 +6,10 @@ require_relative '../utils/sequence'
6
6
  module Datadog
7
7
  module Core
8
8
  module Telemetry
9
- # Collection of telemetry events
10
- class Event
9
+ # Collection of telemetry events.
10
+ #
11
+ # @api private
12
+ module Event
11
13
  extend Core::Utils::Forking
12
14
 
13
15
  # returns sequence that increments every time the configuration changes
@@ -15,477 +17,20 @@ module Datadog
15
17
  after_fork! { @sequence = Datadog::Core::Utils::Sequence.new(1) }
16
18
  @sequence ||= Datadog::Core::Utils::Sequence.new(1)
17
19
  end
18
-
19
- # Base class for all Telemetry V2 events.
20
- class Base
21
- # The type of the event.
22
- # It must be one of the stings defined in the Telemetry V2
23
- # specification for event names.
24
- def type
25
- raise NotImplementedError, 'Must be implemented by subclass'
26
- end
27
-
28
- # The JSON payload for the event.
29
- def payload
30
- {}
31
- end
32
-
33
- # Override equality to allow for deduplication
34
- # The basic implementation is to check if the other object is an instance of the same class.
35
- # This works for events that have no attributes.
36
- # For events with attributes, you should override this method to compare the attributes.
37
- def ==(other)
38
- other.is_a?(self.class)
39
- end
40
-
41
- # @see #==
42
- alias eql? ==
43
-
44
- # @see #==
45
- def hash
46
- self.class.hash
47
- end
48
- end
49
-
50
- # Telemetry class for the 'app-started' event
51
- class AppStarted < Base
52
- def type
53
- 'app-started'
54
- end
55
-
56
- def payload
57
- {
58
- products: products,
59
- configuration: configuration,
60
- install_signature: install_signature,
61
- # DEV: Not implemented yet
62
- # error: error, # Start-up errors
63
- }
64
- end
65
-
66
- private
67
-
68
- def products
69
- # @type var products: Hash[Symbol, Hash[Symbol, Object]]
70
- products = {
71
- appsec: {
72
- enabled: Datadog::AppSec.enabled?,
73
- },
74
- profiler: {
75
- enabled: Datadog::Profiling.enabled?,
76
- },
77
- # DEV: Not implemented yet
78
- # dynamic_instrumentation: {
79
- # enabled: true,
80
- # }
81
- }
82
-
83
- if (unsupported_reason = Datadog::Profiling.unsupported_reason)
84
- products[:profiler][:error] = {
85
- code: 1, # Error code. 0 if no error.
86
- message: unsupported_reason,
87
- }
88
- end
89
-
90
- products
91
- end
92
-
93
- TARGET_OPTIONS = %w[
94
- logger.level
95
- profiling.advanced.code_provenance_enabled
96
- profiling.advanced.endpoint.collection.enabled
97
- profiling.enabled
98
- runtime_metrics.enabled
99
- tracing.analytics.enabled
100
- tracing.propagation_style_extract
101
- tracing.propagation_style_inject
102
- tracing.enabled
103
- tracing.log_injection
104
- tracing.partial_flush.enabled
105
- tracing.partial_flush.min_spans_threshold
106
- tracing.report_hostname
107
- tracing.sampling.rate_limit
108
- ].freeze
109
-
110
- # rubocop:disable Metrics/AbcSize
111
- # rubocop:disable Metrics/MethodLength
112
- def configuration
113
- config = Datadog.configuration
114
- seq_id = Event.configuration_sequence.next
115
-
116
- list = [
117
- conf_value('DD_AGENT_HOST', config.agent.host, seq_id),
118
- conf_value('DD_AGENT_TRANSPORT', agent_transport(config), seq_id),
119
- conf_value('DD_TRACE_SAMPLE_RATE', to_value(config.tracing.sampling.default_rate), seq_id),
120
- conf_value(
121
- 'DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED',
122
- config.tracing.contrib.global_default_service_name.enabled,
123
- seq_id
124
- ),
125
- conf_value(
126
- 'DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED',
127
- config.tracing.contrib.peer_service_defaults,
128
- seq_id
129
- ),
130
- ]
131
-
132
- peer_service_mapping_str = ''
133
- unless config.tracing.contrib.peer_service_mapping.empty?
134
- peer_service_mapping = config.tracing.contrib.peer_service_mapping
135
- peer_service_mapping_str = peer_service_mapping.map { |key, value| "#{key}:#{value}" }.join(',')
136
- end
137
- list << conf_value('DD_TRACE_PEER_SERVICE_MAPPING', peer_service_mapping_str, seq_id)
138
-
139
- # Whitelist of configuration options to send in additional payload object
140
- TARGET_OPTIONS.each do |option|
141
- split_option = option.split('.')
142
- list << conf_value(option, to_value(config.dig(*split_option)), seq_id)
143
- end
144
-
145
- # Add some more custom additional payload values here
146
- list.push(
147
- conf_value('tracing.auto_instrument.enabled', !defined?(Datadog::AutoInstrument::LOADED).nil?, seq_id),
148
- conf_value(
149
- 'tracing.writer_options.buffer_size',
150
- to_value(config.tracing.writer_options[:buffer_size]),
151
- seq_id
152
- ),
153
- conf_value(
154
- 'tracing.writer_options.flush_interval',
155
- to_value(config.tracing.writer_options[:flush_interval]),
156
- seq_id
157
- ),
158
- conf_value(
159
- 'tracing.opentelemetry.enabled',
160
- !defined?(Datadog::OpenTelemetry::LOADED).nil?,
161
- seq_id
162
- ),
163
- )
164
- list << conf_value('logger.instance', config.logger.instance.class.to_s, seq_id) if config.logger.instance
165
- if config.respond_to?('appsec')
166
- list << conf_value('appsec.enabled', config.dig('appsec', 'enabled'), seq_id)
167
- list << conf_value('appsec.sca_enabled', config.dig('appsec', 'sca_enabled'), seq_id)
168
- end
169
- list << conf_value('ci.enabled', config.dig('ci', 'enabled'), seq_id) if config.respond_to?('ci')
170
-
171
- list.reject! { |entry| entry[:value].nil? }
172
- list
173
- end
174
- # rubocop:enable Metrics/AbcSize
175
- # rubocop:enable Metrics/MethodLength
176
-
177
- def agent_transport(config)
178
- adapter = Core::Configuration::AgentSettingsResolver.call(config).adapter
179
- if adapter == Datadog::Core::Transport::Ext::UnixSocket::ADAPTER
180
- 'UDS'
181
- else
182
- 'TCP'
183
- end
184
- end
185
-
186
- def conf_value(name, value, seq_id, origin = 'code')
187
- {
188
- name: name,
189
- value: value,
190
- origin: origin,
191
- seq_id: seq_id,
192
- }
193
- end
194
-
195
- def to_value(value)
196
- # TODO: Add float if telemetry starts accepting it
197
- case value
198
- when Integer, String, true, false, nil
199
- value
200
- else
201
- value.to_s
202
- end
203
- end
204
-
205
- def install_signature
206
- config = Datadog.configuration
207
- {
208
- install_id: config.dig('telemetry', 'install_id'),
209
- install_type: config.dig('telemetry', 'install_type'),
210
- install_time: config.dig('telemetry', 'install_time'),
211
- }
212
- end
213
- end
214
-
215
- # Telemetry class for the 'app-dependencies-loaded' event
216
- class AppDependenciesLoaded < Base
217
- def type
218
- 'app-dependencies-loaded'
219
- end
220
-
221
- def payload
222
- { dependencies: dependencies }
223
- end
224
-
225
- private
226
-
227
- def dependencies
228
- Gem.loaded_specs.collect do |name, gem|
229
- {
230
- name: name,
231
- version: gem.version.to_s,
232
- # hash: nil,
233
- }
234
- end
235
- end
236
- end
237
-
238
- # Telemetry class for the 'app-integrations-change' event
239
- class AppIntegrationsChange < Base
240
- def type
241
- 'app-integrations-change'
242
- end
243
-
244
- def payload
245
- { integrations: integrations }
246
- end
247
-
248
- private
249
-
250
- def integrations
251
- instrumented_integrations = Datadog.configuration.tracing.instrumented_integrations
252
- Datadog.registry.map do |integration|
253
- is_instrumented = instrumented_integrations.include?(integration.name)
254
-
255
- is_enabled = is_instrumented ? !!integration.klass.patcher.patch_successful : false
256
-
257
- version = integration.klass.class.version ? integration.klass.class.version.to_s : nil
258
-
259
- res = {
260
- name: integration.name.to_s,
261
- enabled: is_enabled,
262
- version: version,
263
- compatible: integration.klass.class.compatible?,
264
- error: (patch_error(integration) if is_instrumented && !is_enabled),
265
- # TODO: Track if integration is instrumented by manual configuration or by auto instrumentation
266
- # auto_enabled: is_enabled && ???,
267
- }
268
- res.reject! { |_, v| v.nil? }
269
- res
270
- end
271
- end
272
-
273
- def patch_error(integration)
274
- patch_error_result = integration.klass.patcher.patch_error_result
275
- return patch_error_result.compact.to_s if patch_error_result
276
-
277
- # If no error occurred during patching, but integration is still not instrumented
278
- "Available?: #{integration.klass.class.available?}" \
279
- ", Loaded? #{integration.klass.class.loaded?}" \
280
- ", Compatible? #{integration.klass.class.compatible?}" \
281
- ", Patchable? #{integration.klass.class.patchable?}"
282
- end
283
- end
284
-
285
- # Telemetry class for the 'app-client-configuration-change' event
286
- class AppClientConfigurationChange < Base
287
- attr_reader :changes, :origin
288
-
289
- def type
290
- 'app-client-configuration-change'
291
- end
292
-
293
- def initialize(changes, origin)
294
- super()
295
- @changes = changes
296
- @origin = origin
297
- end
298
-
299
- def payload
300
- { configuration: configuration }
301
- end
302
-
303
- def configuration
304
- config = Datadog.configuration
305
- seq_id = Event.configuration_sequence.next
306
-
307
- res = @changes.map do |name, value|
308
- {
309
- name: name,
310
- value: value,
311
- origin: @origin,
312
- seq_id: seq_id,
313
- }
314
- end
315
-
316
- unless config.dig('appsec', 'sca_enabled').nil?
317
- res << {
318
- name: 'appsec.sca_enabled',
319
- value: config.appsec.sca_enabled,
320
- origin: 'code',
321
- seq_id: seq_id,
322
- }
323
- end
324
-
325
- res
326
- end
327
-
328
- def ==(other)
329
- other.is_a?(AppClientConfigurationChange) && other.changes == @changes && other.origin == @origin
330
- end
331
-
332
- alias eql? ==
333
-
334
- def hash
335
- [self.class, @changes, @origin].hash
336
- end
337
- end
338
-
339
- # Telemetry class for the 'app-heartbeat' event
340
- class AppHeartbeat < Base
341
- def type
342
- 'app-heartbeat'
343
- end
344
- end
345
-
346
- # Telemetry class for the 'app-closing' event
347
- class AppClosing < Base
348
- def type
349
- 'app-closing'
350
- end
351
- end
352
-
353
- # Telemetry class for the 'generate-metrics' event
354
- class GenerateMetrics < Base
355
- attr_reader :namespace, :metric_series
356
-
357
- def type
358
- 'generate-metrics'
359
- end
360
-
361
- def initialize(namespace, metric_series)
362
- super()
363
- @namespace = namespace
364
- @metric_series = metric_series
365
- end
366
-
367
- def payload
368
- {
369
- namespace: @namespace,
370
- series: @metric_series.map(&:to_h)
371
- }
372
- end
373
-
374
- def ==(other)
375
- other.is_a?(GenerateMetrics) && other.namespace == @namespace && other.metric_series == @metric_series
376
- end
377
-
378
- alias eql? ==
379
-
380
- def hash
381
- [self.class, @namespace, @metric_series].hash
382
- end
383
- end
384
-
385
- # Telemetry class for the 'logs' event.
386
- # Logs with the same content are deduplicated at flush time.
387
- class Log < Base
388
- LEVELS = {
389
- error: 'ERROR',
390
- warn: 'WARN',
391
- }.freeze
392
-
393
- LEVELS_STRING = LEVELS.values.freeze
394
-
395
- attr_reader :message, :level, :stack_trace, :count
396
-
397
- def type
398
- 'logs'
399
- end
400
-
401
- # @param message [String] the log message
402
- # @param level [Symbol, String] the log level. Either :error, :warn, 'ERROR', or 'WARN'.
403
- # @param stack_trace [String, nil] the stack trace
404
- # @param count [Integer] the number of times the log was emitted. Used for deduplication.
405
- def initialize(message:, level:, stack_trace: nil, count: 1)
406
- super()
407
- @message = message
408
- @stack_trace = stack_trace
409
-
410
- if level.is_a?(String) && LEVELS_STRING.include?(level)
411
- # String level is used during object copy for deduplication
412
- @level = level
413
- elsif level.is_a?(Symbol)
414
- # Symbol level is used by the regular log emitter user
415
- @level = LEVELS.fetch(level) { |k| raise ArgumentError, "Invalid log level :#{k}" }
416
- else
417
- raise ArgumentError, "Invalid log level #{level}"
418
- end
419
-
420
- @count = count
421
- end
422
-
423
- def payload
424
- {
425
- logs: [
426
- {
427
- message: @message,
428
- level: @level,
429
- stack_trace: @stack_trace,
430
- count: @count,
431
- }.compact
432
- ]
433
- }
434
- end
435
-
436
- # override equality to allow for deduplication
437
- def ==(other)
438
- other.is_a?(Log) &&
439
- other.message == @message &&
440
- other.level == @level && other.stack_trace == @stack_trace && other.count == @count
441
- end
442
-
443
- alias eql? ==
444
-
445
- def hash
446
- [self.class, @message, @level, @stack_trace, @count].hash
447
- end
448
- end
449
-
450
- # Telemetry class for the 'distributions' event
451
- class Distributions < GenerateMetrics
452
- def type
453
- 'distributions'
454
- end
455
- end
456
-
457
- # Telemetry class for the 'message-batch' event
458
- class MessageBatch
459
- attr_reader :events
460
-
461
- def type
462
- 'message-batch'
463
- end
464
-
465
- def initialize(events)
466
- @events = events
467
- end
468
-
469
- def payload
470
- @events.map do |event|
471
- {
472
- request_type: event.type,
473
- payload: event.payload,
474
- }
475
- end
476
- end
477
-
478
- def ==(other)
479
- other.is_a?(MessageBatch) && other.events == @events
480
- end
481
-
482
- alias eql? ==
483
-
484
- def hash
485
- [self.class, @events].hash
486
- end
487
- end
488
20
  end
489
21
  end
490
22
  end
491
23
  end
24
+
25
+ require_relative 'event/base'
26
+ require_relative 'event/app_client_configuration_change'
27
+ require_relative 'event/app_closing'
28
+ require_relative 'event/app_dependencies_loaded'
29
+ require_relative 'event/app_heartbeat'
30
+ require_relative 'event/app_integrations_change'
31
+ require_relative 'event/app_started'
32
+ require_relative 'event/synth_app_client_configuration_change'
33
+ require_relative 'event/generate_metrics'
34
+ require_relative 'event/distributions'
35
+ require_relative 'event/log'
36
+ require_relative 'event/message_batch'
@@ -1,108 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../response'
3
+ # datadog-ci-rb versions 1.15.0 and lower require this file and guard
4
+ # the require with a rescue of StandardError. Unfortunately LoadError,
5
+ # which would be raised if the file is missing, is not a subclass of
6
+ # StandardError and thus would not be caught by the rescue.
7
+ # We provide this file with a dummy class in it to avoid exceptions
8
+ # in datadog-ci-rb until version 2.0 is released.
9
+ #
10
+ # Note that datadog-ci-rb patches telemetry transport to be "real" even when
11
+ # webmock is used; this patching won't work with datadog-ci-rb versions
12
+ # 1.15.0 and older and dd-trace-rb 2.16.0 and newer. There will be no
13
+ # errors/exceptions reported but telemetry events will not be sent.
4
14
 
5
15
  module Datadog
6
16
  module Core
7
17
  module Telemetry
8
18
  module Http
9
19
  module Adapters
10
- # Class defining methods to make http requests via NET
11
- class Net
12
- attr_reader \
13
- :hostname,
14
- :port,
15
- :timeout,
16
- :ssl
17
-
18
- DEFAULT_TIMEOUT = 2
19
-
20
- def initialize(hostname:, port: nil, timeout: DEFAULT_TIMEOUT, ssl: true)
21
- @hostname = hostname
22
- @port = port
23
- @timeout = timeout
24
- @ssl = ssl.nil? || ssl
25
- end
26
-
27
- def open(&block)
28
- req = ::Net::HTTP.new(@hostname, @port)
29
-
30
- req.use_ssl = @ssl
31
- req.open_timeout = req.read_timeout = @timeout
32
-
33
- req.start(&block)
34
- end
35
-
36
- def post(env)
37
- post = ::Net::HTTP::Post.new(env.path, env.headers)
38
- post.body = env.body
39
-
40
- http_response = open do |http|
41
- http.request(post)
42
- end
43
-
44
- Response.new(http_response)
45
- rescue StandardError => e
46
- Datadog.logger.debug("Unable to send telemetry event to agent: #{e}")
47
- Telemetry::Http::InternalErrorResponse.new(e)
48
- end
49
-
50
- # Data structure for an HTTP Response
51
- class Response
52
- include Datadog::Core::Telemetry::Http::Response
53
-
54
- attr_reader :http_response
55
-
56
- def initialize(http_response)
57
- @http_response = http_response
58
- end
59
-
60
- def payload
61
- return super if http_response.nil?
62
-
63
- http_response.body
64
- end
65
-
66
- def code
67
- return super if http_response.nil?
68
-
69
- http_response.code.to_i
70
- end
71
-
72
- def ok?
73
- return super if http_response.nil?
74
-
75
- code.between?(200, 299)
76
- end
77
-
78
- def unsupported?
79
- return super if http_response.nil?
80
-
81
- code == 415
82
- end
83
-
84
- def not_found?
85
- return super if http_response.nil?
86
-
87
- code == 404
88
- end
89
-
90
- def client_error?
91
- return super if http_response.nil?
92
-
93
- code.between?(400, 499)
94
- end
95
-
96
- def server_error?
97
- return super if http_response.nil?
98
-
99
- code.between?(500, 599)
100
- end
101
-
102
- def inspect
103
- "#{super}, http_response:#{http_response}"
104
- end
105
- end
20
+ class Net # rubocop:disable Lint/EmptyClass
106
21
  end
107
22
  end
108
23
  end
@@ -35,7 +35,7 @@ module Datadog
35
35
  # The downside is: this leaves us unable to report telemetry during component initialization.
36
36
  components = Datadog.send(:components, allow_initialization: false)
37
37
 
38
- if components && components.telemetry
38
+ if components&.telemetry
39
39
  components.telemetry
40
40
  else
41
41
  Datadog.logger.warn(
@@ -20,7 +20,7 @@ module Datadog
20
20
  end
21
21
 
22
22
  def id
23
- @id ||= "#{type}::#{name}::#{tags.join(',')}"
23
+ @id ||= "#{type}::#{name}::#{tags.join(",")}"
24
24
  end
25
25
 
26
26
  def track(value)
@@ -47,7 +47,7 @@ module Datadog
47
47
  values == other.values && tags == other.tags && common == other.common && type == other.type
48
48
  end
49
49
 
50
- alias eql? ==
50
+ alias_method :eql?, :==
51
51
 
52
52
  def hash
53
53
  [self.class, name, values, tags, common, type].hash
@@ -88,7 +88,7 @@ module Datadog
88
88
  super && interval == other.interval
89
89
  end
90
90
 
91
- alias eql? ==
91
+ alias_method :eql?, :==
92
92
 
93
93
  def hash
94
94
  [super, interval].hash
@@ -11,11 +11,11 @@ module Datadog
11
11
  class << self
12
12
  using Core::Utils::Hash::Refinement
13
13
 
14
- def build_payload(event, seq_id)
14
+ def build_payload(event, seq_id, api_version: 'v2', debug: false)
15
15
  hash = {
16
- api_version: Http::Ext::API_VERSION,
16
+ api_version: api_version,
17
17
  application: application,
18
- debug: false,
18
+ debug: debug,
19
19
  host: host,
20
20
  payload: event.payload,
21
21
  request_type: event.type,