TraceGuard.Storage.Ecto.Migration (trace_guard v0.1.0)

Copy Markdown View Source

Experimental in 0.1.0. Creates and drops the table used by TraceGuard.Storage.Ecto, from your application's own migration. TraceGuard never runs migrations itself.

Generate a migration with mix trace_guard.gen.ecto_migration, or write one:

defmodule MyApp.Repo.Migrations.AddTraceGuardReports do
  use Ecto.Migration

  def up, do: TraceGuard.Storage.Ecto.Migration.up(version: 1)
  def down, do: TraceGuard.Storage.Ecto.Migration.down(version: 1)
end

then run mix ecto.migrate as usual.

Options

  • :version: the schema version to migrate to (up) or from (down). Only 1 exists. Pin it in your migration so that a later TraceGuard release can't change what an already-run migration does.
  • :prefix: a PostgreSQL schema to create the table in (default: the Repo's default, usually public). Use the same :prefix in the adapter's configuration.

Schema version 1

Table trace_guard_reports:

ColumnTypePurpose
idbigserial (primary key)insertion order (newest = highest)
trace_idvarchar(32), uniquelookup
outcome, method, kindvarcharfilters
route, exceptiontextfilters
statusintegerfilters
request_idvarchar, indexedfilter (from Plug.RequestId)
incoming_idvarchar(128), indexedfilter (client correlation ID)
summaryjsonbTraceGuard.Storage.summary/1
reportjsonbthe redacted report
inserted_attimestamp, indexedage-based retention

Indexes: unique trace_id, inserted_at, incoming_id, request_id, and (route, status).

The filter columns duplicate fields of the redacted summary; nothing in the table comes from anywhere other than the redacted report.

Rollback

down(version: 1) drops the table and all stored reports. Before rolling back, switch TraceGuard to another storage adapter or deploy without the Ecto adapter. While the table is missing, writes are dropped with {:ecto_error, :undefined_table} and reads return {:error, :unavailable}.

Summary

Functions

Drops TraceGuard's table (and every stored report).

Creates TraceGuard's table (schema :version, default and latest: 1).

Functions

down(opts \\ [])

Drops TraceGuard's table (and every stored report).

up(opts \\ [])

Creates TraceGuard's table (schema :version, default and latest: 1).