Obscura.Phoenix.Logger (obscura v0.1.3)

Copy Markdown View Source

Privacy-safe Phoenix request logging backed by redacted Plug assigns.

This handler is an opt-in replacement for Phoenix's default telemetry logger. It never reads conn.params. Instead, it logs the redacted copy produced by Obscura.Phoenix.Plug in :assign_redacted mode.

Disable Phoenix's default logger before starting this handler:

config :phoenix, :logger, false

Startup fails if a corresponding Phoenix default HTTP logger remains attached, preventing raw and sanitized request records from running together.

Place Obscura.Phoenix.Plug after Plug.Parsers and before the router:

plug Obscura.Phoenix.Plug,
  mode: :assign_redacted,
  fields: [:params]

plug MyAppWeb.Router

Then add the handler to the application supervision tree:

children = [
  {Obscura.Phoenix.Logger, assign: :obscura_redacted}
]

When the expected assign is missing, parameters are logged as [FILTERED]. Phoenix's configured :filter_parameters policy is applied as an additional safeguard. Parameter keys containing high-confidence :fast profile PII are replaced before inspection. Ambiguous bare domains are left to explicit Phoenix filter policies. Original request paths and exception reasons are intentionally omitted.

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts the telemetry handler.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the telemetry handler.

Options:

  • :assign - connection assign populated by Obscura.Phoenix.Plug; defaults to :obscura_redacted
  • :name - registered process name; defaults to this module
  • :inspect_opts - valid Inspect.Opts options used to inspect redacted parameters; defaults to [limit: 50, printable_limit: 500]

Unknown options and invalid assign or inspection options stop startup with an {:invalid_option, option, reason} error. Structs, tuples, character lists containing high-confidence :fast profile PII, and other opaque terms in the assigned params are rendered as [FILTERED] rather than invoking custom inspection code. Atom and numeric scalar representations are checked for high-confidence :fast profile PII before inspection. Parameter graphs exceeding 64 keys, 4 KiB of cumulative key text, 64 KiB of cumulative scalar value text, 1,024 traversed values, 128 terms requiring PII analysis, or 64 decimal digits in one number also fail closed as [FILTERED].