formatDiagnosticValue
Renders one value for a diagnostic - an exception's query context, or a traced statement.
Every place a parameter is shown to a human goes through here, so a value reads the same whichever of them the reader is looking at.
The rendering is bounded as it is built, not trimmed afterwards, and that distinction is the whole point. Cutting value.toString() down to size materialises the entire thing first: this driver's own bulk-write idiom passes an array of ten thousand elements as a single parameter, so "render it all, then keep a hundred characters" would build a string of megabytes to discard almost all of it - on the error path, where something has already gone wrong.
So containers are walked element by element against a shared budget and abandoned once it is spent, and a ByteArray is named rather than dumped, its toString being an identity hash anyway. The one thing that cannot be bounded is a class the driver does not know: its toString is a single opaque call that renders whatever it renders. Small DTOs are worth reading and most are small, so it is still called - but a custom toString that assembles something enormous is beyond anything this can do about it.