Skip to content

Commit 77dfd10

Browse files
committed
Remove defensive coding and make it so DSM contrib libraries require libdatadog_api to be built
1 parent dcdfcb1 commit 77dfd10

File tree

6 files changed

+51
-22
lines changed

6 files changed

+51
-22
lines changed

Rakefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ CORE_WITH_LIBDATADOG_API = [
2929
'spec/datadog/core/ddsketch_spec.rb',
3030
].freeze
3131

32+
# Data Streams Monitoring (DSM) requires libdatadog_api for DDSketch
33+
# Add new instrumentation libraries here as they gain DSM support
34+
DSM_ENABLED_LIBRARIES = [
35+
:kafka,
36+
:karafka
37+
].freeze
38+
3239
# rubocop:disable Metrics/BlockLength
3340
namespace :test do
3441
desc 'Run all tests'
@@ -295,6 +302,22 @@ namespace :spec do
295302
end
296303
end
297304

305+
# Ensure DSM-enabled contrib tests compile libdatadog_api before running (MRI Ruby only)
306+
# If compilation fails (e.g., new Ruby version without prebuilt extension), tests will skip via DDSketch.supported?
307+
unless RUBY_PLATFORM == 'java'
308+
task :compile_libdatadog_for_dsm do
309+
Rake::Task["compile:libdatadog_api.#{RUBY_VERSION[/\d+.\d+/]}_#{RUBY_PLATFORM}"].invoke
310+
rescue => e
311+
# Compilation failed (likely unsupported Ruby version) - tests will skip gracefully
312+
puts "Warning: libdatadog_api compilation failed: #{e.message}"
313+
puts "DSM tests will be skipped for this Ruby version"
314+
end
315+
316+
DSM_ENABLED_LIBRARIES.each do |task_name|
317+
Rake::Task["spec:#{task_name}"].enhance([:compile_libdatadog_for_dsm])
318+
end
319+
end
320+
298321
namespace :appsec do
299322
task all: [
300323
:main,

lib/datadog/core/ddsketch.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,13 @@ module Core
88
# APIs in this class are implemented as native code.
99
class DDSketch
1010
def self.supported?
11-
return @supported if defined?(@supported)
11+
return false unless Datadog::Core::LIBDATADOG_API_FAILURE.nil?
1212

13-
@supported = begin
14-
return false unless Datadog::Core::LIBDATADOG_API_FAILURE.nil?
15-
16-
# Test that DDSketch actually works by trying to instantiate it
17-
new
18-
true
19-
rescue ArgumentError
20-
false
21-
end
13+
# Test that DDSketch actually works by trying to instantiate it
14+
new
15+
true
16+
rescue ArgumentError
17+
false
2218
end
2319

2420
def initialize

lib/datadog/tracing/data_streams/processor.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -390,21 +390,15 @@ def record_checkpoint_stats(hash:, parent_hash:, edge_latency_sec:, payload_size
390390

391391
# Get or create stats for this pathway ( aggr_key = (",".join(edge_tags), hash_value, parent_hash))
392392
aggr_key = [tags.join(','), hash, parent_hash]
393-
394-
begin
395-
stats = bucket[:pathway_stats][aggr_key] ||= create_pathway_stats
396-
rescue ArgumentError => e
397-
# DDSketch failed (e.g. in forked process where extension isn't available)
398-
Datadog.logger.debug("DSM processor disabled: #{e.message}")
399-
@enabled = false
400-
return nil
401-
end
393+
stats = bucket[:pathway_stats][aggr_key] ||= create_pathway_stats
402394

403395
# Add latencies to DDSketch ()
404396
full_pathway_latency_sec = timestamp_sec - @pathway_context.pathway_start_sec
405397
stats[:edge_latency].add(edge_latency_sec)
406398
stats[:full_pathway_latency].add(full_pathway_latency_sec)
407399
end
400+
401+
true
408402
end
409403

410404
# Record consumer offset stats for DSM reporting

sig/datadog/tracing/data_streams/processor.rbs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ module Datadog
1616

1717
@stats_mutex: untyped
1818

19-
@ddsketch_class: untyped
20-
2119
@agent_transport: untyped
2220

2321
include Core::Workers::Polling
2422
include Core::Workers::IntervalLoop
2523

2624
attr_accessor enabled: untyped
2725

28-
def initialize: (?ddsketch_class: untyped, ?interval: untyped?) -> void
26+
def initialize: (?interval: untyped?) -> void
2927
def track_kafka_produce: (untyped topic, untyped partition, untyped offset, untyped now_sec) -> (nil | true)
3028
def track_kafka_commit: (untyped group, untyped topic, untyped partition, untyped offset, untyped now_sec) -> (nil | true)
3129
def track_kafka_consume: (untyped topic, untyped partition, untyped offset, ?untyped? now_sec) -> (nil | true)

spec/datadog/tracing/contrib/kafka/data_streams_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'datadog/tracing/contrib/support/spec_helper'
4+
require 'datadog/core/ddsketch'
45
require 'ostruct'
56
require 'datadog/tracing/contrib/kafka/integration'
67
require 'datadog/tracing/contrib/kafka/instrumentation/producer'
@@ -78,6 +79,10 @@ def each_batch(**kwargs)
7879
end
7980

8081
describe 'pathway context' do
82+
before do
83+
skip('DDSketch not available') unless Datadog::Core::DDSketch.supported?
84+
end
85+
8186
let(:test_producer_class) do
8287
Class.new do
8388
attr_accessor :pending_message_queue
@@ -136,6 +141,10 @@ def deliver_messages(**kwargs)
136141
end
137142

138143
describe 'checkpointing' do
144+
before do
145+
skip('DDSketch not available') unless Datadog::Core::DDSketch.supported?
146+
end
147+
139148
let(:test_producer_class) do
140149
Class.new do
141150
attr_accessor :pending_message_queue

spec/datadog/tracing/contrib/karafka/data_streams_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'datadog/tracing/contrib/support/spec_helper'
4+
require 'datadog/core/ddsketch'
45
require 'ostruct'
56

67
RSpec.describe 'Karafka Data Streams Integration' do
@@ -73,6 +74,10 @@ def build_karafka_messages(messages_data, topic_name = 'test_topic', partition =
7374
end
7475

7576
describe 'auto-instrumentation' do
77+
before do
78+
skip('DDSketch not available') unless Datadog::Core::DDSketch.supported?
79+
end
80+
7681
it 'automatically extracts and processes pathway context when consuming messages' do
7782
processor = Datadog.configuration.tracing.data_streams.processor
7883

@@ -139,6 +144,10 @@ def build_karafka_messages(messages_data, topic_name = 'test_topic', partition =
139144
end
140145

141146
describe 'pathway propagation across services' do
147+
before do
148+
skip('DDSketch not available') unless Datadog::Core::DDSketch.supported?
149+
end
150+
142151
it 'maintains pathway continuity through produce → consume → produce chain' do
143152
processor = Datadog.configuration.tracing.data_streams.processor
144153

0 commit comments

Comments
 (0)