Skip to content

Commit d412a6b

Browse files
authored
[log] middleware: add debug logging calls to jqschema (#4912)
## Summary Adds `logMiddleware.Printf` debug logging calls to `internal/middleware/jqschema.go`. The `logMiddleware` logger was declared (`var logMiddleware = logger.New("middleware:jqschema")`) but never used. This PR activates it with 4 meaningful logging calls: ### Changes - **`WrapToolHandler`** – logs when a tool handler is wrapped with the middleware, including `toolName`, `sizeThreshold`, `baseDir`, and whether a `pathPrefix` is set - **`applyJqSchema`** (entry) – logs the start of schema inference with the Go type of the input data - **`applyJqSchema`** (exit) – logs successful schema inference with the result type - **`ShouldApplyMiddleware`** – logs the apply/skip decision for each tool ### Why this matters The existing operational logging uses `logger.LogInfo/LogDebug` (written to files). The `logMiddleware` calls provide developer-facing trace output enabled only when `DEBUG=middleware:*` is set, following the pattern used throughout the codebase. ### Testing - All unit tests pass: `go test ./internal/middleware/...` - No new imports required (logger package already imported) - No side effects in log arguments > [!WARNING] > **⚠️ Firewall blocked 1 domain** > > The following domain was blocked by the firewall during workflow execution: > > - `invalidhostthatdoesnotexist12345.com` > > To allow these domains, add them to the `network.allowed` list in your workflow frontmatter: > > ```yaml > network: > allowed: > - defaults > - "invalidhostthatdoesnotexist12345.com" > ``` > > See [Network Configuration](https://github.github.com/gh-aw/reference/network/) for more information. > Generated by [Go Logger Enhancement](https://github.com/github/gh-aw-mcpg/actions/runs/25203584486/agentic_workflow) · ● 5.3M · [◷](https://github.com/search?q=repo%3Agithub%2Fgh-aw-mcpg+%22gh-aw-workflow-id%3A+go-logger%22&type=pullrequests) <!-- gh-aw-agentic-workflow: Go Logger Enhancement, engine: copilot, version: 1.0.21, model: auto, id: 25203584486, workflow_id: go-logger, run: https://github.com/github/gh-aw-mcpg/actions/runs/25203584486 --> <!-- gh-aw-workflow-id: go-logger -->
2 parents 2612cc6 + f6b1da5 commit d412a6b

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

internal/middleware/jqschema.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ func applyJqSchema(ctx context.Context, jsonData interface{}) (interface{}, erro
172172
return nil, fmt.Errorf("jq schema filter not compiled (check startup logs): %w", jqSchemaCompileErr)
173173
}
174174

175+
logMiddleware.Printf("applyJqSchema: starting schema inference, dataType=%T", jsonData)
176+
175177
// Ensure context has a timeout - add default if none exists
176178
if _, hasDeadline := ctx.Deadline(); !hasDeadline {
177179
var cancel context.CancelFunc
@@ -212,6 +214,7 @@ func applyJqSchema(ctx context.Context, jsonData interface{}) (interface{}, erro
212214
}
213215

214216
// Return the schema object directly (no JSON marshaling needed here)
217+
logMiddleware.Printf("applyJqSchema: schema inference completed, resultType=%T", v)
215218
return v, nil
216219
}
217220

@@ -288,6 +291,8 @@ func WrapToolHandler(
288291
sizeThreshold int,
289292
getSessionID func(context.Context) string,
290293
) func(context.Context, *sdk.CallToolRequest, interface{}) (*sdk.CallToolResult, interface{}, error) {
294+
logMiddleware.Printf("WrapToolHandler: wrapping tool=%s, sizeThreshold=%d bytes, baseDir=%s, pathPrefixSet=%v",
295+
toolName, sizeThreshold, baseDir, pathPrefix != "")
291296
return func(ctx context.Context, req *sdk.CallToolRequest, args interface{}) (*sdk.CallToolResult, interface{}, error) {
292297
// Generate random query ID
293298
queryID := generateRandomID()
@@ -475,5 +480,7 @@ func WrapToolHandler(
475480
// Currently applies to all tools, but can be configured to filter specific tools
476481
func ShouldApplyMiddleware(toolName string) bool {
477482
// Apply to all tools except sys tools
478-
return !strings.HasPrefix(toolName, "sys___")
483+
applies := !strings.HasPrefix(toolName, "sys___")
484+
logMiddleware.Printf("ShouldApplyMiddleware: tool=%s, applies=%v", toolName, applies)
485+
return applies
479486
}

0 commit comments

Comments
 (0)