Deduplicate command tracing provider lifecycle wiring#7840
Merged
Conversation
Copilot
AI
changed the title
[WIP] Refactor duplicate tracing provider lifecycle in cmd commands
Deduplicate command tracing provider lifecycle wiring
Jun 20, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces drift risk in the CLI by centralizing OpenTelemetry tracing provider lifecycle wiring (init + deferred shutdown + warning callbacks) into a shared helper in internal/cmd/tracing.go, while preserving the existing tracing enablement semantics for run() and runProxy().
Changes:
- Added
setupCommandTracing(...)to initialize the tracing provider and return a cleanup function that performs shutdown with timeout. - Added
logTracingWarnf(...)to remove repeated inlinelog.Printf("Warning: ...")lambdas. - Updated root and proxy commands to use the shared helper, and extended unit tests to cover the new helper behavior.
Show a summary per file
| File | Description |
|---|---|
| internal/cmd/tracing.go | Adds shared helper(s) for tracing provider init + shutdown lifecycle and shared warning logging. |
| internal/cmd/tracing_helpers_test.go | Adds TestSetupCommandTracing to validate helper returns a provider + safe cleanup. |
| internal/cmd/root.go | Replaces duplicated tracing lifecycle code with setupCommandTracing(...) while keeping startup warning semantics via logger.StartupWarn. |
| internal/cmd/proxy.go | Uses the shared helper for tracing lifecycle while keeping proxy enablement logging tied to explicit proxy tracing config. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
run()andrunProxy()had copy-pasted tracing lifecycle code (provider init + deferred shutdown + warning callbacks), which created avoidable drift risk. This PR centralizes that lifecycle wiring in one helper while preserving each command’s existing tracing-config semantics.Tracing lifecycle extraction
setupCommandTracing(...)ininternal/cmd/tracing.goto own provider initialization and deferred shutdown wiring.logTracingWarnf(...)to remove repeated inline warning lambdas.Command integration
internal/cmd/root.gonow usessetupCommandTracing(...)with:logger.StartupWarnlogTracingWarnfinternal/cmd/proxy.gonow usessetupCommandTracing(...)withlogTracingWarnffor both init/shutdown warnings.tracingCfg != nil), matching prior behavior.Focused helper coverage
internal/cmd/tracing_helpers_test.gowithTestSetupCommandTracingto assert the helper returns a provider + cleanup function and that noop cleanup is safe.