{"record":{"id":"b435ff76dc0f2abb","repo":"coollabsio/coolify","slug":"new-relic-log-drain-is-not-enabled","errorCode":null,"errorMessage":"New Relic log drain is not enabled.","messagePattern":"New Relic log drain is not enabled\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"warning","filePath":"app/Actions/Server/StartLogDrain.php","lineNumber":36,"sourceCode":"            $type = 'newrelic';\n        } elseif ($server->settings->is_logdrain_highlight_enabled) {\n            $type = 'highlight';\n        } elseif ($server->settings->is_logdrain_axiom_enabled) {\n            $type = 'axiom';\n        } elseif ($server->settings->is_logdrain_custom_enabled) {\n            $type = 'custom';\n        } else {\n            $type = 'none';\n        }\n        if ($type !== 'none') {\n            StopLogDrain::run($server);\n        }\n        try {\n            if ($type === 'none') {\n                return 'No log drain is enabled.';\n            } elseif ($type === 'newrelic') {\n                if (! $server->settings->is_logdrain_newrelic_enabled) {\n                    throw new \\Exception('New Relic log drain is not enabled.');\n                }\n                $config = base64_encode(\"\n[SERVICE]\n    Flush     5\n    Daemon    off\n    Tag container_logs\n    Log_Level debug\n    Parsers_File  parsers.conf\n[INPUT]\n    Name              forward\n    Buffer_Chunk_Size 1M\n    Buffer_Max_Size   6M\n[FILTER]\n    Name grep\n    Match *\n    Exclude log 127.0.0.1\n[FILTER]\n    Name                modify","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/coollabsio/coolify/blob/70b9acc42467278373e00de77abb40684e25b395/app/Actions/Server/StartLogDrain.php#L18-L54","documentation":"Defensive guard in StartLogDrain: $type is derived at the top of handle() (lines 17-27) from the very same settings flag is_logdrain_newrelic_enabled, so by the time $type === 'newrelic' is true the flag re-check should always pass. In practice this branch is unreachable unless the Server's settings relation is mutated or reloaded from the database between type detection and the guard (a concurrent settings save from another request/job). When it fires, Fluent Bit config generation aborts before any container starts.","triggerScenarios":"A concurrent request or queued job toggles the server's New Relic log-drain setting (and the model relation gets refreshed) while a StartLogDrain job is executing on the 'high' queue; or custom code calls handle() with a Server instance whose settings were changed mid-flight.","commonSituations":"Two admins/tabs reconfiguring log drains while a drain restart is queued; Livewire re-render racing a queued job.","solutions":["Simply re-run StartLogDrain after the settings change settles — the flags and type will agree again.","Serialize settings changes: disable/stop the log drain before toggling provider settings.","If it fires repeatedly, look for code that saves ServerSettings without coordinating with running drain jobs."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"$settings = $server->settings()->first(); // fresh read at dispatch time\nif (! $settings->is_logdrain_newrelic_enabled) {\n    return 'Enable the New Relic log drain (and set LICENSE_KEY/BASE_URI) before starting it.';\n}\nStartLogDrain::run($server->refresh());","typeGuard":"function activeLogDrainType(\\App\\Models\\Server $server): string\n{\n    $s = $server->settings;\n    if ($s->is_logdrain_newrelic_enabled) { return 'newrelic'; }\n    if ($s->is_logdrain_highlight_enabled) { return 'highlight'; }\n    if ($s->is_logdrain_axiom_enabled) { return 'axiom'; }\n    if ($s->is_logdrain_custom_enabled) { return 'custom'; }\n    return 'none';\n}","tryCatchPattern":"try {\n    StartLogDrain::run($server);\n} catch (\\Exception $e) {\n    if (str_contains($e->getMessage(), 'log drain is not enabled')) {\n        // settings raced a concurrent save; re-read settings and retry once\n        StartLogDrain::run($server->refresh());\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Treat the drain type flags as one atomic settings save; don't toggle providers while a drain restart is queued.","Call $server->isLogDrainEnabled() (Server model) before dispatching StartLogDrain.","Avoid concurrent UI sessions editing the same server's log-drain settings."],"tags":["log-drain","newrelic","fluent-bit","race-condition","settings"],"backgroundTag":"log-drain-not-configured","analyzedSha":"70b9acc42467278373e00de77abb40684e25b395","analyzedAt":"2026-08-17T01:41:01.313Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}