I needed to do this, and Paul Titheridge from the MQ change team pointed me to some information on how to do this – thank you Paul!
From MQ V8 onwards it is possible to turn on trace dynamically using a utility called traceControl. This is documented here.
Paul has also written a blog post on this, to show how it is used in practice. See here.