refactor: extract ensureTracingConfig to eliminate repeated nil-guard#5317
Merged
Conversation
4 tasks
…l-guard Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/8259e187-c818-48bf-a4fa-9c902f1b2d6f Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix duplicate code pattern for Tracing config nil-guard
refactor: extract ensureTracingConfig to eliminate repeated nil-guard
May 8, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors CLI tracing flag handling in internal/cmd/root.go by extracting a small helper to lazily initialize cfg.Gateway.Tracing, removing repeated nil-guard blocks and keeping the “CLI flags override config” behavior intact.
Changes:
- Extracted
ensureTracingConfig(cfg)helper to initialize and returncfg.Gateway.Tracing. - Replaced three duplicated
cfg.Gateway.Tracing == nilblocks (endpoint/service-name/sample-rate) with helper calls.
Show a summary per file
| File | Description |
|---|---|
| internal/cmd/root.go | Introduces ensureTracingConfig and uses it to de-duplicate tracing flag application logic. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
Comment on lines
+458
to
+463
| // ensureTracingConfig returns cfg.Gateway.Tracing, initializing it if nil. | ||
| func ensureTracingConfig(cfg *config.Config) *config.TracingConfig { | ||
| if cfg.Gateway.Tracing == nil { | ||
| cfg.Gateway.Tracing = &config.TracingConfig{} | ||
| } | ||
| return cfg.Gateway.Tracing |
Collaborator
|
@copilot address the reiew feedback |
Copilot stopped work on behalf of
lpcox due to an error
May 8, 2026 15:43
This was referenced May 8, 2026
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.
Three consecutive copies of the same
cfg.Gateway.Tracing == nilguard ininternal/cmd/root.go— one per OTLP CLI flag — are collapsed into a single lazy-init helper.Changes
internal/cmd/root.go: AddensureTracingConfig(cfg *config.Config) *config.TracingConfighelper that initializescfg.Gateway.Tracingon first use and returns it; replace the three duplicated nil-guard blocks with calls to the helper.Any future OTLP flag now needs one line instead of four.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
example.com/tmp/go-build3163137263/b513/launcher.test /tmp/go-build3163137263/b513/launcher.test -test.testlogfile=/tmp/go-build3163137263/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s --de�� g_.a --debug-prefix-m-ifaceassert x_amd64/vet -I /known/anypb -I x_amd64/vet 0IST�� .cfg 2195407/b316/ x_amd64/vet 2195407/b263/sym/opt/hostedtoolcache/go/1.25.9/x64/pkg/tool/linux_amd64/compile -I /tmp/go-build183/tmp/go-build3163137263/b515/_pkg_.a x_amd64/vet(dns block)invalid-host-that-does-not-exist-12345.com/tmp/go-build3163137263/b495/config.test /tmp/go-build3163137263/b495/config.test -test.testlogfile=/tmp/go-build3163137263/b495/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3163137263/b398/vet.cfg 1.80.0/internal/resolver/dns/internal/internal.go -I x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet -I g_.a -I x_amd64/vet --gdwarf-5 resolver/dns -o x_amd64/vet(dns block)nonexistent.local/tmp/go-build3163137263/b513/launcher.test /tmp/go-build3163137263/b513/launcher.test -test.testlogfile=/tmp/go-build3163137263/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s --de�� g_.a --debug-prefix-m-ifaceassert x_amd64/vet -I /known/anypb -I x_amd64/vet 0IST�� .cfg 2195407/b316/ x_amd64/vet 2195407/b263/sym/opt/hostedtoolcache/go/1.25.9/x64/pkg/tool/linux_amd64/compile -I /tmp/go-build183/tmp/go-build3163137263/b515/_pkg_.a x_amd64/vet(dns block)slow.example.com/tmp/go-build3163137263/b513/launcher.test /tmp/go-build3163137263/b513/launcher.test -test.testlogfile=/tmp/go-build3163137263/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s --de�� g_.a --debug-prefix-m-ifaceassert x_amd64/vet -I /known/anypb -I x_amd64/vet 0IST�� .cfg 2195407/b316/ x_amd64/vet 2195407/b263/sym/opt/hostedtoolcache/go/1.25.9/x64/pkg/tool/linux_amd64/compile -I /tmp/go-build183/tmp/go-build3163137263/b515/_pkg_.a x_amd64/vet(dns block)this-host-does-not-exist-12345.com/tmp/go-build3163137263/b522/mcp.test /tmp/go-build3163137263/b522/mcp.test -test.testlogfile=/tmp/go-build3163137263/b522/testlog.txt -test.paniconexit0 -test.timeout=10m0s -W .cfg olang.org/grpc@v-ifaceassert x_amd64/vet . ions =0 x_amd64/vet .cfg�� 2195407/b387/_pkg_.a 2195407/b316/ x_amd64/vet --gdwarf-5 g/grpc/balancer/--version p=/opt/hostedtoolcache/go/1.25.9-bool x_amd64/vet(dns block)If you need me to access, download, or install something from one of these locations, you can either: