{"record":{"id":"d3add9a526053610","repo":"googleapis/mcp-toolbox","slug":"unable-to-get-logger-from-ctx-s-d3add9","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/trino/trino.go","lineNumber":179,"sourceCode":"\t}\n\n\treturn out, nil\n}\n\nfunc initTrinoConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, password, catalog, schema, queryTimeout, accessToken string, kerberosEnabled, sslEnabled bool, sslCertPath, sslCert string, disableSslVerification bool) (*sql.DB, error) {\n\t//nolint:all // Reassigned ctx\n\tctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)\n\tdefer span.End()\n\n\t// Build Trino DSN\n\tdsn, err := buildTrinoDSN(host, port, user, password, catalog, schema, queryTimeout, accessToken, kerberosEnabled, sslEnabled, sslCertPath, sslCert)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to build DSN: %w\", err)\n\t}\n\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\tif disableSslVerification {\n\t\tlogger.WarnContext(ctx, \"SSL verification is disabled for trino source %s. This is an insecure setting and should not be used in production.\\n\", name)\n\t\ttr := &http.Transport{\n\t\t\tTLSClientConfig: &tls.Config{InsecureSkipVerify: true},\n\t\t}\n\t\tclient := &http.Client{Transport: tr}\n\t\tclientName := fmt.Sprintf(\"insecure_trino_client_%s\", name)\n\t\tif err := trinogo.RegisterCustomClient(clientName, client); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to register custom client: %w\", err)\n\t\t}\n\t\tdsn = fmt.Sprintf(\"%s&custom_client=%s\", dsn, clientName)\n\t}\n\n\tdb, err := sql.Open(\"trino\", dsn)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open connection: %w\", err)","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/trino/trino.go#L161-L197","documentation":"initTrinoConnectionPool fetches the structured logger from the context via util.LoggerFromContext and wraps a non-nil error with this message. Unlike the other wraps it uses %s formatting, so the underlying cause is not chainable. It indicates the request context did not carry the logger the toolbox expects.","triggerScenarios":"Initialize -> initTrinoConnectionPool where the passed ctx lacks the logger util.LoggerFromContext expects — i.e. Initialize invoked with a bare/foreign context rather than one prepared by the toolbox server pipeline.","commonSituations":"Custom integrations calling Config.Initialize directly with context.Background(); tests constructing sources outside the toolbox server lifecycle; middleware that stripped or replaced the context values.","solutions":["Pass a context derived through the toolbox server/middleware pipeline that injects the logger","In tests or custom code, add the logger to the context the same way the server does (util.NewContextWithLogger-style helper)","Upgrade the toolbox version if logger injection behavior changed","Note this fires before any DB call — fix the caller, not the Trino config"],"exampleFix":"// before\nsrc, err := cfg.Initialize(context.Background(), tracer)\n// after\nctx := util.NewContextWithLogger(context.Background(), logger)\nsrc, err := cfg.Initialize(ctx, tracer)","handlingStrategy":"validation","validationCode":"// ensure logger is present before calling Initialize\nif logger := ctx.Value(loggerKey{}); logger == nil {\n    ctx = util.NewContextWithLogger(ctx, slog.Default())\n}\nsrc, err := cfg.Initialize(ctx, tracer)","typeGuard":"func ctxHasLogger(ctx context.Context) bool {\n    l, err := util.LoggerFromContext(ctx)\n    return err == nil && l != nil\n}","tryCatchPattern":"src, err := cfg.Initialize(ctx, tracer)\nif err != nil && strings.Contains(err.Error(), \"unable to get logger from ctx\") {\n    // inject logger and retry once\n    ctx = util.NewContextWithLogger(ctx, slog.Default())\n    src, err = cfg.Initialize(ctx, tracer)\n}","preventionTips":["Always call Initialize with the context from the toolbox server pipeline, not bare context.Background()","In tests, install a logger in the context via the util helper first","Don't strip context values with custom middleware between server setup and source init","Pin toolbox versions to keep logger-injection helpers consistent"],"tags":["context","logging","trino","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"}