Skip to content

Respect global config for OTel tracing and metrics enabled#4326

Merged
amirejaz merged 4 commits intostacklok:mainfrom
gkatz2:fix/otel-global-tracing-metrics-config
Mar 30, 2026
Merged

Respect global config for OTel tracing and metrics enabled#4326
amirejaz merged 4 commits intostacklok:mainfrom
gkatz2:fix/otel-global-tracing-metrics-config

Conversation

@gkatz2
Copy link
Copy Markdown
Contributor

@gkatz2 gkatz2 commented Mar 24, 2026

Summary

  • thv config otel set-tracing-enabled false was silently ignored by thv run because getTelemetryFromFlags had no fallback for TracingEnabled or MetricsEnabled, 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 #4323

Type of change

  • Bug fix

Test plan

  • Unit tests (task test)
  • Linting (task lint-fix)
  • Manual testing (describe below)

Deployed a local build and verified:

  1. With global config tracing-enabled: false and metrics-enabled: false, thv run produces a runconfig with null telemetry (no telemetry initialized)
  2. With explicit --otel-tracing-enabled=true, CLI flag correctly overrides global config
  3. config.yaml now shows tracing-enabled: false instead of silently dropping the field

Changes

File Change
pkg/config/config.go Change TracingEnabled/MetricsEnabled from bool with omitempty to *bool without omitempty, matching the existing UseLegacyAttributes pattern
cmd/thv/app/run_flags.go Add config fallback for both fields in getTelemetryFromFlags; use resolved values in buildRunConfig; return nil from createTelemetryConfig when both signals are disabled
cmd/thv/app/otel.go Update setters/getters/unsetters for *bool
cmd/thv/app/run_flags_test.go Update existing tests and add 4 new cases for tracing/metrics fallback

Does this introduce a user-facing change?

thv config otel set-tracing-enabled and set-metrics-enabled now take effect when starting servers with thv run. Previously these settings were silently ignored.

Special notes for reviewers

The *bool pattern (nil = never set, false = explicitly disabled) is necessary because the CLI defaults for these flags are true, unlike Insecure and EnablePrometheusMetricsPath which default to false. A struct-level comment on OpenTelemetryConfig explains this distinction.

Generated with Claude Code

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>
@github-actions github-actions bot added the size/S Small PR: 100-299 lines changed label Mar 24, 2026
@amirejaz amirejaz requested a review from Copilot March 24, 2026 11:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 OpenTelemetryConfig to use *bool for TracingEnabled/MetricsEnabled to preserve “never set” vs “explicitly disabled”.
  • Extend getTelemetryFromFlags fallbacks 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
Copy link
Copy Markdown

codecov bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.47%. Comparing base (2a89245) to head (bca7200).
⚠️ Report is 27 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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>
@github-actions github-actions bot added size/S Small PR: 100-299 lines changed and removed size/S Small PR: 100-299 lines changed labels Mar 24, 2026
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>
@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/S Small PR: 100-299 lines changed labels Mar 25, 2026
Copy link
Copy Markdown
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

All three findings addressed cleanly. LGTM.

@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Mar 27, 2026
@amirejaz amirejaz merged commit eb0d405 into stacklok:main Mar 30, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Global OTel tracing-enabled and metrics-enabled config ignored by thv run

4 participants