feat(instrumentation): add profiler_enabled to gate the continuous profiler (opt-out) - #166
Conversation
0b9ea7a to
01f560c
Compare
01f560c to
c25c7fe
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c25c7fe. Configure here.
| // preserves the previous behaviour (profiler on wherever Enabled is on) | ||
| // while allowing a service to keep tracing but disable the profiler via | ||
| // profiler_enabled: false. | ||
| enabled: config.Enabled && config.ProfilerEnabled, |
There was a problem hiding this comment.
Manual Config disables profiler
Medium Severity
NewProfiler now requires both config.Enabled and config.ProfilerEnabled, but only NewConfig defaults profiler_enabled to true. A hand-built Config with Enabled: true and an unset ProfilerEnabled leaves profiling off, whereas before this change the profiler followed Enabled alone.
Reviewed by Cursor Bugbot for commit c25c7fe. Configure here.
There was a problem hiding this comment.
Valid observation, but it does not occur in practice: instrumentation.Config is always produced by NewConfig() — directly, or via configuration.NewConfig() (pkg/configuration/configuration.go) which every consumer uses — and NewConfig defaults profiler_enabled to true. So a real caller always follows Enabled; only tests construct a Config{} literal, where the zero value is expected. Keeping the Enabled && ProfilerEnabled gate (rather than reading ProfilerEnabled alone) is deliberate so profiling never turns on where instrumentation is disabled. If we want to be defensive about hand-built configs too, I can switch the field to *bool (nil → follow Enabled), but that adds complexity for a path we do not use.
c25c7fe to
cd1dc10
Compare
…ofiler Add a `profiler_enabled` setting so a service can keep tracing while turning the continuous profiler off (e.g. to avoid per-host profiling usage in non-production environments). It is opt-out: `profiler_enabled` defaults to true, so upgrading go-sdk does not change behavior for existing services — the profiler stays on wherever instrumentation is enabled. Disable it per environment with `profiler_enabled: false` or `APP_DATADOG_PROFILER_ENABLED=false`. Also fix the config builder to apply defaults before binding env vars, so that a default-only key (like profiler_enabled, absent from the config file) is still env-overridable. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
cd1dc10 to
7959a51
Compare


Why
The continuous profiler is gated on
instrumentation.enabled— the same flag that turns on APM tracing. So there is no way to keep tracing while turning the profiler off. That matters because the profiler bills per host, and in shared dev environments it inflates continuous-profiler host usage across many short-lived instances.What
Add a dedicated
profiler_enabledsetting so the profiler can be turned off independently of tracing:config.go: addProfilerEnabled bool(mapstructure:"profiler_enabled"), and default it totrueinNewConfig(SetDefault("profiler_enabled", true)).profiler.go: the profiler runs whenEnabled && ProfilerEnabled. With the default, this is identical to today's behaviour (profiler on wherever instrumentation is enabled).profiler_test.go; default-true +APP_DATADOG_PROFILER_ENABLEDopt-out coverage inconfig_test.go.Opt-out, not opt-in (backwards compatible)
Per review feedback: profiling is a deliberate default in Go SDK (cheap, valuable in prod). So this is opt-out —
profiler_enableddefaults totrue, and upgrading go-sdk does not change behaviour for any service. To disable the profiler while keeping tracing, set per environment:or via env var
APP_DATADOG_PROFILER_ENABLED=false.Rollout
After release, go-sdk upgrades reach services via Go Chassis parity (profiler stays on by default). To stop dev/devkube profiling for api-gateway, add
APP_DATADOG_PROFILER_ENABLED=falseto itsdevkube-configdeployment.Verification
build(go build+go test ./...).Note
Medium Risk
Touches shared configuration loading for all Viper-backed configs and changes profiler startup gating; default-on preserves prod behavior but mis-set env/YAML could unexpectedly disable profiling in some environments.
Overview
Adds
profiler_enabledso the DataDog continuous profiler can be turned off while APM tracing stays on, via YAML (profiler_enabled: false) orAPP_DATADOG_PROFILER_ENABLED=false. The flag defaults totrue, so existing services keep profiler-on-when-instrumentation-is-on behavior after upgrading.NewProfilernow enables profiling only whenEnabled && ProfilerEnabled(previously profiler followedEnabledalone).The shared Viper builder applies
SetDefaultbeforeAllKeys/BindEnv, so keys that exist only as defaults (not in the YAML file) still get env binding—required forprofiler_enabledoverrides without adding the key to everydatadog.yml.README profiling section documents the opt-out; tests cover default-true config, env opt-out, and the profiler gating matrix.
Reviewed by Cursor Bugbot for commit 7959a51. Bugbot is set up for automated code reviews on this repo. Configure here.