In ComponentPageElementImpl there is a check if request has a parameter to enable component tracing:
// should be okay since it's a shadow service object - NOT
private final Request request;
return !productionMode && (componentTracingEnabled || "true".equals(request.getParameter("t:component-trace")));
in a case when PageDocumentGenerator is used there is no request and shadow builder will throw an exception.
Solution would be to use RequestGlobals and check if there is a request.