From d3b43d61e769a54998e51eca62125b148732843f Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Mon, 1 Jul 2024 14:19:44 +0200 Subject: [PATCH 1/8] add MessageBatch event type --- lib/datadog/core/telemetry/event.rb | 20 ++++++++++++++++++++ sig/datadog/core/telemetry/event.rbs | 8 +++++++- spec/datadog/core/telemetry/event_spec.rb | 21 +++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/datadog/core/telemetry/event.rb b/lib/datadog/core/telemetry/event.rb index 60a9886eb1e..f23615a00d6 100644 --- a/lib/datadog/core/telemetry/event.rb +++ b/lib/datadog/core/telemetry/event.rb @@ -313,6 +313,26 @@ def type 'distributions' end end + + # Telemetry class for the 'message-batch' event + class MessageBatch + def type + 'message-batch' + end + + def initialize(events) + @events = events + end + + def payload(seq_id) + @events.map do |event| + { + request_type: event.type, + payload: event.payload(seq_id), + } + end + end + end end end end diff --git a/sig/datadog/core/telemetry/event.rbs b/sig/datadog/core/telemetry/event.rbs index 791f014f9a4..51c84d5d93e 100644 --- a/sig/datadog/core/telemetry/event.rbs +++ b/sig/datadog/core/telemetry/event.rbs @@ -3,7 +3,7 @@ module Datadog module Telemetry class Event class Base - def payload: (int seq_id) -> Hash[Symbol, untyped] + def payload: (int seq_id) -> (Hash[Symbol, untyped] | Array[Hash[Symbol, untyped]]) def type: -> String? end @@ -65,6 +65,12 @@ module Datadog class Distributions < GenerateMetrics end + + class MessageBatch < Base + @events: Array[Datadog::Core::Telemetry::Event::Base] + + def initialize: (Array[Datadog::Core::Telemetry::Event::Base] events) -> void + end end end end diff --git a/spec/datadog/core/telemetry/event_spec.rb b/spec/datadog/core/telemetry/event_spec.rb index f53bd9468ad..2ffc0559a41 100644 --- a/spec/datadog/core/telemetry/event_spec.rb +++ b/spec/datadog/core/telemetry/event_spec.rb @@ -252,4 +252,25 @@ def contain_configuration(*array) ) end end + + context 'MessageBatch' do + let(:event) { described_class::MessageBatch.new(events) } + + let(:events) { [described_class::AppClosing.new, described_class::AppHeartbeat.new] } + + it do + is_expected.to eq( + [ + { + request_type: 'app-closing', + payload: {} + }, + { + request_type: 'app-heartbeat', + payload: {} + } + ] + ) + end + end end From 726b3cff204beede0285b409360fd5b2a2cd18f2 Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Mon, 1 Jul 2024 15:09:02 +0200 Subject: [PATCH 2/8] send telemetry events in batches --- lib/datadog/core/telemetry/event.rb | 2 ++ lib/datadog/core/telemetry/worker.rb | 8 +++---- sig/datadog/core/telemetry/event.rbs | 1 + spec/datadog/core/telemetry/worker_spec.rb | 25 ++++++++++++++-------- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/datadog/core/telemetry/event.rb b/lib/datadog/core/telemetry/event.rb index f23615a00d6..fc4e164079e 100644 --- a/lib/datadog/core/telemetry/event.rb +++ b/lib/datadog/core/telemetry/event.rb @@ -316,6 +316,8 @@ def type # Telemetry class for the 'message-batch' event class MessageBatch + attr_reader :events + def type 'message-batch' end diff --git a/lib/datadog/core/telemetry/worker.rb b/lib/datadog/core/telemetry/worker.rb index 8cb5a685006..cdd0fdf0ad7 100644 --- a/lib/datadog/core/telemetry/worker.rb +++ b/lib/datadog/core/telemetry/worker.rb @@ -82,19 +82,17 @@ def perform(*events) end def flush_events(events) - return if events.nil? + return if events.nil? || events.empty? return if !enabled? || !sent_started_event? Datadog.logger.debug { "Sending #{events&.count} telemetry events" } - events.each do |event| - send_event(event) - end + send_event(Event::MessageBatch.new(events)) end def heartbeat! return if !enabled? || !sent_started_event? - send_event(Event::AppHeartbeat.new) + enqueue(Event::AppHeartbeat.new) end def started! diff --git a/sig/datadog/core/telemetry/event.rbs b/sig/datadog/core/telemetry/event.rbs index 51c84d5d93e..080ebe4ec73 100644 --- a/sig/datadog/core/telemetry/event.rbs +++ b/sig/datadog/core/telemetry/event.rbs @@ -67,6 +67,7 @@ module Datadog end class MessageBatch < Base + attr_reader events: Array[Datadog::Core::Telemetry::Event::Base] @events: Array[Datadog::Core::Telemetry::Event::Base] def initialize: (Array[Datadog::Core::Telemetry::Event::Base] events) -> void diff --git a/spec/datadog/core/telemetry/worker_spec.rb b/spec/datadog/core/telemetry/worker_spec.rb index bc88ad63b38..604b46e0047 100644 --- a/spec/datadog/core/telemetry/worker_spec.rb +++ b/spec/datadog/core/telemetry/worker_spec.rb @@ -40,8 +40,10 @@ response end - allow(emitter).to receive(:request).with(an_instance_of(Datadog::Core::Telemetry::Event::AppHeartbeat)) do - @received_heartbeat = true + allow(emitter).to receive(:request).with(an_instance_of(Datadog::Core::Telemetry::Event::MessageBatch)) do |event| + subevent = event.events.first + + @received_heartbeat = true if subevent.is_a?(Datadog::Core::Telemetry::Event::AppHeartbeat) response end @@ -106,7 +108,7 @@ it 'always sends heartbeat event after started event' do sent_hearbeat = false - allow(emitter).to receive(:request).with(kind_of(Datadog::Core::Telemetry::Event::AppHeartbeat)) do + allow(emitter).to receive(:request).with(kind_of(Datadog::Core::Telemetry::Event::MessageBatch)) do # app-started was already sent by now expect(worker.sent_started_event?).to be(true) @@ -138,7 +140,7 @@ end sent_hearbeat = false - allow(emitter).to receive(:request).with(kind_of(Datadog::Core::Telemetry::Event::AppHeartbeat)) do + allow(emitter).to receive(:request).with(kind_of(Datadog::Core::Telemetry::Event::MessageBatch)) do # app-started was already sent by now expect(@received_started).to be(true) @@ -222,6 +224,7 @@ context 'several workers running' do it 'sends single started event' do started_events = 0 + mutex = Mutex.new allow(emitter).to receive(:request).with(kind_of(Datadog::Core::Telemetry::Event::AppStarted)) do started_events += 1 @@ -229,8 +232,12 @@ end heartbeat_events = 0 - allow(emitter).to receive(:request).with(kind_of(Datadog::Core::Telemetry::Event::AppHeartbeat)) do - heartbeat_events += 1 + allow(emitter).to receive(:request).with(kind_of(Datadog::Core::Telemetry::Event::MessageBatch)) do |event| + event.events.each do |subevent| + mutex.synchronize do + heartbeat_events += 1 if subevent.is_a?(Datadog::Core::Telemetry::Event::AppHeartbeat) + end + end response end @@ -285,9 +292,9 @@ it 'adds events to the buffer and flushes them later' do events_received = 0 allow(emitter).to receive(:request).with( - an_instance_of(Datadog::Core::Telemetry::Event::AppIntegrationsChange) - ) do - events_received += 1 + an_instance_of(Datadog::Core::Telemetry::Event::MessageBatch) + ) do |event| + events_received += event.events.count response end From 572cb273b95039bb324a9d25e07e6a1435c0c61c Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Mon, 1 Jul 2024 15:17:45 +0200 Subject: [PATCH 3/8] fix unit test with concurrency --- spec/datadog/core/telemetry/worker_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/datadog/core/telemetry/worker_spec.rb b/spec/datadog/core/telemetry/worker_spec.rb index 604b46e0047..3a94fa60185 100644 --- a/spec/datadog/core/telemetry/worker_spec.rb +++ b/spec/datadog/core/telemetry/worker_spec.rb @@ -291,10 +291,13 @@ describe '#enqueue' do it 'adds events to the buffer and flushes them later' do events_received = 0 + mutex = Mutex.new allow(emitter).to receive(:request).with( an_instance_of(Datadog::Core::Telemetry::Event::MessageBatch) ) do |event| - events_received += event.events.count + mutex.synchronize do + events_received += event.events.count + end response end From 42a8e3caa85f97a27d876342186ff163688318a9 Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Mon, 1 Jul 2024 15:29:20 +0200 Subject: [PATCH 4/8] fix concurrent test again --- spec/datadog/core/telemetry/worker_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/datadog/core/telemetry/worker_spec.rb b/spec/datadog/core/telemetry/worker_spec.rb index 3a94fa60185..eeea3c70143 100644 --- a/spec/datadog/core/telemetry/worker_spec.rb +++ b/spec/datadog/core/telemetry/worker_spec.rb @@ -295,8 +295,10 @@ allow(emitter).to receive(:request).with( an_instance_of(Datadog::Core::Telemetry::Event::MessageBatch) ) do |event| - mutex.synchronize do - events_received += event.events.count + event.events.each do |subevent| + mutex.synchronize do + events_received += 1 if subevent.is_a?(Datadog::Core::Telemetry::Event::AppIntegrationsChange) + end end response From cb868b78db494a8b40f2f1275dd93dfbb788f2e6 Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Tue, 2 Jul 2024 11:38:27 +0200 Subject: [PATCH 5/8] fixing flaky test --- spec/datadog/core/telemetry/worker_spec.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/spec/datadog/core/telemetry/worker_spec.rb b/spec/datadog/core/telemetry/worker_spec.rb index eeea3c70143..fa6723e9b4d 100644 --- a/spec/datadog/core/telemetry/worker_spec.rb +++ b/spec/datadog/core/telemetry/worker_spec.rb @@ -76,15 +76,12 @@ it 'disables the worker' do worker.start - try_wait_until { @received_started } + try_wait_until { !worker.enabled? } - expect(worker).to have_attributes( - enabled?: false, - loop_base_interval: heartbeat_interval_seconds, - ) expect(Datadog.logger).to have_received(:debug).with( 'Agent does not support telemetry; disabling future telemetry events.' ) + expect(@received_started).to be(true) expect(@received_heartbeat).to be(false) end end From 7b94b2b519d124ae21e6d486821b6b994d60f33a Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Tue, 2 Jul 2024 13:14:01 +0200 Subject: [PATCH 6/8] don't enqueue app-heartbeat events to be batched, send them directly --- lib/datadog/core/telemetry/worker.rb | 2 +- spec/datadog/core/telemetry/worker_spec.rb | 42 +++++++++++++++------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/datadog/core/telemetry/worker.rb b/lib/datadog/core/telemetry/worker.rb index cdd0fdf0ad7..7706ac7ce30 100644 --- a/lib/datadog/core/telemetry/worker.rb +++ b/lib/datadog/core/telemetry/worker.rb @@ -92,7 +92,7 @@ def flush_events(events) def heartbeat! return if !enabled? || !sent_started_event? - enqueue(Event::AppHeartbeat.new) + send_event(Event::AppHeartbeat.new) end def started! diff --git a/spec/datadog/core/telemetry/worker_spec.rb b/spec/datadog/core/telemetry/worker_spec.rb index fa6723e9b4d..f815cc7b65a 100644 --- a/spec/datadog/core/telemetry/worker_spec.rb +++ b/spec/datadog/core/telemetry/worker_spec.rb @@ -40,10 +40,8 @@ response end - allow(emitter).to receive(:request).with(an_instance_of(Datadog::Core::Telemetry::Event::MessageBatch)) do |event| - subevent = event.events.first - - @received_heartbeat = true if subevent.is_a?(Datadog::Core::Telemetry::Event::AppHeartbeat) + allow(emitter).to receive(:request).with(an_instance_of(Datadog::Core::Telemetry::Event::AppHeartbeat)) do + @received_heartbeat = true response end @@ -105,7 +103,7 @@ it 'always sends heartbeat event after started event' do sent_hearbeat = false - allow(emitter).to receive(:request).with(kind_of(Datadog::Core::Telemetry::Event::MessageBatch)) do + allow(emitter).to receive(:request).with(kind_of(Datadog::Core::Telemetry::Event::AppHeartbeat)) do # app-started was already sent by now expect(worker.sent_started_event?).to be(true) @@ -137,7 +135,7 @@ end sent_hearbeat = false - allow(emitter).to receive(:request).with(kind_of(Datadog::Core::Telemetry::Event::MessageBatch)) do + allow(emitter).to receive(:request).with(kind_of(Datadog::Core::Telemetry::Event::AppHeartbeat)) do # app-started was already sent by now expect(@received_started).to be(true) @@ -229,11 +227,9 @@ end heartbeat_events = 0 - allow(emitter).to receive(:request).with(kind_of(Datadog::Core::Telemetry::Event::MessageBatch)) do |event| - event.events.each do |subevent| - mutex.synchronize do - heartbeat_events += 1 if subevent.is_a?(Datadog::Core::Telemetry::Event::AppHeartbeat) - end + allow(emitter).to receive(:request).with(kind_of(Datadog::Core::Telemetry::Event::AppHeartbeat)) do + mutex.synchronize do + heartbeat_events += 1 end response @@ -273,15 +269,35 @@ end describe '#stop' do - let(:heartbeat_interval_seconds) { 3 } + let(:heartbeat_interval_seconds) { 60 } it 'flushes events and stops the worker' do worker.start - expect(worker).to receive(:flush_events).at_least(:once) + try_wait_until { @received_heartbeat } + + events_received = 0 + mutex = Mutex.new + allow(emitter).to receive(:request).with( + an_instance_of(Datadog::Core::Telemetry::Event::MessageBatch) + ) do |event| + event.events.each do |subevent| + mutex.synchronize do + if subevent.is_a?(Datadog::Core::Telemetry::Event::AppIntegrationsChange) + p "received event" + events_received += 1 + end + end + end + + response + end worker.enqueue(Datadog::Core::Telemetry::Event::AppIntegrationsChange.new) + p "stop worker" worker.stop(true) + + try_wait_until { events_received == 1 } end end From 32c2e4243b772547268231b5d6db3e707d15efee Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Tue, 2 Jul 2024 13:14:47 +0200 Subject: [PATCH 7/8] leftovers from test fixes --- spec/datadog/core/telemetry/worker_spec.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/spec/datadog/core/telemetry/worker_spec.rb b/spec/datadog/core/telemetry/worker_spec.rb index f815cc7b65a..54b23ca6e79 100644 --- a/spec/datadog/core/telemetry/worker_spec.rb +++ b/spec/datadog/core/telemetry/worker_spec.rb @@ -283,10 +283,7 @@ ) do |event| event.events.each do |subevent| mutex.synchronize do - if subevent.is_a?(Datadog::Core::Telemetry::Event::AppIntegrationsChange) - p "received event" - events_received += 1 - end + events_received += 1 if subevent.is_a?(Datadog::Core::Telemetry::Event::AppIntegrationsChange) end end @@ -294,7 +291,6 @@ end worker.enqueue(Datadog::Core::Telemetry::Event::AppIntegrationsChange.new) - p "stop worker" worker.stop(true) try_wait_until { events_received == 1 } From 8d02f3e60b1d4ee498026ae88e2899739c0fa132 Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Tue, 2 Jul 2024 13:45:45 +0200 Subject: [PATCH 8/8] introduce sequence for configuration changes reported by telemetry --- lib/datadog/core/telemetry/event.rb | 81 +++++++++++++++-------- lib/datadog/core/telemetry/request.rb | 2 +- sig/datadog/core/telemetry/emitter.rbs | 2 +- sig/datadog/core/telemetry/event.rbs | 14 ++-- spec/datadog/core/telemetry/event_spec.rb | 11 ++- 5 files changed, 73 insertions(+), 37 deletions(-) diff --git a/lib/datadog/core/telemetry/event.rb b/lib/datadog/core/telemetry/event.rb index fc4e164079e..da03069aa54 100644 --- a/lib/datadog/core/telemetry/event.rb +++ b/lib/datadog/core/telemetry/event.rb @@ -3,7 +3,16 @@ module Datadog module Core module Telemetry + # Collection of telemetry events class Event + extend Core::Utils::Forking + + # returns sequence that increments every time the configuration changes + def self.configuration_sequence + after_fork! { @sequence = Datadog::Core::Utils::Sequence.new(1) } + @sequence ||= Datadog::Core::Utils::Sequence.new(1) + end + # Base class for all Telemetry V2 events. class Base # The type of the event. @@ -12,8 +21,7 @@ class Base def type; end # The JSON payload for the event. - # @param seq_id [Integer] The sequence ID for the event. - def payload(seq_id) + def payload {} end end @@ -24,8 +32,7 @@ def type 'app-started' end - def payload(seq_id) - @seq_id = seq_id + def payload { products: products, configuration: configuration, @@ -80,16 +87,19 @@ def products ].freeze # rubocop:disable Metrics/AbcSize + # rubocop:disable Metrics/MethodLength def configuration config = Datadog.configuration + seq_id = Event.configuration_sequence.next list = [ - conf_value('DD_AGENT_HOST', config.agent.host), - conf_value('DD_AGENT_TRANSPORT', agent_transport(config)), - conf_value('DD_TRACE_SAMPLE_RATE', to_value(config.tracing.sampling.default_rate)), + conf_value('DD_AGENT_HOST', config.agent.host, seq_id), + conf_value('DD_AGENT_TRANSPORT', agent_transport(config), seq_id), + conf_value('DD_TRACE_SAMPLE_RATE', to_value(config.tracing.sampling.default_rate), seq_id), conf_value( 'DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED', - config.tracing.contrib.global_default_service_name.enabled + config.tracing.contrib.global_default_service_name.enabled, + seq_id ), ] @@ -98,32 +108,45 @@ def configuration peer_service_mapping = config.tracing.contrib.peer_service_mapping peer_service_mapping_str = peer_service_mapping.map { |key, value| "#{key}:#{value}" }.join(',') end - list << conf_value('DD_TRACE_PEER_SERVICE_MAPPING', peer_service_mapping_str) + list << conf_value('DD_TRACE_PEER_SERVICE_MAPPING', peer_service_mapping_str, seq_id) # Whitelist of configuration options to send in additional payload object TARGET_OPTIONS.each do |option| split_option = option.split('.') - list << conf_value(option, to_value(config.dig(*split_option))) + list << conf_value(option, to_value(config.dig(*split_option)), seq_id) end # Add some more custom additional payload values here list.push( - conf_value('tracing.auto_instrument.enabled', !defined?(Datadog::AutoInstrument::LOADED).nil?), - conf_value('tracing.writer_options.buffer_size', to_value(config.tracing.writer_options[:buffer_size])), - conf_value('tracing.writer_options.flush_interval', to_value(config.tracing.writer_options[:flush_interval])), - conf_value('tracing.opentelemetry.enabled', !defined?(Datadog::OpenTelemetry::LOADED).nil?), + conf_value('tracing.auto_instrument.enabled', !defined?(Datadog::AutoInstrument::LOADED).nil?, seq_id), + conf_value( + 'tracing.writer_options.buffer_size', + to_value(config.tracing.writer_options[:buffer_size]), + seq_id + ), + conf_value( + 'tracing.writer_options.flush_interval', + to_value(config.tracing.writer_options[:flush_interval]), + seq_id + ), + conf_value( + 'tracing.opentelemetry.enabled', + !defined?(Datadog::OpenTelemetry::LOADED).nil?, + seq_id + ), ) - list << conf_value('logger.instance', config.logger.instance.class.to_s) if config.logger.instance + list << conf_value('logger.instance', config.logger.instance.class.to_s, seq_id) if config.logger.instance if config.respond_to?('appsec') - list << conf_value('appsec.enabled', config.dig('appsec', 'enabled')) - list << conf_value('appsec.sca_enabled', config.dig('appsec', 'sca_enabled')) + list << conf_value('appsec.enabled', config.dig('appsec', 'enabled'), seq_id) + list << conf_value('appsec.sca_enabled', config.dig('appsec', 'sca_enabled'), seq_id) end - list << conf_value('ci.enabled', config.dig('ci', 'enabled')) if config.respond_to?('ci') + list << conf_value('ci.enabled', config.dig('ci', 'enabled'), seq_id) if config.respond_to?('ci') list.reject! { |entry| entry[:value].nil? } list end # rubocop:enable Metrics/AbcSize + # rubocop:enable Metrics/MethodLength def agent_transport(config) adapter = Core::Configuration::AgentSettingsResolver.call(config).adapter @@ -134,12 +157,12 @@ def agent_transport(config) end end - def conf_value(name, value, origin = 'code') + def conf_value(name, value, seq_id, origin = 'code') { name: name, value: value, origin: origin, - seq_id: @seq_id, + seq_id: seq_id, } end @@ -169,7 +192,7 @@ def type 'app-dependencies-loaded' end - def payload(seq_id) + def payload { dependencies: dependencies } end @@ -192,7 +215,7 @@ def type 'app-integrations-change' end - def payload(seq_id) + def payload { integrations: integrations } end @@ -245,18 +268,20 @@ def initialize(changes, origin) @origin = origin end - def payload(seq_id) - { configuration: configuration(seq_id) } + def payload + { configuration: configuration } end - def configuration(seq_id) + def configuration config = Datadog.configuration + seq_id = Event.configuration_sequence.next res = @changes.map do |name, value| { name: name, value: value, origin: @origin, + seq_id: seq_id, } end @@ -299,7 +324,7 @@ def initialize(namespace, metric_series) @metric_series = metric_series end - def payload(_) + def payload { namespace: @namespace, series: @metric_series.map(&:to_h) @@ -326,11 +351,11 @@ def initialize(events) @events = events end - def payload(seq_id) + def payload @events.map do |event| { request_type: event.type, - payload: event.payload(seq_id), + payload: event.payload, } end end diff --git a/lib/datadog/core/telemetry/request.rb b/lib/datadog/core/telemetry/request.rb index 86e6bb3b6d9..f15831bc1cf 100644 --- a/lib/datadog/core/telemetry/request.rb +++ b/lib/datadog/core/telemetry/request.rb @@ -17,7 +17,7 @@ def build_payload(event, seq_id) application: application, debug: false, host: host, - payload: event.payload(seq_id), + payload: event.payload, request_type: event.type, runtime_id: Core::Environment::Identity.id, seq_id: seq_id, diff --git a/sig/datadog/core/telemetry/emitter.rbs b/sig/datadog/core/telemetry/emitter.rbs index e1d4320d763..40b1432bedc 100644 --- a/sig/datadog/core/telemetry/emitter.rbs +++ b/sig/datadog/core/telemetry/emitter.rbs @@ -2,7 +2,7 @@ module Datadog module Core module Telemetry class Emitter - @sequence: Datadog::Core::Utils::Sequence + self.@sequence: Datadog::Core::Utils::Sequence attr_reader http_transport: untyped diff --git a/sig/datadog/core/telemetry/event.rbs b/sig/datadog/core/telemetry/event.rbs index 080ebe4ec73..53cc1e20819 100644 --- a/sig/datadog/core/telemetry/event.rbs +++ b/sig/datadog/core/telemetry/event.rbs @@ -2,16 +2,20 @@ module Datadog module Core module Telemetry class Event + extend Core::Utils::Forking + + self.@sequence: Datadog::Core::Utils::Sequence + + def self.configuration_sequence: () -> Datadog::Core::Utils::Sequence + class Base - def payload: (int seq_id) -> (Hash[Symbol, untyped] | Array[Hash[Symbol, untyped]]) + def payload: () -> (Hash[Symbol, untyped] | Array[Hash[Symbol, untyped]]) def type: -> String? end class AppStarted < Base TARGET_OPTIONS: Array[String] - @seq_id: int - private def products: -> Hash[Symbol, untyped] @@ -20,7 +24,7 @@ module Datadog def agent_transport: (untyped config) -> String - def conf_value: (String name, Object value, ?String origin) -> Hash[Symbol, untyped] + def conf_value: (String name, Object value, Integer seq_id, ?String origin) -> Hash[Symbol, untyped] def to_value: (Object value) -> Object @@ -47,7 +51,7 @@ module Datadog def initialize: (Enumerable[[String, Numeric | bool | String]] changes, String origin) -> void - def configuration: (int seq_id) -> Array[Hash[Symbol, untyped]] + def configuration: () -> Array[Hash[Symbol, untyped]] end class AppHeartbeat < Base diff --git a/spec/datadog/core/telemetry/event_spec.rb b/spec/datadog/core/telemetry/event_spec.rb index 2ffc0559a41..b8eee1f48d8 100644 --- a/spec/datadog/core/telemetry/event_spec.rb +++ b/spec/datadog/core/telemetry/event_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Datadog::Core::Telemetry::Event do let(:id) { double('seq_id') } - subject(:payload) { event.payload(id) } + subject(:payload) { event.payload } context 'AppStarted' do let(:event) { described_class::AppStarted.new } @@ -14,6 +14,8 @@ end before do + allow_any_instance_of(Datadog::Core::Utils::Sequence).to receive(:next).and_return(id) + Datadog.configure do |c| c.agent.host = '1.2.3.4' c.tracing.sampling.default_rate = 0.5 @@ -164,12 +166,17 @@ def contain_configuration(*array) let(:name) { 'key' } let(:value) { 'value' } + before do + allow_any_instance_of(Datadog::Core::Utils::Sequence).to receive(:next).and_return(id) + end + it 'has a list of client configurations' do is_expected.to eq( configuration: [{ name: name, value: value, origin: origin, + seq_id: id }] ) end @@ -185,7 +192,7 @@ def contain_configuration(*array) is_expected.to eq( configuration: [ - { name: name, value: value, origin: origin }, + { name: name, value: value, origin: origin, seq_id: id }, { name: 'appsec.sca_enabled', value: false, origin: 'code', seq_id: id } ] )