Skip to content
Coritan Docs

Read logs and metrics

Read and follow a deployment's logs, forward them to your own service with a drain, and watch its requests, errors, latency and alerts.

View as Markdown

What your app prints goes to its logs, which you can search, follow live and forward to a service of your own. The deployment's metrics count its requests, errors, latency and bandwidth for every hour, and alerts tell you by email when a release fails, errors climb or an instance runs out of memory. The Logs and Metrics tabs hold them for a web service or a hybrid site, and a static site has the Metrics tab. A game server's or a database's output is in its console instead (Use the console).

  • Logs are kept for as long as your plan says: 7 days on Free and Pro, 30 days on Business and 90 days on Enterprise (Pricing). The log data a deployment writes is billed by the GB past the free amount each month (Usage rates).
  • A deployment billed by use has log drains once your account has made the first deposit (What you need to run an instance). On older terms, log drains are part of the Pro, Business and Enterprise plans.

Open the deployment and select the Logs tab. The newest lines are at the bottom, each with its time, the instance and process that printed it, and the location. You can:

  • search for lines that hold a word, ignoring case;
  • narrow the lines to one instance or one process, such as web or worker;
  • go back to a time, such as two hours ago, and page through older lines;
  • follow new lines live as the instances print them.

Lines are collected from the instances every minute, so a line's time is when it was collected, within a minute of when it was printed. When an instance printed faster than we could collect, a line is marked as coming after a gap, because lines may be missing just before it. An instance that stops is read once more, so its last words are kept.

A live tail shows each instance's recent lines, then follows new ones for up to 15 minutes, including instances that a new release starts meanwhile. You can have up to 5 live tails open at once. From a terminal, coritan logs -f does the same (The Coritan CLI).

A drain sends the deployment's lines to a service of your own as they are collected, such as a log platform or your own server:

HTTP
Each batch is a POST of newline-delimited JSON to an https:// address. Each request is signed, so your service can check it came from us (Check a drain's signature).
Syslog
RFC 5424 messages over TLS to an address such as syslog+tls://logs.example.com:6514.

To add one, open the Logs tab and select Add drain… on the Log drains card. The Add a drain page opens. Choose the Format, enter the Address, and set Processes and From to limit what it sends. Select Add drain, and the page takes you back to the tab. To change a drain, open its menu in the list and select Edit drain…; the Edit drain page has the same fields and a Save drain button.

A drain can take only some processes, or only production or previews. It starts with the newest line collected when you create it, not the history. Delivery is at least once, so a batch that failed can arrive twice: remove duplicates by each line's id. Lines more than an hour old when a drain reaches them are skipped. A drain that fails every minute for an hour is turned off, and says why. Send a test line at any time to check it.

On older terms your plan sets how many drains your account can have, counted across all its deployments. A deployment billed by use has no plan limit. Either way, a deployment can have up to 10.

An HTTP drain has a secret, which we generate unless you give one of 16 to 200 characters, and which is shown only once: the Add a drain page shows it after you select Add drain and stays open until you select I have saved it. Each request carries X-Coritan-Signature: t=<unix time>,v1=<signature>, where the signature is the HMAC SHA-256 of the time, a full stop and the raw body, keyed with the secret:

Python
import hashlib, hmac, time

def verify(secret: str, header: str, body: bytes, tolerance: int = 300) -> bool:
    parts = dict(item.split("=", 1) for item in header.split(","))
    t = int(parts["t"])
    expected = hmac.new(secret.encode(), f"{t}.".encode() + body, hashlib.sha256).hexdigest()
    return abs(time.time() - t) <= tolerance and hmac.compare_digest(expected, parts["v1"])

Each line is an object with id, ts, deployment, deployment_name, instance, process, location, release, environment, message and gap. A test line also has "test": true.

The Metrics tab shows the last 24 hours, 7 days or 30 days, hour by hour: requests, how many were blocked by the firewall, answers by status (2xx, 3xx, 4xx, 5xx), bandwidth in and out, and the average and slowest latency. It also shows each running instance's processor and memory use now and over the last hour, day or week, kept as long as your plan keeps logs. You can look at one address at a time, such as a preview's.

Under Instances now, an instance at 90% or more of its memory limit has an amber bar and a note under it. The note says that the limit grows if memory stays this high, that it cannot grow past the largest limit, that the next step is waiting for room, or that the limit is the size of the plan (Memory grows automatically).

Recent requests are sampled at every location and kept for 3 days: for each address, every request up to 5 a second, then one in a hundred, and every 5xx answer. Filter them by address, answer or path to find the path behind a burst of errors.

Page views and visitors are counted for the pages that load the Coritan tracking script, over 7, 30 or 90 days. Requests count everything; page views count only people who loaded a page with the script.

We email the deployment's owner, or an organization's owner, when:

  • a production release fails;
  • errors climb: in one hour, at least 100 requests of which 10% or more were 5xx answers;
  • visitors kept waking a sleeping deployment: 25 requests or more in an hour while it was asleep (Sleep when idle);
  • an instance ran out of memory: it restarted after using 90% or more of its memory limit, or restarted twice or more in an hour (Restarts and running out of memory);
  • an instance uses 90% or more of its memory limit and the limit cannot grow: it is the largest limit you allow, a location has no room for the next one, or a spend limit holds the deployment (When the limit cannot grow).

Alert emails follow your Usage alerts preference (Notifications). An organization's webhooks get the same alerts as events. We send an error spike, a wake storm or an out of memory alert once for each incident, and not again for the same deployment within six hours. We send the memory at its limit alert at most once every 6 hours for a deployment.

Restarts and running out of memory

Section titled Restarts and running out of memory

An instance that uses all the memory its size allows is stopped and started again by the system. Your app prints nothing about it, so a deployment can serve errors until the instance is back, with no sign in the logs.

We read every running instance's uptime about once a minute. When an instance's uptime falls, it restarted. We record that as a deployment.instance.restarted event, which an organization's webhooks can receive (Deployment events). The event's reason is out_of_memory when the instance was using 90% or more of its memory limit at the reading before the restart, and restarted otherwise. We leave out a restart we caused: one after a power action we sent in the last two minutes, a wake from sleep, or while a release is on its way.

An instance that stays close to its memory limit is replaced before it fails. When a web instance of the live release keeps using 95% or more of its memory limit, we start a fresh instance in the same location. Once the fresh instance serves, the old one stops taking new requests and is stopped, so visitors do not see a gap. We replace one instance of a location at a time, and not again in that location for 15 minutes. The deployment.instance.replaced event records each replacement, and a replacement is not counted as a failure. The same replacement runs when the memory limit changes: an instance that still runs the earlier limit is replaced with one at the new limit, one instance of a location at a time, and the event's reason is memory_limit (Memory grows automatically).

A fresh instance starts with empty memory, so a replacement buys time and does not cure the cause. When an instance runs out of memory, or the alert names the same instance twice in an hour:

  1. Open the Metrics tab and look at each instance's memory over time. A line that only climbs points to a memory leak.
  2. Look in your code for what holds on to memory, such as a cache that never shrinks or a list that only grows.
  3. If the app needs the memory, let the limit grow. A deployment billed by use raises its memory limit by itself, one step at a time, up to the largest limit you set, which is 4 GB until you change it. Raise the largest limit when an instance is already at it (Set the largest limit). A bigger limit costs nothing until the instances use it (How App Deployment is billed). A deployment on older terms takes its size from the plan it is billed on (Change a service's plan explains how to move to another size), and Redeploy afterwards starts the instances at the new size (Deploy, promote and roll back releases).

The Logs tab shows what the instances printed, and a drain's last delivery says when lines last reached your service.

The logs are empty
Lines are collected every minute, so a new instance's first lines take up to a minute to appear. A static site has no instances and no logs.
A drain turned itself off
It failed for an hour. Its last error says why, such as a refused connection or a 401. Fix the address or the secret, then turn it on again, which starts it from the newest line.
too_many_streams
You have 5 live tails open. Close one, or wait for one to end.
The metrics for the current hour are empty
Each hour fills in after it ends.
An instance keeps restarting
The alert email, and GET /alerts, say which instance and why. A trigger of out_of_memory means the instance restarted at 90% or more of its memory, so follow the steps under Restarts and running out of memory. A trigger of repeated_restarts means it restarted twice or more in an hour without that: read its logs from just before each restart for a crash.

The routes are under /api/v1/client/deployments/{uuid} for your own deployment and /api/v1/orgs/{org_slug}/deployments/{uuid} for an organization's. Any member of an organization reads them; owners and admins change drains.

GET /logs answers the newest limit lines (100 unless you ask for up to 1,000), oldest first, with since, until, instance, process and q to narrow them. since and until take a time or how long ago, such as 2h. Pass the answer's next as before for older lines, and add format=ndjson for one line object a line:

Shell
curl "https://api.coritan.com/api/v1/client/deployments/$DEPLOYMENT/logs?since=2h&q=timeout" \
  -H "Authorization: Bearer $CORITAN_TOKEN"

GET /logs/stream follows new lines as Server-Sent Events, with tail (up to 200 lines to start with) and seconds (up to 900). GET /logs/instances lists the instances with lines kept, and their id for instance.

POST /drains with {"kind": "http", "url": "https://intake.example.com/v1"} creates a drain and answers its generated secret this once. PATCH /drains/{id} changes it, POST /drains/{id}/test sends a test line, and DELETE /drains/{id} removes it.

GET /metrics?window=7d, GET /requests?status=5xx, GET /analytics?window=30d and GET /alerts answer what the Metrics tab shows.

GET /alerts lists the alerts, newest first, and kind narrows them to release_failed, error_spike, wake_storm, out_of_memory or memory_at_limit. An out_of_memory alert's details has location, instance, trigger (out_of_memory or repeated_restarts), restarts, memory_percent and release. A memory_at_limit alert's details has reason (largest_limit, no_room or spend_limit), location, instance, memory_percent, limit_mb, limit_text, max_mb, max_text and release. limit_text and max_text write the limits as people read them, such as 2 GB.

API operations on this page

MethodPathWhat it does
GET/api/v1/client/deployments/{deployment_uuid}/logsGet logs
GET/api/v1/client/deployments/{deployment_uuid}/logs/instancesGet log instances
GET/api/v1/client/deployments/{deployment_uuid}/logs/streamStream logs
GET/api/v1/client/deployments/{deployment_uuid}/drainsList drains
POST/api/v1/client/deployments/{deployment_uuid}/drainsA drain that forwards the lines collected from now on
PATCH/api/v1/client/deployments/{deployment_uuid}/drains/{drain_id}Update drain
DELETE/api/v1/client/deployments/{deployment_uuid}/drains/{drain_id}Remove the drain; nothing more is sent to it
POST/api/v1/client/deployments/{deployment_uuid}/drains/{drain_id}/testTest drain
GET/api/v1/client/deployments/{deployment_uuid}/requestsGet requests
GET/api/v1/client/deployments/{deployment_uuid}/metricsGet metrics
GET/api/v1/client/deployments/{deployment_uuid}/analyticsGet analytics
GET/api/v1/client/deployments/{deployment_uuid}/alertsGet alerts
GET/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/logsGet logs
GET/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/logs/instancesGet log instances
GET/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/logs/streamStream logs
GET/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/drainsList drains
POST/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/drainsA drain that forwards the lines collected from now on
PATCH/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/drains/{drain_id}Update drain
DELETE/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/drains/{drain_id}Remove the drain; nothing more is sent to it
POST/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/drains/{drain_id}/testTest drain
GET/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/requestsGet requests
GET/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/metricsGet metrics
GET/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/analyticsGet analytics
GET/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/alertsGet alerts