Skip to content

feat(instrumentation): add profiler_enabled to gate the continuous profiler (opt-out) - #166

Merged
Neurostep merged 1 commit into
mainfrom
kamranf/decouple-profiler-from-instrumentation
Jul 17, 2026
Merged

feat(instrumentation): add profiler_enabled to gate the continuous profiler (opt-out)#166
Neurostep merged 1 commit into
mainfrom
kamranf/decouple-profiler-from-instrumentation

Conversation

@kamranf

@kamranf kamranf commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

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_enabled setting so the profiler can be turned off independently of tracing:

  • config.go: add ProfilerEnabled bool (mapstructure:"profiler_enabled"), and default it to true in NewConfig (SetDefault("profiler_enabled", true)).
  • profiler.go: the profiler runs when Enabled && ProfilerEnabled. With the default, this is identical to today's behaviour (profiler on wherever instrumentation is enabled).
  • Tests: gating matrix in profiler_test.go; default-true + APP_DATADOG_PROFILER_ENABLED opt-out coverage in config_test.go.
  • README: documents the opt-out.

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-outprofiler_enabled defaults to true, and upgrading go-sdk does not change behaviour for any service. To disable the profiler while keeping tracing, set per environment:

# config/settings/datadog.yml
development:
  enabled: true
  profiler_enabled: false

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=false to its devkube-config deployment.

Verification

  • CI 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_enabled so the DataDog continuous profiler can be turned off while APM tracing stays on, via YAML (profiler_enabled: false) or APP_DATADOG_PROFILER_ENABLED=false. The flag defaults to true, so existing services keep profiler-on-when-instrumentation-is-on behavior after upgrading.

NewProfiler now enables profiling only when Enabled && ProfilerEnabled (previously profiler followed Enabled alone).

The shared Viper builder applies SetDefault before AllKeys / BindEnv, so keys that exist only as defaults (not in the YAML file) still get env binding—required for profiler_enabled overrides without adding the key to every datadog.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.

@kamranf
kamranf force-pushed the kamranf/decouple-profiler-from-instrumentation branch 2 times, most recently from 0b9ea7a to 01f560c Compare July 14, 2026 14:24
@kamranf
kamranf marked this pull request as ready for review July 14, 2026 14:55
@kamranf
kamranf requested a review from a team as a code owner July 14, 2026 14:55
@kamranf
kamranf force-pushed the kamranf/decouple-profiler-from-instrumentation branch from 01f560c to c25c7fe Compare July 17, 2026 13:21
@kamranf kamranf changed the title feat(instrumentation)!: gate continuous profiler behind profiler_enabled feat(instrumentation): add profiler_enabled to gate the continuous profiler (opt-out) Jul 17, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c25c7fe. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kamranf
kamranf force-pushed the kamranf/decouple-profiler-from-instrumentation branch from c25c7fe to cd1dc10 Compare July 17, 2026 13:29
…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>
@kamranf
kamranf force-pushed the kamranf/decouple-profiler-from-instrumentation branch from cd1dc10 to 7959a51 Compare July 17, 2026 13:51
@kamranf
kamranf requested a review from Neurostep July 17, 2026 14:06

@Neurostep Neurostep left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@Neurostep
Neurostep merged commit 56ac199 into main Jul 17, 2026
7 checks passed
@Neurostep
Neurostep deleted the kamranf/decouple-profiler-from-instrumentation branch July 17, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants