<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ojedokun Mololuwa Victor  on Medium]]></title>
        <description><![CDATA[Stories by Ojedokun Mololuwa Victor  on Medium]]></description>
        <link>https://medium.com/@viktohsmith2002?source=rss-14f831c88183------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CRBUbci3AhFCCNW2BIsvKQ.jpeg</url>
            <title>Stories by Ojedokun Mololuwa Victor  on Medium</title>
            <link>https://medium.com/@viktohsmith2002?source=rss-14f831c88183------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 17:35:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@viktohsmith2002/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[One Grafana Cloud Stack, Two Environments: Logs and Metrics From Dev and Production Without…]]></title>
            <link>https://medium.com/@viktohsmith2002/one-grafana-cloud-stack-two-environments-logs-and-metrics-from-dev-and-production-without-b3d96af7fc90?source=rss-14f831c88183------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3d96af7fc90</guid>
            <dc:creator><![CDATA[Ojedokun Mololuwa Victor ]]></dc:creator>
            <pubDate>Sat, 05 Sep 2026 12:12:57 GMT</pubDate>
            <atom:updated>2026-09-05T12:12:57.327Z</atom:updated>
            <content:encoded><![CDATA[<h3>One Grafana Cloud Stack, Two Environments: Logs and Metrics From Dev and Production Without Duplicating Anything</h3><p>How I wired Docker Loki logging and Grafana Alloy metrics from two separate DigitalOcean droplets into a single Grafana Cloud account, with a dashboard dropdown to switch between environments.</p><h3>The setup</h3><p>A Node.js/Express backend I run in Docker on two separate DigitalOcean droplets:</p><ul><li>A dev droplet</li><li>A production droplet</li></ul><p>I wanted both shipping logs and metrics to the same Grafana Cloud stack, viewable in the same dashboards, filterable by environment with one dropdown. Not two Grafana accounts. Not two sets of dashboards to keep in sync.</p><p>The architecture:</p><pre>Droplet (dev)                    Droplet (production)<br>   |  Docker Loki driver             |  Docker Loki driver<br>   |  Grafana Alloy                  |  Grafana Alloy<br>   v                                 v<br>        Grafana Cloud (Loki + Prometheus)<br>                     |<br>                     v<br>        Grafana Dashboard (env dropdown: dev / production)</pre><p>The mechanism that makes this work is external labels. Every log line and every metric point carries app=my-backend and env=dev or env=production. That label pair is the entire multi-environment strategy — no separate infra, just consistent tagging at the source.</p><h3>Part 1 — Logs (Docker Loki driver)</h3><h3>Step 1: Get Loki credentials</h3><p>In the Grafana Cloud portal, under your stack, open <strong>Loki → Details</strong>. You’ll see:</p><pre>URL:  https://logs-prod-████.grafana.net<br>User: ██████████</pre><p>Do not use the password shown on this page. It’s a read-only token and will connect without error, then silently drop everything you send it.</p><h3>Step 2: Generate a write-scoped token</h3><p>Go to <strong>Access Policies → Create access policy</strong>.</p><pre>Name:   docker-logs-write<br>Realm:  &lt;your stack&gt;<br>Scope:  logs:write ✅ (write only)</pre><p>Create the policy, then <strong>Add token</strong>, and copy it immediately. It won’t be shown again.</p><h3>Step 3: Test the token before touching daemon.json</h3><pre>curl -s -u &quot;██████████:glc_eyJ█████████████████████&quot; \<br>  -H &quot;Content-Type: application/json&quot; \<br>  -d &#39;{&quot;streams&quot;:[{&quot;stream&quot;:{&quot;app&quot;:&quot;test&quot;},&quot;values&quot;:[[&quot;&#39;&quot;$(date +%s%N)&quot;&#39;&quot;,&quot;test log entry&quot;]]}]}&#39; \<br>  &quot;https://logs-prod-████.grafana.net/loki/api/v1/push&quot;</pre><p>An empty response means it worked. Any 401 means wrong token or wrong scope — regenerate before continuing.</p><h3>Step 4: Install the Loki Docker plugin (once per droplet)</h3><pre>docker plugin install grafana/loki-docker-driver:latest \<br>  --alias loki \<br>  --grant-all-permissions</pre><pre>$ docker plugin ls<br>ID             NAME          DESCRIPTION           ENABLED<br>a1b2c3d4e5f6   loki:latest   Loki Logging Driver   true</pre><h3>Step 5: Configure Docker globally, per droplet</h3><p>This is the step that actually differentiates dev from production — the env value in the external labels.</p><p>On the <strong>production</strong> droplet:</p><pre>sudo tee /etc/docker/daemon.json &lt;&lt; &#39;DAEMON&#39;<br>{<br>  &quot;log-driver&quot;: &quot;loki&quot;,<br>  &quot;log-opts&quot;: {<br>    &quot;loki-url&quot;: &quot;https://██████████:glc_eyJ████████████████████████@logs-prod-████.grafana.net/loki/api/v1/push&quot;,<br>    &quot;loki-retries&quot;: &quot;3&quot;,<br>    &quot;loki-max-backoff&quot;: &quot;800ms&quot;,<br>    &quot;loki-timeout&quot;: &quot;1s&quot;,<br>    &quot;loki-batch-size&quot;: &quot;102400&quot;,<br>    &quot;labels&quot;: &quot;container_name&quot;,<br>    &quot;loki-external-labels&quot;: &quot;app=my-backend,env=production&quot;<br>  }<br>}<br>DAEMON</pre><p>On the <strong>dev</strong> droplet — identical file, one field different:</p><pre>sudo tee /etc/docker/daemon.json &lt;&lt; &#39;DAEMON&#39;<br>{<br>  &quot;log-driver&quot;: &quot;loki&quot;,<br>  &quot;log-opts&quot;: {<br>    &quot;loki-url&quot;: &quot;https://██████████:glc_eyJ████████████████████████@logs-prod-████.grafana.net/loki/api/v1/push&quot;,<br>    &quot;loki-retries&quot;: &quot;3&quot;,<br>    &quot;loki-max-backoff&quot;: &quot;800ms&quot;,<br>    &quot;loki-timeout&quot;: &quot;1s&quot;,<br>    &quot;loki-batch-size&quot;: &quot;102400&quot;,<br>    &quot;labels&quot;: &quot;container_name&quot;,<br>    &quot;loki-external-labels&quot;: &quot;app=my-backend,env=dev&quot;<br>  }<br>}<br>DAEMON</pre><p>Use tee, not nano, to avoid duplicating or malforming the credential URL. Lock the file down afterward:</p><pre>sudo chmod 600 /etc/docker/daemon.json</pre><p>Restart Docker on each droplet:</p><pre>sudo systemctl restart docker</pre><h3>Step 6: Redeploy — log drivers only apply at container start</h3><p>Existing containers keep using the old (or no) driver until they’re recreated. Either trigger your CI/CD pipeline, or manually:</p><pre>docker stop my-backend<br>docker rm my-backend<br>docker run -d \<br>  --name my-backend \<br>  --restart unless-stopped \<br>  --env-file /etc/myapp/.env \<br>  -p 3003:3003 \<br>  ghcr.io/████████/my-backend:latest</pre><h3>Step 7: Verify</h3><pre>$ sudo journalctl -u docker --no-pager | grep -i &quot;erro&quot; | tail -5</pre><p>No output means logs are shipping. Confirm in Grafana:</p><ol><li><strong>Explore</strong> → select grafanacloud-&lt;stack&gt;-logs (not plain loki)</li><li>Run: {app=&quot;my-backend&quot;}</li><li>Set time range to <strong>Last 15 minutes</strong></li></ol><p>Scope to one environment:</p><pre>{app=&quot;my-backend&quot;, env=&quot;production&quot;}<br>{app=&quot;my-backend&quot;, env=&quot;dev&quot;}</pre><h3>Part 2 — Metrics (Grafana Alloy)</h3><p>Same environment-switching approach, this time for CPU, memory, disk, and network metrics via Prometheus remote write.</p><h3>Step 1: Get Prometheus credentials</h3><p><strong>Grafana Cloud → My Account → Prometheus → Details</strong>:</p><pre>URL:  https://prometheus-prod-██-prod-██-████-█.grafana.net/api/prom/push<br>User: ███████</pre><p>Create an access policy scoped to metrics:write, same pattern as the Loki token.</p><h3>Step 2: Run the Alloy setup on each droplet</h3><p>The install script prompts for the remote write URL, username, token, and environment name. On the production droplet, answer production. On the dev droplet, answer dev. That&#39;s the only difference between the two runs.</p><p>Resulting config on the production droplet, /etc/alloy/config.alloy:</p><pre>prometheus.exporter.unix &quot;node&quot; {<br>  set_collectors = [&quot;cpu&quot;, &quot;meminfo&quot;, &quot;diskstats&quot;, &quot;filesystem&quot;, &quot;netdev&quot;, &quot;loadavg&quot;]<br>}</pre><pre>prometheus.scrape &quot;node&quot; {<br>  targets    = prometheus.exporter.unix.node.targets<br>  forward_to = [prometheus.remote_write.grafana_cloud.receiver]<br>  job_name   = &quot;node_exporter&quot;<br>}</pre><pre>prometheus.remote_write &quot;grafana_cloud&quot; {<br>  endpoint {<br>    url = &quot;https://prometheus-prod-██-prod-██-████-█.grafana.net/api/prom/push&quot;</pre><pre>    basic_auth {<br>      username = &quot;███████&quot;<br>      password = &quot;glc_eyJ████████████████████████&quot;<br>    }<br>  }</pre><pre>  external_labels = {<br>    app = &quot;my-backend&quot;,<br>    env = &quot;production&quot;,<br>  }<br>}</pre><p>Lock it down and start the service:</p><pre>sudo chmod 600 /etc/alloy/config.alloy<br>sudo systemctl enable alloy<br>sudo systemctl start alloy</pre><pre>$ sudo systemctl is-active alloy<br>active</pre><h3>Step 3: Verify metrics are landing</h3><pre>$ sudo journalctl -u alloy --no-pager | tail -20</pre><p>No errors, then in Grafana → <strong>Explore</strong> → select the Prometheus data source:</p><pre>node_cpu_seconds_total{app=&quot;my-backend&quot;, env=&quot;production&quot;}</pre><h3>Part 3 — One dashboard, one dropdown</h3><p>This is the payoff for tagging everything consistently at the source.</p><ol><li>Grafana → <strong>Dashboards</strong> → <strong>New dashboard</strong></li><li><strong>Dashboard settings</strong> → <strong>Variables</strong> → <strong>Add variable</strong></li></ol><pre>Name:            env<br>Type:            Custom<br>Label:           Environment<br>Custom options:  dev,production<br>Default value:   dev</pre><ol><li>Every panel query references $env instead of a hardcoded value:</li></ol><pre>100 - (avg by(env) (rate(node_cpu_seconds_total{mode=&quot;idle&quot;, app=&quot;my-backend&quot;, env=&quot;$env&quot;}[5m])) * 100)</pre><pre>100 * (1 - ((node_memory_MemAvailable_bytes{app=&quot;my-backend&quot;, env=&quot;$env&quot;}) / (node_memory_MemTotal_bytes{app=&quot;my-backend&quot;, env=&quot;$env&quot;})))</pre><p>Flip the dropdown, every panel — CPU, memory, disk, network, load — repoints to the other droplet’s data. No duplicate dashboards, no duplicate Grafana stacks.</p><h3>Troubleshooting reference</h3><p>Symptom Cause Fix 401 Unauthorized: invalid token Read-only token used Regenerate with logs:write / metrics:write scope lookup ██████:https: no such host Duplicate https:// in daemon.json Rewrite the file with tee, not nano No data after restart Container not recreated Redeploy — log drivers bind at container start Dashboard shows both envs mixed A panel query missing env=&quot;$env&quot; Audit every panel query for the label 530 on Loki push Wrong Loki host for your region Re-check the exact URL from the Details page</p><h3>What actually made this work</h3><p>Two labels, applied consistently, at the infrastructure layer rather than the application layer:</p><pre>app = my-backend<br>env = dev | production</pre><p>Everything else — the plugin install, the Alloy binary, the dashboard variable — is scaffolding around that one decision. Get the labels right at the source and the rest of the observability stack falls into place on its own.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3d96af7fc90" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Full Observability Stack on Plain Droplets: Metrics, Logs, and Errors Without an APM…]]></title>
            <link>https://medium.com/@viktohsmith2002/building-a-full-observability-stack-on-plain-droplets-metrics-logs-and-errors-without-an-apm-8ebb7fceaf1b?source=rss-14f831c88183------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ebb7fceaf1b</guid>
            <dc:creator><![CDATA[Ojedokun Mololuwa Victor ]]></dc:creator>
            <pubDate>Fri, 07 Aug 2026 09:29:30 GMT</pubDate>
            <atom:updated>2026-08-07T09:29:30.987Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a Full Observability Stack on Plain Droplets: Metrics, Logs, and Errors Without an APM Vendor</h3><p>When we moved our backend off a serverless platform onto a DigitalOcean droplet, we lost something we hadn’t thought much about: visibility. No built-in metrics dashboard, no automatic log aggregation, no error alerting. Just docker logs and a lot of hoping nothing broke while we weren&#39;t looking.</p><p>This is a walkthrough of the three-part observability stack I built to fix that: server metrics with Grafana Alloy, centralized logging with Docker’s Loki driver, and application error tracking with Sentry. All shipping to a single Grafana Cloud account.</p><p>Company and infrastructure identifiers below are redacted with block characters. Tool output is real but sanitized.</p><h3>Architecture</h3><pre>Droplet (Grafana Alloy) ──────┐<br>Docker containers (Loki driver) ─┼──&gt; Grafana Cloud ──&gt; Dashboards<br>Express app (Sentry SDK) ─────┘         └──&gt; Sentry ──&gt; Error alerts</pre><p>Metrics and logs are captured at the infrastructure layer. Errors are captured at the application layer. This split matters: infra-layer tooling gets configured once on the droplet and never needs to touch the deploy pipeline again. Application-layer tooling ships with the code.</p><h3>Part 1: Server Metrics with Grafana Alloy</h3><h3>Step 1: Get Grafana Cloud Prometheus credentials</h3><p>From the Grafana Cloud portal, under your stack’s Prometheus details, you’ll find a push URL and a numeric username:</p><pre>URL: https://prometheus-prod-██-prod-██-████-█.grafana.net/api/prom/push<br>Username: ███████</pre><p>Then, under Access Policies, create a policy scoped to metrics:write only, and generate a token from it. Keep the token region matched to your Prometheus region, a mismatch here causes silent auth failures.</p><h3>Step 2: Install and configure Alloy</h3><p>On the droplet:</p><pre>sudo mkdir -p /etc/apt/keyrings/<br>wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg &gt; /dev/null<br>echo &quot;deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main&quot; | sudo tee /etc/apt/sources.list.d/grafana.list<br>sudo apt-get update -q<br>sudo apt-get install alloy -y</pre><p>The config file at /etc/alloy/config.alloy defines what gets scraped and where it&#39;s shipped:</p><pre>prometheus.exporter.unix &quot;node&quot; {<br>  set_collectors = [&quot;cpu&quot;, &quot;meminfo&quot;, &quot;diskstats&quot;, &quot;filesystem&quot;, &quot;netdev&quot;, &quot;loadavg&quot;]<br>}</pre><pre>prometheus.scrape &quot;node&quot; {<br>  targets    = prometheus.exporter.unix.node.targets<br>  forward_to = [prometheus.remote_write.grafana_cloud.receiver]<br>  job_name   = &quot;node_exporter&quot;<br>}</pre><pre>prometheus.remote_write &quot;grafana_cloud&quot; {<br>  endpoint {<br>    url = &quot;https://prometheus-prod-██-████.grafana.net/api/prom/push&quot;<br>    basic_auth {<br>      username = &quot;███████&quot;<br>      password = &quot;glc_████████████████&quot;<br>    }<br>  }<br>  external_labels = {<br>    app = &quot;████████&quot;,<br>    env = &quot;production&quot;,<br>  }<br>}</pre><p>The env label is the key design decision here. It&#39;s what lets one dashboard serve both environments later.</p><pre>sudo chmod 600 /etc/alloy/config.alloy<br>sudo systemctl enable alloy<br>sudo systemctl start alloy<br>sudo systemctl is-active alloy</pre><p>Output:</p><pre>active</pre><h3>Step 3: Verify metrics are shipping</h3><pre>sudo journalctl -u alloy --no-pager | tail -20</pre><p>No errors here means data is flowing. Confirm in Grafana under Explore, selecting the Prometheus data source, and running:</p><pre>node_cpu_seconds_total{app=&quot;████████&quot;}</pre><h3>Step 4: Build the dashboard with an environment switch</h3><p>Instead of duplicating dashboards per environment, add one dashboard variable:</p><ul><li>Name: env</li><li>Type: Custom</li><li>Options: dev,production</li></ul><p>Every panel query then filters on env=&quot;$env&quot;. CPU usage panel, for example:</p><pre>100 - (avg by(env) (rate(node_cpu_seconds_total{mode=&quot;idle&quot;, app=&quot;████████&quot;, env=&quot;$env&quot;}[5m])) * 100)</pre><p>Repeat the same pattern for memory, disk, network throughput, and load average. Run the same setup script on each droplet, changing only the environment name at the prompt.</p><h3>Part 2: Centralized Logging with Loki</h3><h3>Step 1: Get Loki credentials, and avoid the read-only token trap</h3><p>This is the part that cost me the most debugging time. On the Loki details page in Grafana Cloud, there’s a pre-generated token sitting right next to the URL and username. It looks ready to use.</p><p>It isn’t. That token is read-only. Shipping logs with it produces no error in your terminal, no error in Docker’s startup, nothing, until you check the journal and find repeated 401s.</p><p>The fix: go to Access Policies, create a new policy scoped to logs:write only, and generate a token from that instead.</p><pre>curl -s -u &quot;███████:glc_████████████████&quot; \<br>  -H &quot;Content-Type: application/json&quot; \<br>  -d &#39;{&quot;streams&quot;:[{&quot;stream&quot;:{&quot;app&quot;:&quot;test&quot;},&quot;values&quot;:[[&quot;&#39;&quot;$(date +%s%N)&quot;&#39;&quot;,&quot;test log entry&quot;]]}]}&#39; \<br>  &quot;https://logs-prod-███.grafana.net/loki/api/v1/push&quot;</pre><p>An empty response confirms the token works.</p><h3>Step 2: Install the Loki Docker plugin</h3><pre>docker plugin install grafana/loki-docker-driver:latest \<br>  --alias loki \<br>  --grant-all-permissions<br>docker plugin ls</pre><p>Output:</p><pre>ID          NAME     DESCRIPTION           ENABLED<br>████████    loki      Loki Logging Driver   true</pre><h3>Step 3: Configure Docker globally</h3><p>This is the part that matters for CI/CD: configuring the log driver in Docker’s daemon config means every container on the droplet ships logs to Loki automatically, no per-container flags, no pipeline changes.</p><pre>sudo tee /etc/docker/daemon.json &lt;&lt; &#39;DAEMON&#39;<br>{<br>  &quot;log-driver&quot;: &quot;loki&quot;,<br>  &quot;log-opts&quot;: {<br>    &quot;loki-url&quot;: &quot;https://███████:glc_████████████████@logs-prod-███.grafana.net/loki/api/v1/push&quot;,<br>    &quot;loki-retries&quot;: &quot;3&quot;,<br>    &quot;loki-max-backoff&quot;: &quot;800ms&quot;,<br>    &quot;loki-timeout&quot;: &quot;1s&quot;,<br>    &quot;loki-batch-size&quot;: &quot;102400&quot;,<br>    &quot;labels&quot;: &quot;container_name&quot;,<br>    &quot;loki-external-labels&quot;: &quot;app=████████,env=production&quot;<br>  }<br>}<br>DAEMON</pre><pre>sudo chmod 600 /etc/docker/daemon.json<br>sudo systemctl restart docker</pre><p>Use tee here, not a text editor. A manually edited file is an easy way to end up with a duplicated https:// in the URL, which produces a confusing lookup ...: no such host error on restart.</p><h3>Step 4: Redeploy to pick up the new driver</h3><p>Log drivers are assigned at container start time, so the running container won’t pick up the change until it’s recreated. Triggering the existing CI/CD pipeline handles this automatically. Manually:</p><pre>docker stop ████████<br>docker rm ████████<br>docker run -d \<br>  --name ████████ \<br>  --restart unless-stopped \<br>  --env-file /etc/████████/.env \<br>  -p ████:████ \<br>  ████████:latest</pre><h3>Step 5: Query logs in Grafana</h3><p>Under Explore, select the grafanacloud-&lt;stack&gt;-logs data source (not the plain loki option), and run:</p><pre>{app=&quot;████████&quot;}</pre><p>Useful filters:</p><pre>{app=&quot;████████&quot;} |= &quot;error&quot;<br>{app=&quot;████████&quot;, env=&quot;production&quot;}<br>{app=&quot;████████&quot;} |= &quot;database&quot;</pre><h3>Part 3: Application Errors with Sentry</h3><p>Metrics and logs tell you something is wrong. Sentry tells you exactly where, with a stack trace and the request that triggered it.</p><h3>Step 1: Install and initialize before anything else loads</h3><pre>npm install @sentry/node @sentry/profiling-node --save</pre><p>Create src/instrument.ts:</p><pre>import dotenv from &#39;dotenv&#39;;<br>dotenv.config();</pre><pre>import * as Sentry from &quot;@sentry/node&quot;;<br>import { nodeProfilingIntegration } from &quot;@sentry/profiling-node&quot;;</pre><pre>Sentry.init({<br>  dsn: process.env.SENTRY_DSN,<br>  integrations: [nodeProfilingIntegration()],<br>  enableLogs: true,<br>  tracesSampleRate: 1.0,<br>  profileSessionSampleRate: 1.0,<br>  profileLifecycle: &#39;trace&#39;,<br>  environment: process.env.NODE_ENV,<br>});</pre><p>dotenv.config() has to run inside this file, before Sentry.init(), or SENTRY_DSN won&#39;t be defined yet.</p><h3>Step 2: Import order in app.ts</h3><pre>import &quot;./instrument&quot;; // must be the first line, before every other import</pre><pre>import express from &#39;express&#39;;<br>import * as Sentry from &#39;@sentry/node&#39;;</pre><pre>const app = express();</pre><pre>// ... routes ...</pre><pre>Sentry.setupExpressErrorHandler(app); // after all routes</pre><pre>app.use((err, _req, res, _next) =&gt; {<br>  console.error(err.stack);<br>  res.status(500).json({ success: false, message: &#39;Something went wrong!&#39; });<br>});</pre><pre>app.use((_req, res) =&gt; {<br>  res.status(404).json({ success: false, message: &#39;Route not found&#39; });<br>});</pre><p>Order matters in three places: instrument.ts loads first so Sentry can instrument everything else, setupExpressErrorHandler runs after all routes so it can catch errors from any of them, and your own error handler runs after Sentry&#39;s so it doesn&#39;t swallow the error before Sentry sees it.</p><h3>Step 3: Verify</h3><p>Hit a route that throws, then check the Sentry dashboard. The error should appear within seconds, complete with stack trace and environment tag.</p><h3>What this setup gets you</h3><p>For the cost of a Grafana Cloud free tier and a Sentry free tier, this stack gives you:</p><ul><li>Real-time CPU, memory, disk, and network visibility per environment</li><li>Centralized, searchable logs across every container on the droplet, with zero pipeline overhead</li><li>Application error tracking with full stack traces, not just “the container restarted”</li></ul><p>The two lessons that generalize beyond this specific stack: infrastructure-layer observability (metrics, logs) should be configured once at the OS or Docker level so it survives redeploys without touching CI/CD, and any managed platform’s pre-generated credentials should be treated as untrusted until you’ve confirmed their actual scope, not just their apparent readiness.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ebb7fceaf1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When the Pipeline Catches What Code Review Misses: A Credential Leak Case Study]]></title>
            <link>https://medium.com/@viktohsmith2002/when-the-pipeline-catches-what-code-review-misses-a-credential-leak-case-study-128113d275b0?source=rss-14f831c88183------2</link>
            <guid isPermaLink="false">https://medium.com/p/128113d275b0</guid>
            <dc:creator><![CDATA[Ojedokun Mololuwa Victor ]]></dc:creator>
            <pubDate>Sat, 25 Jul 2026 17:10:46 GMT</pubDate>
            <atom:updated>2026-07-25T17:10:46.023Z</atom:updated>
            <content:encoded><![CDATA[<p>Code review is good at catching logic errors, style issues, and missing edge cases. It is not reliable at catching a stray JSON key file sitting three folders deep in a diff with 40 changed files. That’s exactly the gap that automated secret scanning in CI/CD is built to close, and this is a walkthrough of it doing its job.</p><h3>The Setup: Secret Scanning as a Required Check</h3><p>Before this incident, the pipeline already had a secret scanning step wired into the pull request workflow. It runs on every PR targeting main, scans the branch’s commit history (not just the latest diff), and fails the build if it finds anything matching a live credential pattern.</p><p>A simplified version of that step looks like this:</p><pre>name: Security Scan</pre><pre>on:<br>  pull_request:<br>    branches: [main]</pre><pre>jobs:<br>  secret-scan:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v4<br>        with:<br>          fetch-depth: 0</pre><pre>      - name: Run secret scanner<br>        run: |<br>          docker run -v $(pwd):/repo zricethezav/gitleaks:latest \<br>            detect --source /repo --verbose --redact</pre><pre>      - name: Run TruffleHog verification<br>        run: |<br>          trufflehog filesystem /repo --only-verified --json</pre><p>Two tools, two different strengths. One scans for known credential patterns across the full commit history. The other actually attempts to verify a match against the provider’s API, so a “verified” hit means the secret is confirmed live, not just pattern-matched.</p><p>Both are configured as required status checks. A pull request cannot merge into main until both pass.</p><h3>The Incident: A Credential Slips Into a Commit</h3><p>A teammate was wiring up a Google Cloud Vision integration and needed a service account key to authenticate locally. The key file was supposed to stay outside version control. Instead, it got added, committed, and pushed as part of a feature branch, then included in a pull request targeting main.</p><p>Nobody caught it in review. That’s not a criticism of the reviewer, it’s the nature of the problem: a JSON credentials file doesn’t look meaningfully different from any other config file at a glance, and it was buried in a larger changeset.</p><h3>Detection: The Pipeline Catches It</h3><p>The moment the pull request was opened, the security scan job ran automatically. Both tools flagged it.</p><p>Gitleaks output (redacted):</p><pre>Finding:     &quot;private_key&quot;: &quot;[REDACTED]&quot;,<br>Secret:      [REDACTED]<br>RuleID:      private-key<br>Entropy:     6.01<br>File:        [REDACTED_FILENAME].json<br>Line:        5<br>Commit:      [REDACTED_COMMIT_HASH]</pre><pre>Finding:     &quot;private_key_id&quot;: &quot;[REDACTED]&quot;<br>Secret:      [REDACTED]<br>RuleID:      generic-api-key<br>Entropy:     3.77<br>File:        [REDACTED_FILENAME].json<br>Line:        4<br>Commit:      [REDACTED_COMMIT_HASH]</pre><pre>INF 163 commits scanned.<br>WRN leaks found: 2<br>Error: Process completed with exit code 1.</pre><p>TruffleHog corroborated it independently, and its verification step confirmed the key was live:</p><pre>Warning: Found verified GCP result<br>{&quot;chunks&quot;: 1232, &quot;bytes&quot;: 1689095, &quot;verified_secrets&quot;: 1, &quot;unverified_secrets&quot;: 0}<br>Error: Process completed with exit code 183.</pre><p>Two findings from Gitleaks (a private key and its key ID), one verified hit from TruffleHog against Google’s own API. That combination left no ambiguity. This wasn’t a false positive or a vendored dependency artifact, it was a real, active credential.</p><p>Both checks failed. The merge button stayed disabled. The pull request could not reach main.</p><h3>Immediate Response: Containing the Exposure</h3><p>Once a scanner confirms a live credential, the response order matters more than the cleanup order.</p><p><strong>Revoke first.</strong> The service account key was deleted in the Google Cloud Console immediately, in IAM &amp; Admin, under the affected service account’s Keys tab. This happened before touching git history at all. A key that has been pushed to a remote, even briefly, should be treated as compromised. There’s no way to know with certainty whether it was scraped by an automated bot scanning public or shared repositories in that window.</p><p><strong>Audit second.</strong> Cloud Logging and the Vision API usage metrics were checked for the affected service account to look for any calls that didn’t originate from known infrastructure. No unauthorized usage turned up, but this step happens regardless of how confident you are, because assumptions aren’t evidence.</p><h3>Scrubbing Git History</h3><p>Deleting the file in a new commit does nothing for the exposure, since the key still exists in every prior commit that touched it. The file had to be purged from history entirely.</p><pre># Install git-filter-repo<br>pip install git-filter-repo</pre><pre># Remove the file from every commit in history<br>git filter-repo --path &quot;[REDACTED_FILENAME].json&quot; --invert-paths</pre><pre># Force push the cleaned history<br>git push origin --force --all<br>git push origin --force --tags</pre><p>A few things worth calling out about this step:</p><ul><li>git filter-repo rewrites commit hashes for every commit after the one where the file was introduced. Anyone with a local clone needs to discard it and reclone rather than pull.</li><li>If branch protection rules block force pushes (as they should, normally), those rules need to be temporarily relaxed for this one operation, then restored immediately after.</li><li>This only needs to happen once, and only because the key reached a remote branch. Catching a leak before it’s pushed at all avoids this step entirely, which is exactly what the next section is about.</li></ul><h3>Prevention: Making Sure It Doesn’t Happen Again</h3><p>Catching the leak at the PR stage worked, but PR stage is late. The goal after an incident like this is to push detection as early in the workflow as possible, and to make the failure mode harder to hit in the first place.</p><p><strong>Updated </strong><strong>.gitignore:</strong></p><pre># Google / GCP credentials<br>*-key.json<br>*-credentials.json<br>*.json.json<br>service-account*.json<br>google-vision*.json</pre><p><strong>Added a pre-commit hook</strong> so the same scanner runs locally, before a commit can even be made, not just at PR time:</p><pre># .pre-commit-config.yaml<br>repos:<br>  - repo: https://github.com/gitleaks/gitleaks<br>    rev: v8.18.0<br>    hooks:<br>      - id: gitleaks</pre><p><strong>Tightened branch protection</strong> so the secret scanning check is explicitly marked as required for merge, not just present in the workflow file. A check that exists but isn’t required can still be bypassed by an admin merge or a misconfigured ruleset.</p><p><strong>Removed file-based credentials entirely</strong> for this integration. Instead of a JSON key file, the service account credentials are now injected as a base64-encoded environment variable through the CI/CD secrets store:</p><pre># Set once in CI/CD secrets, never in code<br>export GOOGLE_CREDS_B64=&quot;[REDACTED]&quot;</pre><pre>import { Storage } from &#39;@google-cloud/storage&#39;;</pre><pre>const credentials = JSON.parse(<br>  Buffer.from(process.env.GOOGLE_CREDS_B64 || &#39;&#39;, &#39;base64&#39;).toString(&#39;utf-8&#39;)<br>);</pre><pre>const client = new Storage({ credentials });</pre><p>No file on disk means no file to accidentally git add.</p><h3>Closing Thoughts</h3><p>Nothing about this incident is unusual. A developer needed a credential to test something locally, and a file that should have stayed local ended up in a commit. That happens constantly, across teams of every size.</p><p>What made the difference here wasn’t avoiding the mistake, it was having a pipeline that assumed the mistake would happen eventually and was built to catch it before it mattered. The scan ran without anyone remembering to run it. It blocked the merge without anyone needing to notice the file in review. The only manual work required was the response once the pipeline had already done the hard part.</p><p>That’s the actual argument for secret scanning in CI/CD: not that it prevents developers from making mistakes, but that it makes the blast radius of a mistake close to zero.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=128113d275b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Zero-Touch CI/CD Pipeline for a Self-Managed Droplet]]></title>
            <link>https://medium.com/@viktohsmith2002/building-a-zero-touch-ci-cd-pipeline-for-a-self-managed-droplet-ad62e570426f?source=rss-14f831c88183------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad62e570426f</guid>
            <dc:creator><![CDATA[Ojedokun Mololuwa Victor ]]></dc:creator>
            <pubDate>Fri, 17 Jul 2026 16:25:30 GMT</pubDate>
            <atom:updated>2026-07-17T16:25:30.256Z</atom:updated>
            <content:encoded><![CDATA[<p>When you move off a managed platform and onto your own server, you lose the deploy button. There’s no dashboard that rebuilds your app the moment you push code. You’re back to doing it yourself, or building the automation that used to come for free.</p><p>This is a walkthrough of the CI/CD setup I built to replace that missing deploy button: two separate GitHub Actions workflows, one that guards main from bad code, and one that builds a Docker image, pushes it to a container registry, and deploys it to a DigitalOcean droplet over SSH, with a health check gating the release.</p><h3>Architecture</h3><p><strong>Workflow 1 — Checks, on pull request open against main</strong></p><pre>Pull request opened against main<br>      ↓<br>GitHub Actions: install dependencies<br>      ↓<br>Run test suite<br>      ↓<br>Lint the codebase<br>      ↓<br>Scan for committed secrets<br>      ↓<br>Checks pass → PR is safe to review and merge</pre><p><strong>Workflow 2 — Deploy, after the pull request is merged</strong></p><pre>Pull request merged into main<br>      ↓<br>GitHub Actions: build Docker image<br>      ↓<br>Push image to GitHub Container Registry (GHCR)<br>      ↓<br>SSH into droplet<br>      ↓<br>Pull new image + restart container<br>      ↓<br>Health check verifies /health endpoint<br>      ↓<br>Deployment marked successful (or workflow fails)</pre><p>Every step in both workflows runs unattended. Nothing reaches main without passing the checks workflow first, and if any step in the deploy workflow fails, the previous container keeps running, so a bad build never takes down production.</p><h3>Step 1: Building the Docker Image</h3><p>The app already had a multi-stage Dockerfile for building the TypeScript project and running the compiled output. The relevant parts:</p><pre>FROM node:20-alpine AS builder<br>WORKDIR /app<br>COPY package*.json ./<br>RUN npm ci<br>COPY . .<br>RUN npm run build</pre><pre>FROM node:20-alpine<br>WORKDIR /app<br>COPY --from=builder /app/dist ./dist<br>COPY --from=builder /app/node_modules ./node_modules<br>COPY package*.json ./<br>EXPOSE 3003<br>CMD [&quot;node&quot;, &quot;dist/app.js&quot;]</pre><p>Nothing exotic here. The multi-stage build keeps the final image lean by excluding dev dependencies and source files that aren’t needed at runtime.</p><h3>Step 2: The Checks Workflow</h3><p>This workflow, saved as .github/workflows/checks.yml, runs the moment a pull request is opened against main. It never touches production. Its only job is to catch problems before code review even starts.</p><pre>name: PR Checks</pre><pre>on:<br>  pull_request:<br>    branches: [main]</pre><pre>jobs:<br>  checks:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v4</pre><pre>      - name: Set up Node<br>        uses: actions/setup-node@v4<br>        with:<br>          node-version: 20</pre><pre>      - name: Install dependencies<br>        run: npm ci</pre><pre>      - name: Run tests<br>        run: npm test</pre><pre>      - name: Lint code<br>        run: npm run lint</pre><pre>      - name: Scan for committed secrets<br>        uses: gitleaks/gitleaks-action@v2<br>        env:<br>          GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}</pre><p>Every pull request has to pass all four steps before it’s mergeable. The secret scan in particular catches the kind of mistake that’s easy to make and expensive to fix after the fact, an API key or token committed by accident and pushed to a shared branch.</p><h3>Step 3: The Deploy Workflow</h3><p>This workflow, saved as .github/workflows/deploy.yml, runs only after a pull request is merged into main. Secrets referenced with ${{ secrets.NAME }} pull from GitHub&#39;s encrypted secrets store, never from plaintext in the repo.</p><pre>name: Deploy to Production</pre><pre>on:<br>  push:<br>    branches: [main]</pre><pre>jobs:<br>  build-and-deploy:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v4</pre><pre>      - name: Log in to GitHub Container Registry<br>        uses: docker/login-action@v3<br>        with:<br>          registry: ghcr.io<br>          username: ${{ github.actor }}<br>          password: ${{ secrets.GHCR_PAT }}</pre><pre>      - name: Build and push image<br>        uses: docker/build-push-action@v5<br>        with:<br>          context: .<br>          push: true<br>          tags: ghcr.io/████████████/backend:latest</pre><pre>      - name: Deploy to droplet<br>        uses: appleboy/ssh-action@v1<br>        with:<br>          host: ${{ secrets.DROPLET_HOST }}<br>          username: ${{ secrets.DROPLET_USER }}<br>          key: ${{ secrets.DROPLET_SSH_KEY }}<br>          script: |<br>            echo &quot;${{ secrets.GHCR_PAT }}&quot; | docker login ghcr.io -u ████████████ --password-stdin<br>            docker pull ghcr.io/████████████/backend:latest<br>            docker compose -f /opt/████████/docker-compose.yml up -d<br>            docker image prune -f</pre><pre>      - name: Verify deployment<br>        run: |<br>          sleep 10<br>          curl -f &quot;${{ secrets.APP_URL }}/health&quot; || exit 1</pre><p>A few details worth calling out:</p><ul><li>Because this workflow triggers on push to main, and main only changes through merged pull requests, it only ever runs after code has already passed the checks workflow.</li><li><strong>GHCR_PAT</strong> is a GitHub Personal Access Token scoped only to write:packages, so a leaked token can&#39;t do much beyond pushing images.</li><li><strong>DROPLET_SSH_KEY</strong> is a dedicated deploy key, separate from any personal SSH key, added only to the droplet&#39;s authorized_keys.</li><li><strong>docker image prune -f</strong> runs after every deploy to stop old, unused images from slowly filling the disk.</li></ul><h3>Step 4: Restarting the Container Cleanly</h3><p>The docker compose up -d command handles the restart. Because the image tag stays latest but the underlying image changes, Compose detects the new image and recreates the container rather than reusing the stale one.</p><pre>services:<br>  backend:<br>    image: ghcr.io/████████████/backend:latest<br>    container_name: ████████-backend<br>    restart: unless-stopped<br>    ports:<br>      - &quot;3003:3003&quot;<br>    env_file:<br>      - .env<br>    healthcheck:<br>      test: [&quot;CMD&quot;, &quot;wget&quot;, &quot;-qO-&quot;, &quot;http://localhost:3003/health&quot;]<br>      interval: 30s<br>      timeout: 5s<br>      retries: 3</pre><p>The .env file lives only on the droplet itself, outside version control, and is never touched by the pipeline. Application secrets and CI/CD secrets stay in two completely separate places.</p><h3>Step 5: Gating the Deploy with a Health Check</h3><p>The last step in the workflow isn’t optional. After restarting the container, the workflow waits ten seconds and hits the app’s /health endpoint directly:</p><pre>- name: Verify deployment<br>        run: |<br>          sleep 10<br>          curl -f &quot;${{ secrets.APP_URL }}/health&quot; || exit 1</pre><p>If the endpoint doesn’t return a success status, curl -f exits non-zero, the step fails, and GitHub Actions marks the whole run as failed. This turns a silent bad deploy into a visible, actionable failure instead of something you discover from a user report.</p><h3>What This Replaced</h3><p>Before this setup existed, a deploy meant:</p><ol><li>Merge code with no automated check that it was tested, linted, or free of leaked secrets</li><li>SSH into the droplet manually</li><li>Pull the latest code or rebuild the image by hand</li><li>Restart the container</li><li>Manually check that the app came back up</li></ol><p>Every one of those steps was a place a typo, a skipped step, or an untested change could cause downtime. Splitting the pipeline into two workflows removes all five from the human side of the process. Opening a pull request now guarantees a baseline of quality before anyone even reviews it, and merging that pull request is the entire deploy procedure from there.</p><h3>Result</h3><p>Nothing reaches main untested, unlinted, or unscanned for secrets, and every merge into main becomes a verified, running deployment within about two minutes, with no manual intervention and a built-in safety net if something goes wrong. The bigger shift isn’t the time saved. It’s that shipping small changes stopped feeling risky, which changes how often you’re willing to ship them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad62e570426f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating a Node.js/Express API from Vercel to a DigitalOcean Droplet: A Step-by-Step Guide]]></title>
            <link>https://medium.com/@viktohsmith2002/migrating-a-node-js-express-api-from-vercel-to-a-digitalocean-droplet-a-step-by-step-guide-4728eeee2215?source=rss-14f831c88183------2</link>
            <guid isPermaLink="false">https://medium.com/p/4728eeee2215</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Ojedokun Mololuwa Victor ]]></dc:creator>
            <pubDate>Fri, 10 Jul 2026 14:13:29 GMT</pubDate>
            <atom:updated>2026-07-10T14:13:29.835Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A practical walkthrough of moving a TypeScript/Express backend off serverless and onto a self-managed, observable, containerized server.</em></p><h3>Why Migrate Off Vercel?</h3><p>Vercel is great for getting an API live fast. But as traffic and complexity grow, a few limitations start to bite:</p><ul><li>Serverless cron jobs become unreliable for anything beyond simple scheduled pings</li><li>Cold starts add latency under bursty load</li><li>No native infra-level metrics (CPU, memory, disk, network)</li><li>No centralized log aggregation across invocations</li><li>Costs scale less predictably than a fixed-price droplet</li></ul><p>Here’s exactly how I moved a production Express + TypeScript backend from Vercel to a Dockerized DigitalOcean droplet, with full observability bolted on.</p><h3>Step 1: Provision the Droplet</h3><p>Everything starts with a clean, hardened Ubuntu server. I wrote a single idempotent provisioning script that:</p><ul><li>Verifies the OS and configures a swap file (prevents OOM kills on smaller droplets)</li><li>Updates packages non-interactively</li><li>Installs Docker via the official signed apt repo (not curl | sh)</li><li>Adds the deploy user to the docker group</li><li>Configures UFW, <strong>verifying the SSH rule exists before enabling the firewall</strong>, a small check that prevents accidentally locking yourself out</li><li>Sets up Nginx as a reverse proxy with a maintenance-page fallback</li></ul><pre># Firewall: always confirm SSH is allowed BEFORE enabling<br>sudo ufw allow OpenSSH<br>sudo ufw allow 22/tcp<br>sudo ufw allow 80/tcp<br>sudo ufw allow 443/tcp</pre><pre>if sudo ufw show added | grep -qiE &quot;(OpenSSH|22/tcp)&quot;; then<br>  sudo ufw --force enable<br>else<br>  echo &quot;ERROR: SSH rule not found. Aborting to prevent lockout.&quot;<br>  exit 1<br>fi</pre><p>Nginx config (trimmed):</p><pre>server {<br>    listen 80;<br>    server_name ██████████████████;   # your API domain</pre><pre>    location / {<br>        proxy_pass <a href="http://127.0.0.1:3003;">http://127.0.0.1:3003;</a><br>        proxy_http_version 1.1;<br>        proxy_set_header Host              $host;<br>        proxy_set_header X-Real-IP         $remote_addr;<br>        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;<br>        proxy_set_header X-Forwarded-Proto $scheme;<br>    }<br>}</pre><p>Once DNS pointed at the droplet, I issued a cert with:</p><pre>sudo certbot --nginx -d ██████████████████</pre><h3>Step 2: Containerize the App</h3><p>The Express app runs in Docker with a simple docker-compose.yml:</p><pre>services:<br>  backend:<br>    build:<br>      context: .<br>      dockerfile: Dockerfile<br>    container_name: ████-backend<br>    restart: unless-stopped<br>    ports:<br>      - &quot;3003:3003&quot;<br>    env_file:<br>      - .env<br>    healthcheck:<br>      test: [&quot;CMD&quot;, &quot;wget&quot;, &quot;-qO-&quot;, &quot;http://localhost:3003/health&quot;]<br>      interval: 30s<br>      timeout: 5s<br>      retries: 3</pre><p>restart: unless-stopped plus a /health check means the container self-heals if the process crashes.</p><h3>Step 3: Replace Vercel Cron with node-cron</h3><p>Vercel’s cron config looked like this:</p><pre>&quot;crons&quot;: [<br>  { &quot;path&quot;: &quot;/api/cron/auctions&quot;, &quot;schedule&quot;: &quot;0 0 * * *&quot; }<br>]</pre><p>On a long-running server, there’s a simpler and more reliable option: an in-process scheduler.</p><pre>import cron from &quot;node-cron&quot;;</pre><pre>cron.schedule(&quot;0 0 * * *&quot;, async () =&gt; {<br>  // run the auction job directly, no HTTP round-trip needed<br>  await runAuctionJob();<br>});</pre><p>No missed invocations, no dependency on an external trigger hitting your endpoint.</p><h3>Step 4: Error Tracking with Sentry</h3><p>Sentry has to initialize <strong>before</strong> anything else in the app. I put it in its own file:</p><pre>// src/instrument.ts<br>import dotenv from &quot;dotenv&quot;;<br>dotenv.config();</pre><pre>import * as Sentry from &quot;@sentry/node&quot;;<br>import { nodeProfilingIntegration } from &quot;@sentry/profiling-node&quot;;</pre><pre>Sentry.init({<br>  dsn: &quot;https://████████████████████████@██.ingest.sentry.io/██████&quot;,<br>  integrations: [nodeProfilingIntegration()],<br>  tracesSampleRate: 1.0,<br>  environment: process.env.NODE_ENV,<br>});</pre><p>Then in app.ts, import &quot;./instrument&quot; must be the <strong>very first line</strong>, and the Sentry error handler goes after all routes but before your own error handler:</p><pre>import &quot;./instrument&quot;; // must be first</pre><pre>// ...routes...</pre><pre>Sentry.setupExpressErrorHandler(app);</pre><pre>app.use((err, _req, res, _next) =&gt; {<br>  res.status(500).json({ success: false, message: &quot;Something went wrong!&quot; });<br>});</pre><p><strong>Key rule:</strong> Sentry init → routes → Sentry.setupExpressErrorHandler() → your own handler → 404 handler, in that exact order.</p><h3>Step 5: Ship Metrics with Grafana Alloy</h3><p>For CPU, memory, disk, and network visibility, I installed Grafana Alloy on the droplet and pointed it at Grafana Cloud Prometheus.</p><pre>prometheus.exporter.unix &quot;node&quot; {<br>  set_collectors = [&quot;cpu&quot;, &quot;meminfo&quot;, &quot;diskstats&quot;, &quot;filesystem&quot;, &quot;netdev&quot;, &quot;loadavg&quot;]<br>}</pre><pre>prometheus.remote_write &quot;grafana_cloud&quot; {<br>  endpoint {<br>    url = &quot;https://prometheus-prod-██-prod-██-████-█.grafana.net/api/prom/push&quot;<br>    basic_auth {<br>      username = &quot;███████&quot;<br>      password = &quot;████████████████████████████████&quot;<br>    }<br>  }<br>  external_labels = {<br>    app = &quot;████-backend&quot;,<br>    env = &quot;production&quot;,<br>  }<br>}</pre><p>⚠️ Two gotchas worth flagging:</p><ul><li>The pre-generated Grafana Cloud token is often <strong>read-only</strong>, so you need to explicitly create an access policy with metrics:write scope.</li><li>The token’s region must match your Prometheus stack’s region, or you’ll get silent auth failures.</li></ul><p>From there, a dashboard with an env variable (dev / production) lets the whole team switch context without duplicating panels.</p><h3>Step 6: Centralize Logs with Grafana Loki</h3><p>Rather than wiring logging into the app itself, I configured the <strong>Docker daemon</strong> to ship every container’s logs to Loki globally:</p><pre>{<br>  &quot;log-driver&quot;: &quot;loki&quot;,<br>  &quot;log-opts&quot;: {<br>    &quot;loki-url&quot;: &quot;https://███████:████████████████████████@logs-prod-███.grafana.net/loki/api/v1/push&quot;,<br>    &quot;loki-retries&quot;: &quot;3&quot;,<br>    &quot;loki-batch-size&quot;: &quot;102400&quot;,<br>    &quot;labels&quot;: &quot;container_name&quot;,<br>    &quot;loki-external-labels&quot;: &quot;app=████-backend,env=production&quot;<br>  }<br>}</pre><p>This is written once to /etc/docker/daemon.json on the host, never committed to the repo, never touched by CI/CD. After a systemctl restart docker and a container redeploy, logs are queryable in Grafana Explore:</p><pre>{app=&quot;████-backend&quot;} |= &quot;error&quot;</pre><p><strong>Gotcha:</strong> Docker log drivers are assigned at container <em>start</em> time. Restarting the daemon alone doesn’t retroactively apply the new driver to a running container, so you need to redeploy the container itself.</p><h3>Step 7: CI/CD</h3><p>The final piece was a deploy pipeline that SSHes into the droplet, pulls the latest image, and restarts the container, turning deploys into a git push instead of a manual SSH session.</p><h3>What I’d Tell Anyone Doing This Migration</h3><ol><li><strong>Observability isn’t optional.</strong> Vercel gives you a lot of this for free. The moment you self-host, you have to consciously rebuild error tracking, metrics, and logs, or you’re flying blind.</li><li><strong>Sequence matters for Sentry.</strong> Init order and error-handler placement are unforgiving; get it wrong and errors silently don’t get captured.</li><li><strong>Test your Loki/Prometheus tokens before wiring them into </strong><strong>daemon.json.</strong> A wrong scope or region produces a 401 that&#39;s easy to misdiagnose.</li><li><strong>Verify your firewall rule before enabling it.</strong> One line of defensive scripting (ufw show added | grep) can save you from locking yourself out of a remote box.</li></ol><p>The end result: an API with the same functionality as before, but now with real error visibility, infrastructure metrics, centralized logs, and predictable costs, running on infrastructure the team fully controls.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4728eeee2215" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>