Fix 'load core only and configure library with no settings' spec when run locally#5555
Fix 'load core only and configure library with no settings' spec when run locally#5555
Conversation
|
Thank you for updating Change log entry section 👏 Visited at: 2026-04-02 15:49:37 UTC |
Typing analysisNote: Ignored files are excluded from the next sections.
|
|
The fix is suggested by Cursor, maybe there is a better fix? |
| # Profiling is not loaded when disabled (see Profiling::Component.build_profiler_component); skip error payload | ||
| if Datadog::Profiling.respond_to?(:unsupported_reason) && (unsupported_reason = Datadog::Profiling.unsupported_reason) |
There was a problem hiding this comment.
This doesn't look right? lib/datadog/profiling.rb is loaded even when disabled -- so if the module is loaded, the unsupported_reason method is expected to be here.
There was a problem hiding this comment.
See
which seems the likely cause.I checked and I indeed get the NoMethodError when undoing this change.
There was a problem hiding this comment.
Ah, you're right. It's because of the big comment above it -- we delay requiring profiling to break the potential require cycle.
Yeaaaah this whole thing needs a bit of a clean-up. Thanks for spotting it. I think this is indeed the correct interim fix for now.
| @@ -52,7 +52,8 @@ def products(components) | |||
| products = { | |||
| appsec: { | |||
| # TODO take appsec status out of component tree? | |||
There was a problem hiding this comment.
To address this at the same time maybe it should be components.appsec&.enabled? or so, but I'm not sure what kind of object is components.appsec when not nil.
There was a problem hiding this comment.
Welcome to some of our legacy issues haha! The configuration system... is weird... and some things monkey patch themselves in there for reasons that made sense at the time when we wrote them but no longer make sense in 2026+
There was a problem hiding this comment.
I tried and it doesn't work:
1) Datadog::Core::Telemetry::Event::AppStarted.payload with stable config with config id reports config id
Failure/Error: enabled: !!components.appsec&.enabled?,
NoMethodError:
undefined method 'enabled?' for an instance of Datadog::AppSec::Component
# ./lib/datadog/core/telemetry/event/app_started.rb:54:in 'Datadog::Core::Telemetry::Event::AppStarted#products'
# ./lib/datadog/core/telemetry/event/app_started.rb:22:in 'Datadog::Core::Telemetry::Event::AppStarted#initialize'
# ./spec/datadog/core/telemetry/event/app_started_spec.rb:7:in 'Class#new'
# ./spec/datadog/core/telemetry/event/app_started_spec.rb:7:in 'block (2 levels) in <top (required)>'
# ./spec/datadog/core/telemetry/event/app_started_spec.rb:256:in 'block (5 levels) in <top (required)>'
# ./spec/spec_helper.rb:274:in 'block (2 levels) in <top (required)>'
# ./spec/spec_helper.rb:154:in 'block (2 levels) in <top (required)>'
# ./spec/support/execute_in_fork.rb:32:in 'ForkableExample#run'
2) Datadog::Core::Telemetry::Event::AppStarted.payload with stable config with config id without config id does not report config id
Failure/Error: enabled: !!components.appsec&.enabled?,
NoMethodError:
undefined method 'enabled?' for an instance of Datadog::AppSec::Component
# ./lib/datadog/core/telemetry/event/app_started.rb:54:in 'Datadog::Core::Telemetry::Event::AppStarted#products'
# ./lib/datadog/core/telemetry/event/app_started.rb:22:in 'Datadog::Core::Telemetry::Event::AppStarted#initialize'
# ./spec/datadog/core/telemetry/event/app_started_spec.rb:7:in 'Class#new'
# ./spec/datadog/core/telemetry/event/app_started_spec.rb:7:in 'block (2 levels) in <top (required)>'
# ./spec/datadog/core/telemetry/event/app_started_spec.rb:273:in 'block (6 levels) in <top (required)>'
# ./spec/spec_helper.rb:274:in 'block (2 levels) in <top (required)>'
# ./spec/spec_helper.rb:154:in 'block (2 levels) in <top (required)>'
# ./spec/support/execute_in_fork.rb:32:in 'ForkableExample#run'
There was a problem hiding this comment.
https://github.com/DataDog/dd-trace-rb/blob/master/lib/datadog/appsec/extensions.rb is where the appsec settings "show up" -- TBH we should just eagerly load all the settings instead of doing this but maybe not for this PR yet?
There was a problem hiding this comment.
How about lib/datadog/appsec/component.rb defining an enabled? method when build_appsec_component doesn't return nil?
There was a problem hiding this comment.
I guess that would work as well, but to me is slightly more weird than the settings.respond_to?(:appsec) as usually we don't ask the components about things being enabled -- that's usually the job of the settings.
(But no strong feelings on it, I think that one would work too for now)
There was a problem hiding this comment.
FYI I worked on this in #5075, maybe you will find it helpful.
There was a problem hiding this comment.
Overall I think our old "modularization" efforts mostly failed, so I'm of the opinion that in the future (not in this PR) we should just clean up the wish-it-was-modular code.
(Not for this PR :P) Once we're ready/need to be modular, then we can actually do the work end-to-end, I don't think we're saving ourselves any work from keeping the half-broken migration as-is.
There was a problem hiding this comment.
I like the direction #5075 is going, this PR feels too hacky for me.
What's the reason it was closed?
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 711390a | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
e83c1f1 to
711390a
Compare
BenchmarksBenchmark execution time: 2026-04-03 13:16:22 Comparing candidate commit 711390a in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 45 metrics, 1 unstable metrics.
|
ivoanjo
left a comment
There was a problem hiding this comment.
👍 LGTM, thanks for catching this one!
| # Profiling is not loaded when disabled (see Profiling::Component.build_profiler_component); skip error payload | ||
| if Datadog::Profiling.respond_to?(:unsupported_reason) && (unsupported_reason = Datadog::Profiling.unsupported_reason) |
There was a problem hiding this comment.
Ah, you're right. It's because of the big comment above it -- we delay requiring profiling to break the potential require cycle.
Yeaaaah this whole thing needs a bit of a clean-up. Thanks for spotting it. I think this is indeed the correct interim fix for now.
What does this PR do?
Fix a spec failing when running the test suite locally:
dd-trace-rb/spec/loading_spec.rb
Lines 76 to 96 in e191a14
Motivation:
Be green.
Change log entry
None.
Additional Notes:
How to test the change?