Commit 971fb5a
authored
Refactor tracer fallback + logger helper layout to remove duplication and tighten logging semantics (#4213)
Semantic clustering flagged four targeted refactor opportunities:
duplicated tracer fallback logic, misplaced shared logger dispatch
state, unnecessary markdown logging indirection, and unclear
marshal-error handling in a logging helper. This PR consolidates those
seams without changing external behavior.
- **Tracer fallback deduplicated (`internal/tracing`, `internal/proxy`,
`internal/server`)**
- Added `tracing.GetCachedOrGlobal(cached trace.Tracer)` as the single
fallback path.
- Replaced duplicated `getTracer()` implementations in `proxyHandler`
and `UnifiedServer` with one-line calls to the shared helper.
- **`logFuncs` ownership moved to `common.go` (`internal/logger`)**
- Relocated shared `LogLevel -> function` dispatch map from
`file_logger.go` to `common.go`.
- Co-located implementation with the existing design guidance and
updated references to the new source location.
- **Markdown logging helper flow simplified
(`internal/logger/markdown_logger.go`)**
- Removed `logWithMarkdownLevel` indirection.
- Updated `logWithMarkdown` to resolve `logFuncs[level]` internally,
reducing one helper layer and tightening call flow for `Log*Md`
wrappers.
- **Marshal helper intent made explicit
(`internal/server/tool_registry.go`)**
- Documented `marshalAndSanitizeForLog` as best-effort logging behavior
when JSON marshaling fails (sanitized empty-string fallback by design).
```go
// internal/tracing/provider.go
func GetCachedOrGlobal(cached trace.Tracer) trace.Tracer {
if cached != nil {
return cached
}
return Tracer()
}
```
> [!WARNING]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses (expand for details)</summary>
>
> #### I tried to connect to the following addresses, but was blocked by
firewall rules:
>
> - `example.com`
> - Triggering command: `/tmp/go-build1164881766/b513/launcher.test
/tmp/go-build1164881766/b513/launcher.test
-test.testlogfile=/tmp/go-build1164881766/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s
/tmp/go-build1164881766/b437/vet.cfg _.a go x_amd64/vet --gdwarf-5 --64
-o x_amd64/vet -E mBfaT_lUZ 544961/b287/ x_amd64/vet -I . -imultiarch
x_amd64/vet` (dns block)
> - Triggering command: `/tmp/go-build3536398537/b513/launcher.test
/tmp/go-build3536398537/b513/launcher.test
-test.testlogfile=/tmp/go-build3536398537/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s list��
ithub-guard/rust-guard/target/de/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust/opt/hostedtoolcache/go/1.25.8/x64/pkg/tool/linux_amd64/link
s
Agent-Logs-Url: REDACTED
ithub-guard/rust-guard/target/de/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust/tmp/go-build3536398537/b507/guard.test
Ld/symbols.o 437f known-linux-gnu/-bool known-linux-gnu/-buildtags
know�� known-linux-gnu/-errorsas known-linux-gnu/-ifaceassert
known-linux-gnu/-nilfunc known-linux-gnu/bash
known-linux-gnu//usr/bin/runc known-linux-gnu/--version
known-linux-gnu/-tests` (dns block)
> - `invalid-host-that-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build1164881766/b495/config.test
/tmp/go-build1164881766/b495/config.test
-test.testlogfile=/tmp/go-build1164881766/b495/testlog.txt
-test.paniconexit0 -test.timeout=10m0s
/tmp/go-build1164881766/b395/vet.cfg /http2/ascii.go /http2/ciphers.go
x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet --de�� _.a zhqG-0L32
x_amd64/vet -I` (dns block)
> - Triggering command: `/tmp/go-build3536398537/b495/config.test
/tmp/go-build3536398537/b495/config.test
-test.testlogfile=/tmp/go-build3536398537/b495/testlog.txt
-test.paniconexit0 -test.timeout=10m0s lib/��
lib/rustlib/x86_/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust-guard/target/debash
lib/rustlib/x86_/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust-guard/target/de--norc
lib/rustlib/x86_/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust-guard/target/de--noprofile
lib/rustlib/x86_git lib/rustlib/x86_checkout
lib/rustlib/x86_copilot/refactor-semantic-function-clustering
lib/rustlib/x86_/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust-guard/target/debug/deps/github_guard-57d41235e07a5585.53ehv5r2twmuqycv01jbjtq95.19dllou.rcgu.o
lib/��
lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libminiz_oxide-2b6a8d2f6e1dc71b.rlib
lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libadler2-39ffdbc27c978ccc.rlib
"CURL_CA_BUNDLE=//home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/echo
"" c1063f.rlib .cfg` (dns block)
> - `nonexistent.local`
> - Triggering command: `/tmp/go-build1164881766/b513/launcher.test
/tmp/go-build1164881766/b513/launcher.test
-test.testlogfile=/tmp/go-build1164881766/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s
/tmp/go-build1164881766/b437/vet.cfg _.a go x_amd64/vet --gdwarf-5 --64
-o x_amd64/vet -E mBfaT_lUZ 544961/b287/ x_amd64/vet -I . -imultiarch
x_amd64/vet` (dns block)
> - Triggering command: `/tmp/go-build3536398537/b513/launcher.test
/tmp/go-build3536398537/b513/launcher.test
-test.testlogfile=/tmp/go-build3536398537/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s list��
ithub-guard/rust-guard/target/de/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust/opt/hostedtoolcache/go/1.25.8/x64/pkg/tool/linux_amd64/link
s
Agent-Logs-Url: REDACTED
ithub-guard/rust-guard/target/de/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust/tmp/go-build3536398537/b507/guard.test
Ld/symbols.o 437f known-linux-gnu/-bool known-linux-gnu/-buildtags
know�� known-linux-gnu/-errorsas known-linux-gnu/-ifaceassert
known-linux-gnu/-nilfunc known-linux-gnu/bash
known-linux-gnu//usr/bin/runc known-linux-gnu/--version
known-linux-gnu/-tests` (dns block)
> - `slow.example.com`
> - Triggering command: `/tmp/go-build1164881766/b513/launcher.test
/tmp/go-build1164881766/b513/launcher.test
-test.testlogfile=/tmp/go-build1164881766/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s
/tmp/go-build1164881766/b437/vet.cfg _.a go x_amd64/vet --gdwarf-5 --64
-o x_amd64/vet -E mBfaT_lUZ 544961/b287/ x_amd64/vet -I . -imultiarch
x_amd64/vet` (dns block)
> - Triggering command: `/tmp/go-build3536398537/b513/launcher.test
/tmp/go-build3536398537/b513/launcher.test
-test.testlogfile=/tmp/go-build3536398537/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s list��
ithub-guard/rust-guard/target/de/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust/opt/hostedtoolcache/go/1.25.8/x64/pkg/tool/linux_amd64/link
s
Agent-Logs-Url: REDACTED
ithub-guard/rust-guard/target/de/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rust/tmp/go-build3536398537/b507/guard.test
Ld/symbols.o 437f known-linux-gnu/-bool known-linux-gnu/-buildtags
know�� known-linux-gnu/-errorsas known-linux-gnu/-ifaceassert
known-linux-gnu/-nilfunc known-linux-gnu/bash
known-linux-gnu//usr/bin/runc known-linux-gnu/--version
known-linux-gnu/-tests` (dns block)
> - `this-host-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build1164881766/b522/mcp.test
/tmp/go-build1164881766/b522/mcp.test
-test.testlogfile=/tmp/go-build1164881766/b522/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -o cfg
om/modelcontextprotocol/go-sdk@v1.5.0/mcp/cmd.go x_amd64/vet -p
g/grpc/internal/--version -lang=go1.25 x_amd64/vet cfg /auth/header.go
/auth/header_test.go x_amd64/vet -c /cobra /tmp/go-build945544961/b287/
dWtd0aB/LlpLOT-ZzUhjnWEpG9lp` (dns block)
> - Triggering command: `/tmp/go-build3536398537/b522/mcp.test
/tmp/go-build3536398537/b522/mcp.test
-test.testlogfile=/tmp/go-build3536398537/b522/testlog.txt
-test.paniconexit0 -test.timeout=10m0s know��
known-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libobject-926daa94a00ee327.rlib
known-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libmemchr-48d5b0db80402653.rlib
known-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libaddr2line-3367f26bd486b29d.rlib
known-linux-gnu/bash known-linux-gnu//usr/bin/runc
known-linux-gnu/--version ive.12123747d8da05ed-cgu.00.rcgu.o ive.��
ive.12123747d8da05ed-cgu.02.rcgu.o ive.12123747d8da05ed-cgu.03.rcgu.o
ive.12123747d8da05ed-cgu.04.rcgu.o
ive.12123747d8da/usr/libexec/docker/cli-plugins/docker-buildx
ive.12123747d8dadocker-cli-plugin-metadata
ive.12123747d8da05ed-cgu.07.rcgu/tmp/go-build3867419718/b001/exe/a.out
ive.12123747d8da05ed-cgu.08.rcgu-importcfg` (dns block)
>
> If you need me to access, download, or install something from one of
these locations, you can either:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to the custom allowlist in this
repository's [Copilot coding agent
settings](https://github.com/github/gh-aw-mcpg/settings/copilot/coding_agent)
(admins only)
>
> </details>10 files changed
Lines changed: 51 additions & 40 deletions
File tree
- internal
- logger
- proxy
- server
- tracing
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
| 197 | + | |
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
205 | | - | |
206 | | - | |
| 205 | + | |
| 206 | + | |
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
211 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
212 | 224 | | |
213 | 225 | | |
214 | 226 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | 136 | | |
149 | 137 | | |
150 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
| 102 | + | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
173 | | - | |
| 173 | + | |
174 | 174 | | |
175 | | - | |
| 175 | + | |
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | 183 | | |
191 | 184 | | |
192 | | - | |
| 185 | + | |
193 | 186 | | |
194 | 187 | | |
195 | 188 | | |
196 | 189 | | |
197 | | - | |
| 190 | + | |
198 | 191 | | |
199 | 192 | | |
200 | 193 | | |
201 | 194 | | |
202 | | - | |
| 195 | + | |
203 | 196 | | |
204 | 197 | | |
205 | 198 | | |
206 | 199 | | |
207 | | - | |
| 200 | + | |
208 | 201 | | |
209 | 202 | | |
210 | 203 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 43 | + | |
47 | 44 | | |
48 | 45 | | |
49 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
350 | 350 | | |
351 | 351 | | |
352 | 352 | | |
| 353 | + | |
| 354 | + | |
353 | 355 | | |
354 | 356 | | |
355 | 357 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
| 127 | + | |
131 | 128 | | |
132 | 129 | | |
133 | 130 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
309 | 317 | | |
310 | 318 | | |
311 | 319 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
95 | 109 | | |
96 | 110 | | |
97 | 111 | | |
| |||
0 commit comments