Respect global config for OTel tracing and metrics enabled#4326
Respect global config for OTel tracing and metrics enabled#4326amirejaz merged 4 commits intostacklok:mainfrom
Conversation
thv config otel set-tracing-enabled false was silently ignored by thv run because getTelemetryFromFlags had no fallback for these two fields, and buildRunConfig bypassed the fallback entirely for the proxy runner config. Users could not globally disable telemetry without passing CLI flags on every invocation. Fixes stacklok#4323 Signed-off-by: Greg Katz <gkatz@indeed.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes thv run ignoring global OpenTelemetry tracing-enabled / metrics-enabled settings by introducing proper config fallbacks and representing “unset vs explicitly false” in the global config model.
Changes:
- Update global
OpenTelemetryConfigto use*boolforTracingEnabled/MetricsEnabledto preserve “never set” vs “explicitly disabled”. - Extend
getTelemetryFromFlagsfallbacks to include tracing/metrics enabled, and use the resolved values when building telemetry config. - Update config CLI setters/getters/unsetters and expand unit test coverage for telemetry flag/config resolution.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
pkg/config/config.go |
Switch tracing/metrics enabled fields to *bool and add rationale comment. |
cmd/thv/app/run_flags.go |
Add tracing/metrics config fallback and adjust telemetry creation / legacy runconfig wiring. |
cmd/thv/app/otel.go |
Update config mutation and printing logic to work with *bool. |
cmd/thv/app/run_flags_test.go |
Add/adjust tests for tracing/metrics fallback behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4326 +/- ##
==========================================
+ Coverage 69.46% 69.47% +0.01%
==========================================
Files 485 485
Lines 49821 49821
==========================================
+ Hits 34608 34613 +5
+ Misses 12535 12528 -7
- Partials 2678 2680 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Cover the createTelemetryConfig early-return when both tracing and metrics are disabled with the endpoint still configured. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Greg Katz <gkatz@indeed.com>
Fix unset guard to check nil only, not nil-or-false, so users can unset an explicit false value. Return a struct from getTelemetryFromFlags instead of 8 positional values. Default tracing/metrics to false when telemetry config is nil to avoid fragile fallback to runFlags. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Greg Katz <gkatz@indeed.com>
jhrozek
left a comment
There was a problem hiding this comment.
All three findings addressed cleanly. LGTM.
Summary
thv config otel set-tracing-enabled falsewas silently ignored bythv runbecausegetTelemetryFromFlagshad no fallback forTracingEnabledorMetricsEnabled, andbuildRunConfigbypassed the fallback entirely for the proxy runner configFixes #4323
Type of change
Test plan
task test)task lint-fix)Deployed a local build and verified:
tracing-enabled: falseandmetrics-enabled: false,thv runproduces a runconfig withnulltelemetry (no telemetry initialized)--otel-tracing-enabled=true, CLI flag correctly overrides global configconfig.yamlnow showstracing-enabled: falseinstead of silently dropping the fieldChanges
pkg/config/config.goTracingEnabled/MetricsEnabledfromboolwithomitemptyto*boolwithoutomitempty, matching the existingUseLegacyAttributespatterncmd/thv/app/run_flags.gogetTelemetryFromFlags; use resolved values inbuildRunConfig; return nil fromcreateTelemetryConfigwhen both signals are disabledcmd/thv/app/otel.go*boolcmd/thv/app/run_flags_test.goDoes this introduce a user-facing change?
thv config otel set-tracing-enabledandset-metrics-enablednow take effect when starting servers withthv run. Previously these settings were silently ignored.Special notes for reviewers
The
*boolpattern (nil = never set, false = explicitly disabled) is necessary because the CLI defaults for these flags aretrue, unlikeInsecureandEnablePrometheusMetricsPathwhich default tofalse. A struct-level comment onOpenTelemetryConfigexplains this distinction.Generated with Claude Code