{"record":{"id":"ac439214b9ca0122","repo":"googleapis/mcp-toolbox","slug":"unable-to-get-logger-from-ctx-s-ac4392","errorCode":null,"errorMessage":"unable to get logger from ctx: %s","messagePattern":"unable to get logger from ctx: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/tools/looker/lookerhealthpulse/lookerhealthpulse.go","lineNumber":210,"sourceCode":"\t\treturn t.checkDashboardPerformance(ctx, source)\n\tcase \"check_dashboard_errors\":\n\t\treturn t.checkDashboardErrors(ctx, source)\n\tcase \"check_explore_performance\":\n\t\treturn t.checkExplorePerformance(ctx, source)\n\tcase \"check_schedule_failures\":\n\t\treturn t.checkScheduleFailures(ctx, source)\n\tcase \"check_legacy_features\":\n\t\treturn t.checkLegacyFeatures(ctx, source)\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unknown action: %s\", params.Action)\n\t}\n}\n\n// Check DB connections and run tests\nfunc (t *pulseTool) checkDBConnections(ctx context.Context, source compatibleSource) (interface{}, error) {\n\tlogger, err := util.LoggerFromContext(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to get logger from ctx: %s\", err)\n\t}\n\tlogger.InfoContext(ctx, \"Test 1/6: Checking connections\")\n\n\treservedNames := map[string]struct{}{\n\t\t\"looker__internal__analytics__replica\": {},\n\t\t\"looker__internal__analytics\":          {},\n\t\t\"looker\":                               {},\n\t\t\"looker__ilooker\":                      {},\n\t}\n\n\tconnections, err := t.SdkClient.AllConnections(\"\", source.LookerApiSettings())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error fetching connections: %w\", err)\n\t}\n\n\tvar filteredConnections []v4.DBConnection\n\tfor _, c := range connections {\n\t\tif _, reserved := reservedNames[*c.Name]; !reserved {","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/looker/lookerhealthpulse/lookerhealthpulse.go#L192-L228","documentation":"checkDBConnections retrieves a structured logger from the request context via util.LoggerFromContext; if the context carries no logger it returns this error. The pulse checks rely on contextual logging, so a bare context.Background() without the server's logger injection will fail. It indicates the tool was invoked outside the server's normal request pipeline.","triggerScenarios":"Calling checkDBConnections (via RunPulse/Invoke) with a context that was not populated by util.AddLoggerToContext / the server's middleware, e.g. in custom harnesses, tests, or scripts.","commonSituations":"Custom test harnesses passing context.Background(), background goroutines that drop the request context, or older server versions that did not inject a logger.","solutions":["Invoke the tool through the server's normal request path, which injects the logger into ctx.","In tests or custom code, add a logger first: ctx = util.AddLoggerToContext(ctx, slog.Default()) (or the equivalent helper).","Pass the request's context, not context.Background(), into Invoke.","Check the util package for the exact logger context helper used by this version."],"exampleFix":"// before\nt.Invoke(ctx, src, params, token) // ctx = context.Background()\n// after\nlogger := slog.Default()\nctx = util.AddLoggerToContext(context.Background(), logger)\nt.Invoke(ctx, src, params, token)","handlingStrategy":"try-catch","validationCode":"if util.LoggerFromContext(ctx) == nil /* or err != nil via helper */ {\n    ctx = util.AddLoggerToContext(ctx, slog.Default())\n}","typeGuard":null,"tryCatchPattern":"result, toolErr := tool.Invoke(ctx, src, params, token)\nif toolErr != nil && strings.Contains(toolErr.Error(), \"unable to get logger\") {\n    ctx = util.AddLoggerToContext(ctx, slog.Default())\n    result, toolErr = tool.Invoke(ctx, src, params, token)\n}","preventionTips":["Always invoke tools through the server request path that injects the logger","In tests, build contexts with the util logger helper instead of context.Background()","Preserve request context values in goroutines (pass ctx down, don't recreate it)","Check util.LoggerFromContext behavior when upgrading server versions"],"tags":["go","looker","logging","context"],"backgroundTag":"missing-logger-in-context","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}