{"record":{"id":"4a5c5630d943b2c9","repo":"googleapis/mcp-toolbox","slug":"unable-to-get-logger-from-ctx-s-4a5c56","errorCode":null,"errorMessage":"unable to get logger from ctx: %s","messagePattern":"unable to get logger from ctx: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/looker/looker.go","lineNumber":94,"sourceCode":"\tTimeout            string `yaml:\"timeout\"`\n\tShowHiddenModels   bool   `yaml:\"show_hidden_models\"`\n\tShowHiddenExplores bool   `yaml:\"show_hidden_explores\"`\n\tShowHiddenFields   bool   `yaml:\"show_hidden_fields\"`\n\tProject            string `yaml:\"project\"`\n\tLocation           string `yaml:\"location\"`\n\tQuotaProject       string `yaml:\"quotaProject\"`\n\tSessionLength      int64  `yaml:\"sessionLength\"`\n}\n\nfunc (r Config) SourceConfigType() string {\n\treturn SourceType\n}\n\n// Initialize initializes a Looker Source instance.\nfunc (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, 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\n\tuserAgent, err := util.UserAgentFromContext(ctx)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tduration, err := time.ParseDuration(r.Timeout)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to parse Timeout string as time.Duration: %s\", err)\n\t}\n\n\tif !r.SslVerification {\n\t\tlogger.WarnContext(ctx, \"Insecure HTTP is enabled for Looker source %s. TLS certificate verification is skipped.\\n\", r.Name)\n\t}\n\tcfg := rtl.ApiSettings{\n\t\tAgentTag:     userAgent,\n\t\tBaseUrl:      r.BaseURL,","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/looker/looker.go#L76-L112","documentation":"Looker's Config.Initialize pulls a slog logger out of the context via util.LoggerFromContext; the toolbox always injects one at startup. If it is absent, Initialize cannot log and aborts with this error. This almost always means the source is being initialized outside the normal server bootstrap path (e.g. tests or custom embedding) without the logger context value.","triggerScenarios":"Calling Config.Initialize(ctx, tracer) with a bare context.Context that was not decorated by the toolbox's server setup (which normally adds the logger via context utilities).","commonSituations":"Unit/integration tests constructing sources manually with context.Background(); embedding the toolbox as a library without running its server initialization; a modified bootstrap path dropping the logger.","solutions":["Add the toolbox logger to the context before calling Initialize, e.g. util.AddLoggerToContext / the same helper the server uses.","If in tests, use the context fixture the other source tests use (it already carries a logger).","Ensure you initialize sources through the toolbox server bootstrap rather than calling Initialize directly with a raw context."],"exampleFix":"// before\nsrc, err := cfg.Initialize(context.Background(), tracer)\n// after\nlogger := slog.Default()\nctx := util.AddLoggerToContext(context.Background(), logger)\nsrc, err := cfg.Initialize(ctx, tracer)","handlingStrategy":"validation","validationCode":"// Go: before calling Initialize directly, ensure the ctx carries the toolbox logger\nif util.LoggerFromContext(ctx) != nil == false {\n    ctx = util.AddLoggerToContext(ctx, slog.Default()) // or your configured logger\n}","typeGuard":null,"tryCatchPattern":"src, err := cfg.Initialize(ctx, tracer)\nif err != nil {\n    if strings.Contains(err.Error(), \"unable to get logger from ctx\") {\n        // context wasn't prepared by the toolbox bootstrap; add logger and retry once\n        ctx = util.AddLoggerToContext(ctx, slog.Default())\n        src, err = cfg.Initialize(ctx, tracer)\n    }\n    if err != nil { return err }\n}","preventionTips":["Always initialize sources through the toolbox server bootstrap path.","In tests, reuse the shared context fixture that already contains the logger.","Never pass bare context.Background() to Config.Initialize in library embedding."],"tags":["looker","context","logging","initialization"],"backgroundTag":"missing-context-value","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"}