mirror of
https://github.com/hanzoai/skills.git
synced 2026-11-19 00:47:36 +00:00
hanzoskills.com/llms.txt now opens with the install line, the API reference index and the company index, so an agent that lands on any one of the three can find the rest. robots.txt claimed 537 documents while llms.txt counts 920. The number is gone from robots.txt; llms.txt derives it. public/ is regenerated from scripts/site.py, which it had fallen behind: the copy-prompt menu and agent bar were in the generator and not in the committed pages. tests/site.mjs passes against the result. Co-authored-by: Hanzo Dev <[email protected]>
624 lines
31 KiB
HTML
624 lines
31 KiB
HTML
<!doctype html>
|
|
<html lang="en"><head>
|
|
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>deployment-heroku-addons</title>
|
|
<meta name="color-scheme" content="dark">
|
|
<style>
|
|
/* Committed to one visual world: a dark instrument panel. No light variant —
|
|
the dot field and the hairline rules only read on black, and a naive
|
|
inversion would wash both out. Every colour is painted explicitly so the page
|
|
never borrows a host background. */
|
|
@font-face{font-family:'Zen';src:url('/fonts/Zen-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
|
|
@font-face{font-family:'Zen';src:url('/fonts/Zen-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
|
|
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
|
|
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
|
|
@font-face{font-family:'Zen Pixel Square';src:url('/fonts/ZenPixel-Square.woff2') format('woff2');font-style:normal;font-display:swap}
|
|
|
|
:root{
|
|
--ink:#f4f4f2; --soft:#9c9c98; --faint:#6a6a66; --ground:#000; --panel:#0a0a0a;
|
|
--line:#232323; --line-hi:#3a3a3a; --accent:#f4f4f2;
|
|
--font-zen-sans:'Zen',-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif;
|
|
--font-zen-mono:'Zen Mono',ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
|
|
--font-zen-pixel-square:'Zen Pixel Square',monospace;
|
|
--mono:var(--font-zen-mono);
|
|
--sans:var(--font-zen-sans);
|
|
/* Controls are pills and surfaces are soft, as on hanzo.ai. */
|
|
--r:999px; --r-soft:14px;
|
|
}
|
|
*{box-sizing:border-box}
|
|
html{-webkit-text-size-adjust:100%}
|
|
body{margin:0;background:var(--ground);color:var(--ink);font-family:var(--sans);
|
|
font-size:16px;line-height:1.65;-webkit-font-smoothing:antialiased}
|
|
.wrap{max-width:60rem;margin:0 auto;padding:0 1.75rem}
|
|
|
|
/* The dot field. A halftone made of one repeating radial-gradient, faded out
|
|
along the diagonal by a mask so it reads as a wave rather than wallpaper. */
|
|
/* No overflow clip here: the dot field is inset to the box already, and a clip
|
|
would cut off the copy-prompt menu. */
|
|
.hero{position:relative;border-bottom:1px solid var(--line)}
|
|
.hero::before{content:"";position:absolute;inset:0;
|
|
background-image:radial-gradient(var(--line-hi) 1px, transparent 1px);
|
|
background-size:7px 7px;
|
|
-webkit-mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
|
|
mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
|
|
pointer-events:none}
|
|
.hero .wrap{position:relative;padding-top:5.5rem;padding-bottom:4rem}
|
|
|
|
nav{border-bottom:1px solid var(--line)}
|
|
nav .in{max-width:60rem;margin:0 auto;padding:1.1rem 1.75rem;display:flex;
|
|
justify-content:space-between;align-items:center;gap:1rem}
|
|
.brand{font-family:var(--mono);font-size:.85rem;letter-spacing:.14em;
|
|
text-transform:uppercase;color:var(--ink);text-decoration:none;
|
|
display:inline-flex;align-items:center;gap:.6rem}
|
|
.brand i{font-style:normal;color:var(--faint)}
|
|
.mark{width:1.15em;height:1.15em;display:block;flex:0 0 auto}
|
|
nav a.up{font-family:var(--mono);font-size:.72rem;letter-spacing:.14em;
|
|
text-transform:uppercase;color:var(--soft);text-decoration:none}
|
|
nav a.up:hover{color:var(--ink)}
|
|
|
|
h1{font-family:var(--mono);font-size:clamp(2rem,5.4vw,3.4rem);line-height:1.12;
|
|
letter-spacing:-.02em;margin:0 0 1.1rem;font-weight:500;text-wrap:balance}
|
|
h1 em{font-style:normal;color:var(--faint)}
|
|
.lede{color:var(--soft);font-size:1.05rem;max-width:52ch;margin:0 0 2.25rem}
|
|
|
|
.btns{display:flex;flex-wrap:wrap;gap:.7rem;margin:0 0 .5rem;align-items:center}
|
|
.btn{display:inline-flex;align-items:center;gap:.5rem;font-family:var(--mono);
|
|
font-size:.72rem;letter-spacing:.14em;text-transform:uppercase;
|
|
padding:.8rem 1.4rem;border:1px solid var(--line-hi);border-radius:var(--r);
|
|
color:var(--ink);text-decoration:none;background:transparent;cursor:pointer;
|
|
line-height:1.2;font-weight:400}
|
|
.btn:hover{background:#141414;text-decoration:none;border-color:var(--soft)}
|
|
.btn.solid{background:var(--ink);color:#000;border-color:var(--ink)}
|
|
.btn.solid:hover{background:#d8d8d4}
|
|
.btn .chev{width:.7em;height:.7em;flex:0 0 auto;transition:transform .15s ease}
|
|
.btn[aria-expanded="true"] .chev{transform:rotate(180deg)}
|
|
|
|
/* Copy-prompt selector. Each row copies the prompt for its own target. */
|
|
.copy{position:relative;display:inline-flex}
|
|
.menu{position:absolute;top:calc(100% + .5rem);left:0;z-index:20;min-width:21rem;
|
|
background:var(--panel);border:1px solid var(--line-hi);border-radius:var(--r-soft);
|
|
padding:.4rem;display:flex;flex-direction:column;
|
|
box-shadow:0 12px 32px rgba(0,0,0,.75)}
|
|
.menu[hidden]{display:none}
|
|
.mi{display:flex;align-items:center;gap:.7rem;width:100%;text-align:left;
|
|
padding:.62rem .8rem;border:0;border-radius:calc(var(--r-soft) - .35rem);
|
|
background:transparent;color:var(--ink);font-family:var(--mono);font-size:.76rem;
|
|
letter-spacing:.04em;text-decoration:none;cursor:pointer;line-height:1.3;
|
|
white-space:nowrap}
|
|
.mi:hover,.mi:focus-visible{background:#181818;outline:none}
|
|
.mi .mark{width:1.05rem;height:1.05rem;color:var(--soft)}
|
|
.mi:hover .mark{color:var(--ink)}
|
|
.mi u{margin-left:auto;color:var(--faint);text-decoration:none;font-size:.68rem;
|
|
letter-spacing:.1em;text-transform:uppercase}
|
|
|
|
/* Works-with bar: one scrolling row, name and mark per agent. */
|
|
.strip{border-bottom:1px solid var(--line);background:var(--panel)}
|
|
.strip .in{max-width:60rem;margin:0 auto;padding:.9rem 1.75rem;display:flex;
|
|
align-items:center;gap:1.25rem;font-family:var(--mono);font-size:.72rem;
|
|
letter-spacing:.1em;text-transform:uppercase;color:var(--faint)}
|
|
.strip b{color:var(--soft);font-weight:400;flex:0 0 auto;
|
|
border-right:1px solid var(--line);padding-right:1.25rem;align-self:stretch;
|
|
display:flex;align-items:center}
|
|
.bar{display:flex;align-items:center;gap:.5rem;flex:1 1 auto;min-width:0;
|
|
overflow-x:auto;scrollbar-width:none;scroll-snap-type:x proximity;
|
|
-webkit-overflow-scrolling:touch;
|
|
-webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent);
|
|
mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent)}
|
|
.bar::-webkit-scrollbar{display:none}
|
|
.agent{display:inline-flex;align-items:center;gap:.45rem;flex:0 0 auto;
|
|
padding:.4rem .85rem;border:1px solid var(--line);border-radius:var(--r);
|
|
color:var(--soft);white-space:nowrap;scroll-snap-align:start;
|
|
text-decoration:none;background:var(--ground)}
|
|
.agent:hover{color:var(--ink);border-color:var(--line-hi);text-decoration:none}
|
|
.agent .mark{width:.95rem;height:.95rem}
|
|
|
|
h2{font-family:var(--mono);font-size:1.1rem;letter-spacing:-.01em;margin:2.75rem 0 .75rem;font-weight:500}
|
|
h3{font-size:1rem;margin:2rem 0 .5rem;font-weight:600}
|
|
h4,h5,h6{font-size:.94rem;margin:1.5rem 0 .5rem;font-weight:600}
|
|
p{margin:0 0 1rem;max-width:70ch}
|
|
ul,ol{margin:0 0 1rem;padding-left:1.35rem;max-width:70ch}
|
|
li{margin:.22rem 0}
|
|
a{color:var(--ink);text-decoration:underline;text-underline-offset:3px;
|
|
text-decoration-color:var(--line-hi)}
|
|
a:hover{text-decoration-color:var(--ink)}
|
|
a:focus-visible{outline:1px solid var(--ink);outline-offset:3px}
|
|
code{font-family:var(--mono);font-size:.85em;background:var(--panel);
|
|
border:1px solid var(--line);border-radius:5px;padding:.1em .36em}
|
|
pre{background:var(--panel);border:1px solid var(--line);padding:1rem 1.1rem;
|
|
border-radius:var(--r-soft);overflow-x:auto;margin:0 0 1.25rem}
|
|
pre code{background:none;border:0;padding:0;font-size:.82rem;line-height:1.7}
|
|
blockquote{margin:0 0 1rem;padding-left:1rem;border-left:1px solid var(--line-hi);color:var(--soft)}
|
|
hr{border:0;border-top:1px solid var(--line);margin:2.5rem 0}
|
|
table{border-collapse:collapse;width:100%;margin:0 0 1.25rem;font-size:.92rem;
|
|
display:block;overflow-x:auto}
|
|
th,td{border:1px solid var(--line);padding:.5rem .7rem;text-align:left}
|
|
|
|
.curl{display:block;background:var(--panel);border:1px solid var(--line);
|
|
border-radius:var(--r-soft);padding:.95rem 1.1rem;font-family:var(--mono);
|
|
font-size:.8rem;color:var(--soft);overflow-x:auto;margin:0 0 2.5rem;
|
|
white-space:pre;line-height:1.9}
|
|
.curl b{color:var(--ink);font-weight:400}
|
|
.curl i{font-style:normal;color:var(--faint)}
|
|
|
|
/* index */
|
|
#q{width:100%;padding:.85rem 1.2rem;font-family:var(--mono);font-size:.85rem;color:var(--ink);
|
|
background:var(--panel);border:1px solid var(--line);border-radius:var(--r);margin:0 0 .6rem}
|
|
#q::placeholder{color:var(--faint);text-transform:uppercase;letter-spacing:.1em;font-size:.72rem}
|
|
#q:focus{outline:none;border-color:var(--soft)}
|
|
#count{color:var(--faint);font-family:var(--mono);font-size:.72rem;letter-spacing:.1em;
|
|
text-transform:uppercase;margin:0 0 2rem}
|
|
.cat{margin:2.5rem 0 .5rem;font-family:var(--mono);font-size:.7rem;letter-spacing:.16em;
|
|
text-transform:uppercase;color:var(--faint);border-bottom:1px solid var(--line);
|
|
padding-bottom:.45rem}
|
|
.row{display:block;padding:.6rem .9rem;margin:0 -.9rem;border-bottom:1px solid var(--line);
|
|
border-radius:var(--r-soft);text-decoration:none}
|
|
.row:hover{background:#0a0a0a}
|
|
.nm{font-family:var(--mono);font-size:.84rem;color:var(--ink);display:block}
|
|
.ds{color:var(--soft);font-size:.9rem;display:block;margin-top:.12rem}
|
|
footer{margin-top:4rem;padding:2rem 0 4rem;border-top:1px solid var(--line);
|
|
color:var(--faint);font-size:.85rem}
|
|
footer a{color:var(--soft)}
|
|
.fmap{display:grid;gap:1.75rem;grid-template-columns:repeat(auto-fit,minmax(11rem,1fr));
|
|
margin:0 0 2rem;font-size:.85rem}
|
|
.fmap b{display:block;font-family:var(--mono);font-size:.68rem;letter-spacing:.16em;
|
|
text-transform:uppercase;color:var(--faint);font-weight:400;margin:0 0 .6rem;
|
|
border-bottom:1px solid var(--line);padding-bottom:.4rem}
|
|
.fmap a{display:inline-block;color:var(--ink);text-decoration:none;margin:.3rem .35rem 0 0}
|
|
.fmap a:hover{text-decoration:underline}
|
|
.fmap div{color:var(--faint);line-height:1.5}
|
|
.fend{border-top:1px solid var(--line);padding-top:1.25rem;font-size:.82rem}
|
|
|
|
@media (max-width:640px){
|
|
.hero .wrap{padding-top:3.25rem;padding-bottom:2.75rem}
|
|
.btns{gap:.5rem}
|
|
.btn{padding:.75rem 1.15rem;font-size:.68rem}
|
|
.copy,.copy .btn{width:100%;justify-content:center}
|
|
.menu{left:0;right:0;min-width:0}
|
|
.strip .in{flex-direction:column;align-items:flex-start;gap:.6rem;padding:.9rem 1.75rem}
|
|
.strip b{border-right:0;padding-right:0}
|
|
.bar{width:100%}
|
|
}
|
|
</style>
|
|
<link rel="alternate" type="text/markdown" href="/deployment-heroku-addons.md">
|
|
|
|
<link rel="icon" href="/favicon.svg">
|
|
<link rel="canonical" href="https://hanzoskills.com/deployment-heroku-addons">
|
|
</head>
|
|
<!-- Reading this with a machine? Every page here is also plain markdown.
|
|
This one: https://hanzoskills.com/deployment-heroku-addons.md
|
|
Index: https://hanzoskills.com/llms.txt
|
|
Corpus: https://hanzoskills.com/all.md
|
|
Append .md to any path for the markdown twin. -->
|
|
<body>
|
|
<nav><div class="in">
|
|
<a class="brand" href="/"><svg class="mark" viewBox="0 0 67 67" fill="currentColor" aria-hidden="true"><path d="M22.21 67V44.6369H0V67H22.21Z"/><path d="M66.7038 22.3184H22.2534L0.0878906 44.6367H44.4634L66.7038 22.3184Z"/><path d="M22.21 0H0V22.3184H22.21V0Z"/><path d="M66.7198 0H44.5098V22.3184H66.7198V0Z"/><path d="M66.7198 67V44.6369H44.5098V67H66.7198Z"/></svg> HANZO<i>SKILLS</i></a>
|
|
<a class="up" href="/">All skills</a>
|
|
</div></nav>
|
|
|
|
<div class="wrap">
|
|
<h1>deployment-heroku-addons</h1><p class="lede">Adding databases (Postgres, MySQL, MongoDB) to Heroku apps</p><h1>Heroku Add-ons</h1>
|
|
<p><strong>Scope</strong>: Heroku add-on ecosystem, Postgres, Redis, monitoring, logging, email services <strong>Lines</strong>: ~310 <strong>Last Updated</strong>: 2025-10-18</p>
|
|
<h2>When to Use This Skill</h2>
|
|
<p>Activate this skill when:</p>
|
|
<ul><li>Adding databases (Postgres, MySQL, MongoDB) to Heroku apps</li><li>Setting up caching with Redis or Memcached</li><li>Implementing application monitoring and error tracking</li><li>Configuring log aggregation and analysis</li><li>Adding email delivery services (SendGrid, Mailgun)</li><li>Setting up scheduled jobs with Heroku Scheduler</li><li>Optimizing add-on costs and performance</li></ul>
|
|
<h2>Core Concepts</h2>
|
|
<h3>Add-on Architecture</h3>
|
|
<p><strong>Provisioning</strong>: Add-ons as managed services</p>
|
|
<ul><li>Single command installation: <code>heroku addons:create</code></li><li>Automatic configuration injection (environment variables)</li><li>Independent lifecycle from app code</li><li>Shared or dedicated resources (plan-dependent)</li></ul>
|
|
<p><strong>Connection Pattern</strong>:</p>
|
|
<pre><code class="lang-bash"># Add-on creates config var automatically
|
|
heroku addons:create heroku-postgresql:essential-0
|
|
|
|
# Check created config vars
|
|
heroku config | grep DATABASE_URL
|
|
# DATABASE_URL: postgres://user:pass@host:5432/dbname</code></pre>
|
|
<p><strong>Pricing Tiers</strong>:</p>
|
|
<ul><li>Free/Hobby: Development and testing</li><li>Essential: Small production apps</li><li>Premium/Standard: Production-grade with SLA</li><li>Enterprise: High availability, dedicated resources</li></ul>
|
|
<h3>Add-on Categories</h3>
|
|
<p><strong>Data Stores</strong>:</p>
|
|
<ul><li>Heroku Postgres: Primary relational database</li><li>Heroku Redis: Caching, sessions, queues</li><li>MongoDB Atlas: Document database</li><li>Apache Kafka: Event streaming</li></ul>
|
|
<p><strong>Developer Tools</strong>:</p>
|
|
<ul><li>Heroku Scheduler: Cron-like job runner</li><li>Heroku Exec: SSH into running dynos</li><li>Heroku Connect: Salesforce data sync</li></ul>
|
|
<p><strong>Monitoring & Logging</strong>:</p>
|
|
<ul><li>Papertrail: Log aggregation and search</li><li>New Relic: APM and performance monitoring</li><li>Sentry: Error tracking and debugging</li><li>LogDNA: Advanced log analysis</li></ul>
|
|
<p><strong>Performance</strong>:</p>
|
|
<ul><li>Fastly: CDN and edge caching</li><li>Cloudflare: DDoS protection and CDN</li><li>Advanced Scheduler: High-frequency cron jobs</li></ul>
|
|
<p><strong>Communication</strong>:</p>
|
|
<ul><li>SendGrid: Transactional email</li><li>Mailgun: Email API and SMTP</li><li>Twilio: SMS and voice</li></ul>
|
|
<hr>
|
|
<h2>Patterns</h2>
|
|
<h3>Pattern 1: Heroku Postgres Setup</h3>
|
|
<p><strong>Provision database</strong>:</p>
|
|
<pre><code class="lang-bash"># Essential plan (~$5/mo, 10GB storage, 20 connections)
|
|
heroku addons:create heroku-postgresql:essential-0
|
|
|
|
# Check status
|
|
heroku pg:info
|
|
|
|
# Output:
|
|
# Plan: Essential 0
|
|
# Status: Available
|
|
# Connections: 0/20
|
|
# PG Version: 15.3
|
|
# Created: 2025-10-18
|
|
# Data Size: 8.2 MB</code></pre>
|
|
<p><strong>Connection pooling</strong> (recommended for >20 connections):</p>
|
|
<pre><code class="lang-bash"># Enable connection pooling (increases connection limit)
|
|
heroku pg:connection-pooling:attach DATABASE --as DATABASE_CONNECTION_POOL
|
|
|
|
# Use pooled connection
|
|
heroku config:set DATABASE_URL=$(heroku config:get DATABASE_CONNECTION_POOL_URL)</code></pre>
|
|
<p><strong>Python connection</strong> (using psycopg2):</p>
|
|
<pre><code class="lang-python">import os
|
|
import psycopg2
|
|
from urllib.parse import urlparse
|
|
|
|
DATABASE_URL = os.environ['DATABASE_URL']
|
|
|
|
# Parse connection URL
|
|
url = urlparse(DATABASE_URL)
|
|
|
|
conn = psycopg2.connect(
|
|
database=url.path[1:], # Remove leading '/'
|
|
user=url.username,
|
|
password=url.password,
|
|
host=url.hostname,
|
|
port=url.port
|
|
)
|
|
|
|
# Or use Django DATABASE setting
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.postgresql',
|
|
'NAME': url.path[1:],
|
|
'USER': url.username,
|
|
'PASSWORD': url.password,
|
|
'HOST': url.hostname,
|
|
'PORT': url.port,
|
|
}
|
|
}</code></pre>
|
|
<p><strong>Backup and restore</strong>:</p>
|
|
<pre><code class="lang-bash"># Create manual backup
|
|
heroku pg:backups:capture --app myapp
|
|
|
|
# List backups
|
|
heroku pg:backups
|
|
|
|
# Restore from backup
|
|
heroku pg:backups:restore b101 DATABASE_URL --app myapp
|
|
|
|
# Download backup
|
|
heroku pg:backups:download
|
|
|
|
# Schedule automatic backups (Premium plans only)
|
|
heroku pg:backups:schedule DATABASE_URL --at '02:00 America/Los_Angeles'</code></pre>
|
|
<h3>Pattern 2: Heroku Redis for Caching</h3>
|
|
<p><strong>Provision Redis</strong>:</p>
|
|
<pre><code class="lang-bash"># Mini plan (~$3/mo, 25MB memory)
|
|
heroku addons:create heroku-redis:mini
|
|
|
|
# Check status
|
|
heroku redis:info
|
|
|
|
# Output:
|
|
# Plan: Mini
|
|
# Status: available
|
|
# Version: 7.0.8
|
|
# Max Memory: 25 MB</code></pre>
|
|
<p><strong>Python (Django cache)</strong>:</p>
|
|
<pre><code class="lang-python"># settings.py
|
|
import os
|
|
|
|
CACHES = {
|
|
'default': {
|
|
'BACKEND': 'django_redis.cache.RedisCache',
|
|
'LOCATION': os.environ.get('REDIS_URL'),
|
|
'OPTIONS': {
|
|
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
|
|
'SOCKET_CONNECT_TIMEOUT': 5,
|
|
'SOCKET_TIMEOUT': 5,
|
|
'CONNECTION_POOL_KWARGS': {'max_connections': 50}
|
|
}
|
|
}
|
|
}
|
|
|
|
# Use cache
|
|
from django.core.cache import cache
|
|
|
|
cache.set('key', 'value', 300) # 5 minutes
|
|
value = cache.get('key')</code></pre>
|
|
<p><strong>Node.js (with ioredis)</strong>:</p>
|
|
<pre><code class="lang-javascript">const Redis = require('ioredis');
|
|
const redis = new Redis(process.env.REDIS_URL);
|
|
|
|
// Set with expiration
|
|
await redis.set('user:123', JSON.stringify(userData), 'EX', 3600);
|
|
|
|
// Get
|
|
const data = await redis.get('user:123');
|
|
const user = JSON.parse(data);
|
|
|
|
// Pub/Sub pattern
|
|
const subscriber = new Redis(process.env.REDIS_URL);
|
|
subscriber.subscribe('notifications');
|
|
|
|
subscriber.on('message', (channel, message) => {
|
|
console.log(`Received ${message} from ${channel}`);
|
|
});
|
|
|
|
// Publish
|
|
await redis.publish('notifications', 'New order received');</code></pre>
|
|
<p><strong>Session storage</strong>:</p>
|
|
<pre><code class="lang-python"># Django sessions in Redis
|
|
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
|
|
SESSION_CACHE_ALIAS = 'default'</code></pre>
|
|
<h3>Pattern 3: Papertrail for Log Management</h3>
|
|
<p><strong>Provision Papertrail</strong>:</p>
|
|
<pre><code class="lang-bash"># Choklad plan (free, 50MB/mo, 2-day retention)
|
|
heroku addons:create papertrail:choklad
|
|
|
|
# Open dashboard
|
|
heroku addons:open papertrail</code></pre>
|
|
<p><strong>Search logs via CLI</strong>:</p>
|
|
<pre><code class="lang-bash"># Search for errors
|
|
heroku logs --tail | grep ERROR
|
|
|
|
# Or via Papertrail CLI
|
|
papertrail -f -S 'error OR exception'
|
|
|
|
# Search specific time range
|
|
papertrail -S 'status=500' --min-time '1 hour ago'</code></pre>
|
|
<p><strong>Structured logging</strong> (Python):</p>
|
|
<pre><code class="lang-python">import logging
|
|
import json
|
|
|
|
# JSON formatter for better Papertrail parsing
|
|
class JSONFormatter(logging.Formatter):
|
|
def format(self, record):
|
|
log_data = {
|
|
'timestamp': self.formatTime(record),
|
|
'level': record.levelname,
|
|
'message': record.getMessage(),
|
|
'module': record.module,
|
|
}
|
|
if record.exc_info:
|
|
log_data['exception'] = self.formatException(record.exc_info)
|
|
return json.dumps(log_data)
|
|
|
|
handler = logging.StreamHandler()
|
|
handler.setFormatter(JSONFormatter())
|
|
|
|
logger = logging.getLogger('myapp')
|
|
logger.addHandler(handler)
|
|
logger.setLevel(logging.INFO)
|
|
|
|
# Use logger
|
|
logger.info('User logged in', extra={'user_id': 123, 'ip': '1.2.3.4'})</code></pre>
|
|
<p><strong>Alerts</strong> (via Papertrail dashboard):</p>
|
|
<ul><li>Create search: <code>status=500</code></li><li>Set frequency threshold: <code>10 matches in 5 minutes</code></li><li>Send to: Email, Slack, PagerDuty</li></ul>
|
|
<h3>Pattern 4: SendGrid for Email</h3>
|
|
<p><strong>Provision SendGrid</strong>:</p>
|
|
<pre><code class="lang-bash"># Starter plan (free, 100 emails/day)
|
|
heroku addons:create sendgrid:starter
|
|
|
|
# Get API key
|
|
heroku config:get SENDGRID_API_KEY</code></pre>
|
|
<p><strong>Python (Flask-Mail)</strong>:</p>
|
|
<pre><code class="lang-python">from flask import Flask
|
|
from flask_mail import Mail, Message
|
|
import os
|
|
|
|
app = Flask(__name__)
|
|
|
|
app.config['MAIL_SERVER'] = 'smtp.sendgrid.net'
|
|
app.config['MAIL_PORT'] = 587
|
|
app.config['MAIL_USE_TLS'] = True
|
|
app.config['MAIL_USERNAME'] = 'apikey'
|
|
app.config['MAIL_PASSWORD'] = os.environ.get('SENDGRID_API_KEY')
|
|
app.config['MAIL_DEFAULT_SENDER'] = '[email protected]'
|
|
|
|
mail = Mail(app)
|
|
|
|
def send_welcome_email(user_email):
|
|
msg = Message(
|
|
subject='Welcome to MyApp',
|
|
recipients=[user_email],
|
|
body='Thanks for signing up!',
|
|
html='<h1>Thanks for signing up!</h1>'
|
|
)
|
|
mail.send(msg)</code></pre>
|
|
<p><strong>Node.js (SendGrid SDK)</strong>:</p>
|
|
<pre><code class="lang-javascript">const sgMail = require('@sendgrid/mail');
|
|
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
|
|
|
|
async function sendWelcomeEmail(email) {
|
|
const msg = {
|
|
to: email,
|
|
from: '[email protected]',
|
|
subject: 'Welcome to MyApp',
|
|
text: 'Thanks for signing up!',
|
|
html: '<h1>Thanks for signing up!</h1>',
|
|
};
|
|
|
|
await sgMail.send(msg);
|
|
}</code></pre>
|
|
<h3>Pattern 5: Heroku Scheduler for Cron Jobs</h3>
|
|
<p><strong>Provision Scheduler</strong>:</p>
|
|
<pre><code class="lang-bash"># Free add-on
|
|
heroku addons:create scheduler:standard
|
|
|
|
# Open dashboard to configure jobs
|
|
heroku addons:open scheduler</code></pre>
|
|
<p><strong>Configure job</strong> (via dashboard):</p>
|
|
<ul><li>Frequency: <code>Every 10 minutes</code>, <code>Hourly</code>, <code>Daily</code></li><li>Command: <code>python manage.py cleanup_expired_sessions</code></li><li>Dyno size: <code>Standard-1X</code></li></ul>
|
|
<p><strong>Example commands</strong>:</p>
|
|
<pre><code class="lang-bash"># Data cleanup
|
|
python manage.py cleanup_old_records
|
|
|
|
# Report generation
|
|
python manage.py generate_daily_report && python manage.py email_report
|
|
|
|
# Cache warming
|
|
python manage.py warm_cache
|
|
|
|
# Database maintenance
|
|
python manage.py vacuum_db</code></pre>
|
|
<p><strong>Alternative: APScheduler</strong> (in-process, for Standard+ dynos):</p>
|
|
<pre><code class="lang-python">from apscheduler.schedulers.background import BackgroundScheduler
|
|
|
|
scheduler = BackgroundScheduler()
|
|
|
|
@scheduler.scheduled_job('cron', hour=2, minute=0)
|
|
def cleanup_task():
|
|
# Run at 2:00 AM daily
|
|
cleanup_old_records()
|
|
|
|
@scheduler.scheduled_job('interval', minutes=10)
|
|
def sync_task():
|
|
# Run every 10 minutes
|
|
sync_external_data()
|
|
|
|
scheduler.start()</code></pre>
|
|
<h3>Pattern 6: New Relic APM for Performance Monitoring</h3>
|
|
<p><strong>Provision New Relic</strong>:</p>
|
|
<pre><code class="lang-bash"># Wayne plan (free, 100GB/mo data)
|
|
heroku addons:create newrelic:wayne
|
|
|
|
# Open dashboard
|
|
heroku addons:open newrelic</code></pre>
|
|
<p><strong>Python (Django) integration</strong>:</p>
|
|
<pre><code class="lang-bash"># Install agent
|
|
pip install newrelic
|
|
|
|
# Generate config
|
|
newrelic-admin generate-config $NEW_RELIC_LICENSE_KEY newrelic.ini
|
|
|
|
# Update Procfile
|
|
web: newrelic-admin run-program gunicorn myapp.wsgi</code></pre>
|
|
<p><strong>Environment configuration</strong>:</p>
|
|
<pre><code class="lang-bash">heroku config:set NEW_RELIC_APP_NAME='MyApp Production'
|
|
heroku config:set NEW_RELIC_LOG=stdout
|
|
heroku config:set NEW_RELIC_LOG_LEVEL=info</code></pre>
|
|
<p><strong>Custom instrumentation</strong>:</p>
|
|
<pre><code class="lang-python">import newrelic.agent
|
|
|
|
@newrelic.agent.function_trace()
|
|
def expensive_operation():
|
|
# Track function execution time
|
|
pass
|
|
|
|
# Record custom metric
|
|
newrelic.agent.record_custom_metric('Custom/ActiveUsers', user_count)
|
|
|
|
# Add custom attributes to transaction
|
|
newrelic.agent.add_custom_attribute('user_id', user.id)</code></pre>
|
|
<h3>Pattern 7: Cost Optimization Strategies</h3>
|
|
<p><strong>Review add-on costs</strong>:</p>
|
|
<pre><code class="lang-bash"># List all add-ons with pricing
|
|
heroku addons --all
|
|
|
|
# Check specific add-on details
|
|
heroku addons:info heroku-postgresql-12345</code></pre>
|
|
<p><strong>Optimization tactics</strong>:</p>
|
|
<p><strong>1. Right-size database</strong>:</p>
|
|
<pre><code class="lang-bash"># Downgrade if under-utilized
|
|
heroku pg:info # Check data size and connections
|
|
|
|
# If using <3GB on Standard-0 (50GB, $50/mo)
|
|
# Downgrade to Essential-0 (10GB, $5/mo)
|
|
heroku addons:upgrade heroku-postgresql-12345 essential-0</code></pre>
|
|
<p><strong>2. Use connection pooling</strong> (instead of higher plans):</p>
|
|
<pre><code class="lang-bash"># Increases effective connection limit
|
|
heroku pg:connection-pooling:attach DATABASE</code></pre>
|
|
<p><strong>3. Consolidate Redis instances</strong>:</p>
|
|
<pre><code class="lang-bash"># Use namespaces instead of multiple Redis instances
|
|
# cache:user:123
|
|
# session:abc456
|
|
# queue:high_priority</code></pre>
|
|
<p><strong>4. Scale dynos during low traffic</strong>:</p>
|
|
<pre><code class="lang-bash"># Use Heroku Scheduler to scale down at night
|
|
# Job at 11pm: heroku ps:scale web=1 worker=0
|
|
# Job at 6am: heroku ps:scale web=2 worker=1</code></pre>
|
|
<p><strong>5. Remove unused add-ons</strong>:</p>
|
|
<pre><code class="lang-bash"># Destroy add-on (DESTRUCTIVE, backs up data first!)
|
|
heroku addons:destroy heroku-postgresql-12345 --confirm myapp</code></pre>
|
|
<hr>
|
|
<h2>Quick Reference</h2>
|
|
<h3>Common Add-ons</h3>
|
|
<pre><code>Add-on | Purpose | Free Tier | Paid From
|
|
---------------------|----------------------|------------------|------------
|
|
heroku-postgresql | Postgres database | No | $5/mo
|
|
heroku-redis | Redis cache | No | $3/mo
|
|
papertrail | Log management | 50MB/mo | $7/mo
|
|
sendgrid | Email delivery | 100/day | $15/mo
|
|
heroku-scheduler | Cron jobs | Yes (Free) | Free
|
|
newrelic | APM monitoring | 100GB/mo | $99/mo
|
|
sentry | Error tracking | 5K events/mo | $26/mo
|
|
cloudflare | CDN + DDoS | Yes | $20/mo
|
|
mailgun | Email API | 5K emails/mo | $35/mo</code></pre>
|
|
<h3>Essential Commands</h3>
|
|
<pre><code>Command | Purpose
|
|
------------------------------------------|----------------------------------------
|
|
heroku addons | List all add-ons for app
|
|
heroku addons:create addon:plan | Provision add-on
|
|
heroku addons:upgrade addon plan | Change plan
|
|
heroku addons:destroy addon | Remove add-on (destructive)
|
|
heroku addons:info addon | Show add-on details
|
|
heroku addons:open addon | Open add-on dashboard
|
|
heroku pg:info | Postgres database info
|
|
heroku pg:psql | Connect to Postgres CLI
|
|
heroku pg:backups:capture | Create database backup
|
|
heroku redis:info | Redis instance info
|
|
heroku redis:cli | Connect to Redis CLI</code></pre>
|
|
<h3>Configuration Best Practices</h3>
|
|
<pre><code>✅ DO: Use connection pooling for Postgres (increases connection limit)
|
|
✅ DO: Enable automatic backups for production databases
|
|
✅ DO: Monitor add-on metrics (CPU, memory, connections)
|
|
✅ DO: Use structured logging for better Papertrail searches
|
|
✅ DO: Set up alerts for critical errors (500s, exceptions)
|
|
✅ DO: Review add-on costs monthly and optimize
|
|
✅ DO: Use appropriate plan for workload (don't over-provision)
|
|
|
|
❌ DON'T: Use Hobby tier for production (no SLA, limited resources)
|
|
❌ DON'T: Ignore connection pool exhaustion errors
|
|
❌ DON'T: Skip backups (data loss risk)
|
|
❌ DON'T: Provision multiple add-ons when one suffices
|
|
❌ DON'T: Hardcode add-on credentials (use environment variables)
|
|
❌ DON'T: Leave unused add-ons running (ongoing costs)</code></pre>
|
|
<hr>
|
|
<h2>Anti-Patterns</h2>
|
|
<p>❌ <strong>Using Hobby Postgres in production</strong>: No backups, limited connections, no SLA ✅ Use Essential tier minimum ($5/mo) with automatic backups enabled</p>
|
|
<p>❌ <strong>Not using connection pooling</strong>: Exhausts database connections quickly ✅ Enable <code>heroku pg:connection-pooling:attach</code> for apps with >10 dynos</p>
|
|
<p>❌ <strong>Ignoring database connection leaks</strong>: Unclosed connections accumulate ✅ Use connection context managers (<code>with</code> in Python) and properly close connections</p>
|
|
<p>❌ <strong>Over-provisioning add-ons</strong>: Paying for unused capacity ✅ Monitor usage metrics and right-size plans (downgrade if under-utilized)</p>
|
|
<p>❌ <strong>Multiple Redis instances for same app</strong>: Unnecessary cost ✅ Use single Redis with namespaced keys (<code>cache:</code>, <code>session:</code>, <code>queue:</code>)</p>
|
|
<p>❌ <strong>Not monitoring add-on health</strong>: Silent degradation ✅ Set up New Relic/Papertrail alerts for errors, slow queries, high memory</p>
|
|
<p>❌ <strong>Skipping database backups</strong>: Risk of data loss ✅ Enable automatic backups and test restore process</p>
|
|
<p>❌ <strong>Hardcoding add-on URLs</strong>: Breaks on credential rotation ✅ Always use environment variables (<code>DATABASE_URL</code>, <code>REDIS_URL</code>)</p>
|
|
<p>❌ <strong>No error tracking in production</strong>: Blind to user-facing bugs ✅ Add Sentry or similar for exception monitoring</p>
|
|
<p>❌ <strong>Using free email tier for production</strong>: Rate limits, deliverability issues ✅ Upgrade to paid SendGrid/Mailgun plan with dedicated IP</p>
|
|
<hr>
|
|
<h2>Related Skills</h2>
|
|
<ul><li><code>heroku-deployment.md</code> - Deploying apps that use add-ons</li><li><code>heroku-troubleshooting.md</code> - Debugging add-on connection and performance issues</li><li><code>postgres-query-optimization.md</code> - Optimizing database queries for better performance</li><li><code>redis-caching-strategies.md</code> - Advanced Redis patterns for caching and queues</li><li><code>structured-logging.md</code> - Best practices for log formatting and analysis</li><li><code>cost-optimization-cloud.md</code> - General cloud cost management strategies</li></ul>
|
|
<hr>
|
|
<p><strong>Last Updated</strong>: 2025-10-18 <strong>Format Version</strong>: 1.0 (Atomic)</p>
|
|
<footer>
|
|
<div class="fmap">
|
|
<div><b>Build</b>
|
|
<a href="https://hanzo.app">hanzo.app</a> app builder
|
|
<a href="https://hanzo.codes">hanzo.codes</a> code with an agent
|
|
<a href="https://hanzoskills.com">hanzoskills.com</a> what an agent reads</div>
|
|
<div><b>Run</b>
|
|
<a href="https://console.hanzo.ai">console.hanzo.ai</a> cloud console
|
|
<a href="https://api.hanzo.ai">api.hanzo.ai</a> the API</div>
|
|
<div><b>Account</b>
|
|
<a href="https://hanzo.id">hanzo.id</a> sign in
|
|
<a href="https://pay.hanzo.ai">pay.hanzo.ai</a> top up
|
|
<a href="https://billing.hanzo.ai">billing.hanzo.ai</a> invoices and usage</div>
|
|
<div><b>Company</b>
|
|
<a href="https://hanzo.ai">hanzo.ai</a> canonical
|
|
<a href="https://hanzo.ventures">hanzo.ventures</a> ventures</div>
|
|
</div>
|
|
<div class="fend"><a href="/deployment-heroku-addons.md">This page as plain text</a> · <a href="/llms.txt">Index for agents</a></div>
|
|
</footer>
|
|
</div></body></html> |