Standardize enable option handling across all plugins#324
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
430542d to
dd508cf
Compare
Introduce a shared `resolveEnable` helper in @dd/core that all six user-facing plugins now use to resolve their `enable` config flag. This replaces the two divergent patterns (explicit `??` vs spread- override) with a single greppable call site per plugin. Non-boolean values continue to be coerced for backwards compatibility but now emit a deprecation warning so strict validation can land in the next major. live-debugger retains its existing hard rejection via the companion `validateEnableStrict` helper. Also fixes the misleading `default: true` wording in the output and metrics READMEs, adds the missing `errorTracking.enable` docs section, and authors a full README for the rum plugin (lost in the sourcemaps extraction refactor of 804f917).
dd508cf to
00679a8
Compare
yoannmoinet
left a comment
There was a problem hiding this comment.
Looks mostly good.
I wonder if we could handle one level higher than just resolveEnable and have something like a global validateOptions, that would, for now, validate enable.
It would be called from each plugin, but would be implemented, tested and documented just once.
Since this is a standard, this can be documented just at the root, once, and not for each individual plugin.
Or alternatively, handle this at the factory level directly, where we also have an validateOptions too.
build-plugins/packages/factory/src/index.ts
Lines 176 to 190 in 00679a8
This way, plugins themselves don't even have to handle it.
The standard is applied by design.
I think I prefer the factory approach after all.
WDYT?
| const mockLogger: Logger = { | ||
| getLogger: jest.fn(() => mockLogger), | ||
| time: jest.fn() as unknown as Logger['time'], | ||
| error: jest.fn(), | ||
| warn: jest.fn(), | ||
| info: jest.fn(), | ||
| debug: jest.fn(), | ||
| }; |
There was a problem hiding this comment.
This already exists.
build-plugins/packages/tests/src/_jest/helpers/mocks.ts
Lines 118 to 136 in 00679a8
Same thing in the other test files.
There was a problem hiding this comment.
This should live in its own PR.

What and why?
The six user-facing plugins (
apps,error-tracking,live-debugger,metrics,output,rum) each had a divergent implementation for resolving theirenableconfig boolean:appsandlive-debuggerused explicit??nullish coalescing, while the other four used a spread-override trick (enable: !!config[KEY], ...config[KEY]) that relies on property ordering.live-debuggerrejected non-boolean values; the rest silently coerced.outputandmetricsdocumenteddefault: true(misleading — it's false when the config block is absent),error-trackinghad noenablesection at all, andrumhad no README (lost in the sourcemaps extraction refactor of 804f917).This PR standardizes all three axes so future plugins have a single pattern to follow.
How?
Shared helper (
@dd/core/helpers/options):resolveEnable(options, configKey, log)— single source of truth for resolvingenable. Emits a deprecation warning (once per key) when a non-boolean value is passed, but still coerces it with!!to avoid breaking existing users. Strict rejection is deferred to the next major.validateEnableStrict(pluginConfig, errors)— pushes a hard validation error for non-booleans. Used only bylive-debugger, preserving its existing contract.Plugin refactors:
resolveEnable()instead of ad-hoc logic.appsandoutputgained alogparameter (call sites updated). For the spread-override plugins,enableis now set after the spread so it can never be silently overwritten.Documentation:
### <key>.enablesection with the correct default wording: "truewhen a<key>config block is present,falseotherwise."error-trackinggained its missingenablesection and TOC entry.rumREADME was authored coveringenable,sdk.*,privacy.*, andsourceCodeContext.*.Tests:
enablecases asserting the deprecation warning.