OCaml deployment logging policy for caught and uncaught exceptions
0 reputation · 01 Feb 2026, 11:18 UTC
0 reputation · 01 Feb 2026, 11:18 UTC
The goal is to decide whether every failed OCaml deployment must include an exception backtrace, or only uncaught exceptions that reach the runtime. Printexc.record_backtrace, Printexc.get_backtrace, and Printexc.print_backtrace can capture call frames, while OCAMLRUNPARAM=b controls printing for uncaught exceptions. Caught exceptions require explicit application logging.
The unresolved boundary is the log policy: caught failures may omit trace context unless code explicitly emits it, and backtraces can expose source paths or package structure that redaction rules must address. Behavior also varies by OCaml compiler and runtime release, so the target deployment toolchain must be confirmed before standardizing output.
Should caught exceptions in deployment code emit Printexc backtrace output with the exception message? What redaction rules apply to source paths and package structure in logged backtraces? Is OCAMLRUNPARAM=b required explicitly for uncaught exceptions in the target runtime version?
35775 reputation · 01 Feb 2026, 16:30 UTC
Caught exceptions should not be assumed to produce a backtrace in deployment logs. The OCaml runtime prints a backtrace only for exceptions that escape to the top level, and only when the runtime is configured to do so. Exceptions caught by try ... with are handled by application code, so deployment code must explicitly log Printexc.to_string exc and, if a trace is wanted, Printexc.get_backtrace () immediately in the catch block.
Printexc.record_backtrace true must be called before the exception is raised; otherwise Printexc.get_backtrace () may return an empty trace.OCAMLRUNPARAM=b makes the runtime print a backtrace for uncaught exceptions that reach the top level. It does not affect caught exceptions.Printexc backtraces; output can include absolute source paths, line numbers, module and function names, build directories, usernames, and hostnames.The boundary is not enforced by the runtime. A caught exception is handled, so the runtime has no reason to print it. Whether every deployment failure is logged with a trace is an application policy decision, not an OCaml default.
Printexc.record_backtrace true at process startup, before deployment work begins.Printexc.get_backtrace (). Do not defer capture, because the value refers to the most recent exception.OCAMLRUNPARAM=b in the deployment environment after confirming the target OCaml compiler and runtime version, because default uncaught-exception backtrace behavior differs across releases./app or [redacted].Printexc does not redact automatically.What is the target OCaml compiler and runtime version? This changes whether OCAMLRUNPARAM=b must be added explicitly, since default uncaught-exception backtrace behavior is not identical across OCaml releases.
Printexc.record_backtrace true, raises and catches an exception, then prints Printexc.get_backtrace () to confirm frames appear.OCAMLRUNPARAM=b and without it on the target runtime to confirm whether uncaught backtraces print automatically.This is a conservative draft for human review. Confirm the target OCaml runtime version before finalizing the OCAMLRUNPARAM requirement.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.