Commit df79a19
authored
refactor: deduplicate reconnect telemetry and SSE deprecation logging in connection.go (#3660)
Three duplicate logging patterns in `internal/mcp/connection.go` created
maintainability risk: reconnect lifecycle logs were copy-pasted verbatim
across two sibling functions, and SSE deprecation connected with a
5-line near-identical warning burst.
## Changes
- **Reconnect telemetry helpers** — extracted `logReconnectStart()` and
`logReconnectResult(err error)` methods; both `reconnectPlainJSON()` and
`reconnectSDKTransport()` now delegate to them instead of duplicating
three `logger.Log*` call sites each:
```go
func (c *Connection) logReconnectStart() {
logger.LogWarn("backend", "MCP session expired for %s, attempting to
reconnect...", c.serverID)
}
func (c *Connection) logReconnectResult(err error) {
if err != nil {
logger.LogError("backend", "Session reconnect failed for %s: %v",
c.serverID, err)
} else {
logger.LogInfo("backend", "Session successfully reconnected for %s",
c.serverID)
}
}
```
- **SSE deprecation warning** — collapsed 5 overlapping `LogWarn` calls
(all saying "SSE is deprecated, please migrate") into one `LogWarn` with
the URL + spec version, plus one `LogInfo` for the connection
confirmation. Issue #3633 (redundant `log.Printf` / `logger.LogInfo`
pairs) was already resolved prior to this PR.
> [!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-build3844589215/b514/launcher.test
/tmp/go-build3844589215/b514/launcher.test
-test.testlogfile=/tmp/go-build3844589215/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -W .cfg
elemetry.io/otel-ifaceassert x_amd64/vet
ache/go/1.25.8/x/usr/libexec/docker/cli-plugins/docker-compose --gdwarf2
--64 x_amd64/vet -I .cfg om/yosida95/uritemplate/v3@v3.0.2/equals.go
x_amd64/vet --gdwarf-5 g/protobuf/inter--version -o x_amd64/vet` (dns
block)
> - `https://api.github.com/graphql`
> - Triggering command: `/usr/bin/gh gh issue close 3634 --comment Fixed
in PR #3660: Consolidated the 5-line SSE deprecation warning burst into
2 concise log calls ��� one `LogWarn` containing the URL, spec version,
and migration ask, and one `LogInfo` confirming the connection. This
eliminates the near-duplicate messag ock
- Extract logReconnectStart() and logReconnectResult(err) helpers to
deduplicate the three identical logger.Log* call sites shared by
reconnectPlainJSON() and reconne` (http block)
> - Triggering command: `/usr/bin/gh gh issue close 3632 --comment Fixed
in PR #3660: Extracted `logReconnectStart()` and
`logReconnectResult(err)` helper methods into `connection.go`. Both
`reconnectPlainJSON()` and `reconnectSDKTransport()` now delegate their
three shared `logger.Log*` call sites to these helpers, elim
iVcYPCLQvuKP by/fbd8401427f0fc669ca1ec4ad2768json D8KssBkgN
059210538/b288///opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/go/tools/autobuild.sh`
(http block)
> - Triggering command: `/usr/bin/gh gh issue comment 3634 --body Fixed
in PR #3660: Consolidated the 5-line SSE deprecation warning burst into
2 concise log calls ��� one `LogWarn` containing the URL, spec version,
and migration ask, and one `LogInfo` confirming the connection. --repo
github/gh-aw-mcpg ntime.v2.task/mogit om/tetratelabs/w-c x_amd64/vet
egration/start_glog 4589�� .go y /bin/java ntime.v2.task/mogit
rg/x/net@v0.52.0add x_amd64/vet /bin/java` (http block)
> - `invalid-host-that-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build3844589215/b496/config.test
/tmp/go-build3844589215/b496/config.test
-test.testlogfile=/tmp/go-build3844589215/b496/testlog.txt
-test.paniconexit0 -test.timeout=10m0s
/tmp/go-build3844589215/b396/vet.cfg @v1.1.3/cpu/cpu.-errorsas
om/tetratelabs/w-ifaceassert x_amd64/vet --gdwarf-5
nal/encoding/def-atomic -o x_amd64/vet -I hB8eipdrZ -I x_amd64/vet
--gdwarf-5 9210538/b239/ -o x_amd64/vet` (dns block)
> - `nonexistent.local`
> - Triggering command: `/tmp/go-build3844589215/b514/launcher.test
/tmp/go-build3844589215/b514/launcher.test
-test.testlogfile=/tmp/go-build3844589215/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -W .cfg
elemetry.io/otel-ifaceassert x_amd64/vet
ache/go/1.25.8/x/usr/libexec/docker/cli-plugins/docker-compose --gdwarf2
--64 x_amd64/vet -I .cfg om/yosida95/uritemplate/v3@v3.0.2/equals.go
x_amd64/vet --gdwarf-5 g/protobuf/inter--version -o x_amd64/vet` (dns
block)
> - `slow.example.com`
> - Triggering command: `/tmp/go-build3844589215/b514/launcher.test
/tmp/go-build3844589215/b514/launcher.test
-test.testlogfile=/tmp/go-build3844589215/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -W .cfg
elemetry.io/otel-ifaceassert x_amd64/vet
ache/go/1.25.8/x/usr/libexec/docker/cli-plugins/docker-compose --gdwarf2
--64 x_amd64/vet -I .cfg om/yosida95/uritemplate/v3@v3.0.2/equals.go
x_amd64/vet --gdwarf-5 g/protobuf/inter--version -o x_amd64/vet` (dns
block)
> - `this-host-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build3844589215/b523/mcp.test
/tmp/go-build3844589215/b523/mcp.test
-test.testlogfile=/tmp/go-build3844589215/b523/testlog.txt
-test.paniconexit0 -test.timeout=10m0s
/tmp/go-build3844589215/b517/_pkg_.a 64/src/os/signal/sig.s -I
x_amd64/vet --gdwarf-5 g/grpc/credentiainspect -o x_amd64/vet -W
/auth/apikey.go /auth/header.go x_amd64/vet . --gdwarf2 --64
x_amd64/vet` (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>1 file changed
+21
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
| 246 | + | |
| 247 | + | |
251 | 248 | | |
252 | 249 | | |
253 | 250 | | |
| |||
296 | 293 | | |
297 | 294 | | |
298 | 295 | | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
299 | 311 | | |
300 | 312 | | |
301 | 313 | | |
| |||
304 | 316 | | |
305 | 317 | | |
306 | 318 | | |
307 | | - | |
| 319 | + | |
308 | 320 | | |
309 | 321 | | |
| 322 | + | |
310 | 323 | | |
311 | | - | |
312 | 324 | | |
313 | 325 | | |
314 | 326 | | |
315 | 327 | | |
316 | 328 | | |
317 | | - | |
318 | 329 | | |
319 | 330 | | |
320 | 331 | | |
| |||
325 | 336 | | |
326 | 337 | | |
327 | 338 | | |
328 | | - | |
| 339 | + | |
329 | 340 | | |
330 | 341 | | |
331 | 342 | | |
| |||
359 | 370 | | |
360 | 371 | | |
361 | 372 | | |
| 373 | + | |
362 | 374 | | |
363 | | - | |
364 | 375 | | |
365 | 376 | | |
366 | 377 | | |
367 | 378 | | |
368 | 379 | | |
369 | 380 | | |
370 | 381 | | |
371 | | - | |
372 | 382 | | |
373 | 383 | | |
374 | 384 | | |
| |||
0 commit comments