aicoded.dev

Telemetry: logs and traces

An app logs with Go's log/slog and records trace spans with telemetry.Start. The framework already records a span for every request, statement, file, mail and call, and ties each log line to its trace. None of it may hold personal data.

Logs

app.Main makes the default slog logger write JSON lines to standard output, with the trace_id and span_id of the context on every line that has one. Log with the context:

slog.InfoContext(ctx, "user added")
slog.InfoContext(ctx, "report sent", "rows", len(rows))

Spans

The framework records these spans:

Span Attributes For
HTTP GET, HTTP POST, … http.path every request the app serves, including its live connection
sql.query, sql.exec, sql.begin db.operation every statement; see the SQL database
filestore.<operation> store every file store operation; see file stores
mailer.send, mailer.list, … every mail call; see mail
rpc.call rpc.app, rpc.method every call to another app; see calls between apps

A call to another app carries the trace, so the called app's spans join the caller's trace.

To time your own work, start a span with the context, and end it:

ctx, span := telemetry.Start(ctx, "users.add")
span.SetAttr("photos", strconv.Itoa(len(photos)))
defer span.End()

addUser in the people example, which Deps.AddUser calls, records the error that ends it:

defer func() {
	if err != nil {
		span.RecordError(err)
	}
	span.End()
}()

aicoded dev keeps each app's last 10000 spans and shows them on the Traces page of the dev UI, as a tree with their timing, attributes and errors, and through the traces and trace tools of aicoded mcp.

On the platform

On the platform, the runner sends each app's output lines and spans to the platform's store, which keeps them 30 days, marked with the app's organisation, name, release and environment, preview or production, whatever the app sets. A line that is JSON keeps its level, trace and span; any other line counts as INFO. You read them with your sign-in, for an app you own:

One read covers at most 7 days and 1000 rows, and the platform writes it to its audit log: who read which app, the range and the filters, never the rows. On the platform, secret values are not hidden from the logs: never log one.

What the platform records about each request

Hosted by us, the runner, which carries every request to the app and every call it makes to an outside service, records each one itself; the app cannot write, edit or remove these records; what it answers (the status) is recorded as it is. It needs no code for them. For each request it records:

Calls a page makes in its live connection, such as page calls and live updates, are part of that connection: a page whose work is done by calls shows no latency or failures of its own.

From these records the platform shows each app's health: requests per second, latency and failures, by page and outside service. You read it with your sign-in, for an app you own, with aicoded health or the health tool of aicoded mcp; see the tools. In the console, the app's owner, the organisation's admins and security admins, and the platform's operator, whose reads as operator are written to the audit log, see its health; the app's owner and the organisation's admins and security admins also see its usage: how many people opened it and which pages, as numbers only. The records are kept 32 days; health by the minute 14 days and by the hour 90 days; the daily usage numbers 13 months. Usage and health are Hosted by us only for now: In your own cloud the runner records none of this, and a read is refused with E-REL-011.

The viewer's pseudonym is the first 16 bytes of an HMAC-SHA256 of the viewer's sign-in, with a key of 32 random bytes that the platform keeps for each app and never gives to the app. That is not what E-LINT-008 forbids: a hash the app makes of the viewer's identity can be made again by anyone who has the app's code and the identity, so it names the viewer wherever the hash goes. The platform's key is outside the app, so neither the app nor a reader of its logs can make the pseudonym, and one person's pseudonyms in two apps cannot be joined by anyone without the platform's keys. The platform's operator holds those keys and could compute a known person's pseudonym; the data processing description says so. With the key, the operator could read that person's times and pages in one app; and with a small audience, the usage counts are close to personal. It is still personal data: it is kept 32 days with the records and is never shown in the console, the API or the tools; usage shows only counts.

No personal data

Logs and spans reach more tools and more people than the app's data does. Never put personal data in them: no form values, names, logins, email addresses, uploaded file names or message texts, and no secret.

See also

Markdown · Source on GitHub · framework 93c19e3