Migrate OTEL config to use generic field framework #2486
Closed
+340
−556
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Refactors OpenTelemetry configuration commands to use the generic config field framework introduced in #2483, demonstrating the framework's value by eliminating ~450 lines of boilerplate code.
Note: This PR is based on #2483 and includes those commits. It should be reviewed after #2483 is merged. The actual changes in this PR are only in the most recent commit.
Changes
New OTEL Field Registrations (
pkg/config/fields_otel.go)Registers 7 OTEL fields with the generic framework:
otel-endpoint: OTLP endpoint URL with protocol validationotel-sampling-rate: Sampling rate with 0.0-1.0 range validationotel-env-vars: Comma-separated environment variablesotel-metrics-enabled: Boolean metrics export flagotel-tracing-enabled: Boolean tracing export flagotel-insecure: Boolean insecure connection flagotel-enable-prometheus-metrics-path: Boolean Prometheus metrics path flagRefactored Commands (
cmd/thv/app/otel.go)Replaced boilerplate functions with three generic helpers:
createOTELSetCommand()- Generic set command generatorcreateOTELGetCommand()- Generic get command generatorcreateOTELUnsetCommand()- Generic unset command generatorBenefits
✅ Dramatic Code Reduction: 78% less code (577 → 127 lines)
✅ Consistent Behavior: All commands use the same framework logic
✅ Easier Maintenance: Changes to validation/error handling apply to all fields
✅ Proven Pattern: Same approach used for ca-cert, registry-url, registry-file
✅ No Behavioral Changes: All OTEL commands work identically
Before & After
Before (per field):
After (all fields):
Test Plan
--help)Dependencies
Depends on #2483 - This PR is stacked on top of the config field framework PR. Review #2483 first.
🤖 Generated with Claude Code