Skip to content

Refactor tracer fallback + logger helper layout to remove duplication and tighten logging semantics#4213

Merged
lpcox merged 2 commits intomainfrom
copilot/refactor-semantic-function-clustering
Apr 20, 2026
Merged

Refactor tracer fallback + logger helper layout to remove duplication and tighten logging semantics#4213
lpcox merged 2 commits intomainfrom
copilot/refactor-semantic-function-clustering

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 20, 2026

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).
// internal/tracing/provider.go
func GetCachedOrGlobal(cached trace.Tracer) trace.Tracer {
	if cached != nil {
		return cached
	}
	return Tracer()
}

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
    • 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:

Copilot AI changed the title [WIP] Refactor duplicate logic and utility in Go codebase Refactor tracer fallback + logger helper layout to remove duplication and tighten logging semantics Apr 20, 2026
Copilot AI requested a review from lpcox April 20, 2026 15:47
@lpcox lpcox marked this pull request as ready for review April 20, 2026 16:13
Copilot AI review requested due to automatic review settings April 20, 2026 16:13
@lpcox lpcox merged commit 971fb5a into main Apr 20, 2026
27 checks passed
@lpcox lpcox deleted the copilot/refactor-semantic-function-clustering branch April 20, 2026 16:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors shared tracer fallback and logger helper plumbing to remove duplication and centralize key behaviors without changing external behavior.

Changes:

  • Added tracing.GetCachedOrGlobal() and replaced duplicated tracer fallback code in proxyHandler and UnifiedServer.
  • Moved the shared LogLevel -> log function dispatch map (logFuncs) to internal/logger/common.go and updated references.
  • Simplified markdown logging flow by removing logWithMarkdownLevel indirection and updating tests accordingly.
  • Clarified marshalAndSanitizeForLog as best-effort logging behavior when JSON marshaling fails.
Show a summary per file
File Description
internal/tracing/provider.go Adds GetCachedOrGlobal helper to centralize tracer fallback behavior.
internal/tracing/provider_test.go Adds coverage for GetCachedOrGlobal with cached and nil tracer inputs.
internal/server/unified.go Switches UnifiedServer.getTracer() to use tracing.GetCachedOrGlobal.
internal/proxy/handler.go Switches proxyHandler.getTracer() to use tracing.GetCachedOrGlobal.
internal/server/tool_registry.go Documents marshalAndSanitizeForLog as intentionally best-effort/silent on marshal failure.
internal/logger/common.go Relocates logFuncs into the shared logger conventions/dispatch section.
internal/logger/file_logger.go Removes the old logFuncs definition now hosted in common.go.
internal/logger/markdown_logger.go Removes logWithMarkdownLevel, simplifies markdown logging helper path.
internal/logger/server_file_logger.go Updates comment to reference logFuncs in common.go.
internal/logger/helper_functions_test.go Renames markdown helper test to reflect new helper layout.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 10/10 changed files
  • Comments generated: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refactor] Semantic Function Clustering Analysis: Refactoring Opportunities

3 participants