Recipes

Content Security Policy

If your site uses Content Security Policy, you'll need to add 'nonce-<value>' to script-src and eventually the same nonce to style-src for Tracy to work properly. Some 3rd plugins may require additional directives. Avoid adding 'unsafe-inline' & 'unsafe-eval' in production mode, if you can.

Configuration example for Nette Framework:

http:
	csp:
		script-src: nonce
		style-src: nonce

Faster loading

The basic integration is straightforward, however if you have slow blocking scripts in web page, they can slow the Tracy loading. The solution is to place <?php Tracy\Debugger::renderLoader() ?> into your template before any scripts:

<!DOCTYPE html>
<html>
<head>
	<title>...<title>
	<?php Tracy\Debugger::renderLoader() ?>
	<link rel="stylesheet" href="assets/style.css">
	<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>

AJAX and redirected requests

Tracy is able to show Debug bar and Bluescreens for AJAX and redirected requests. You just have to start session before Tracy:

session_start();
Debugger::enable();

In case you use non-standard session handler, you can start Tracy immediately (in order to handle any errors), then initialize your session handler and then inform Tracy that session is ready to use via dispatch():

Debugger::enable();

// initialize session handler
session_start();

Debugger::dispatch();

Custom Logger

We can create a custom logger to log errors, uncatched exceptions, and also be called by Tracy\Debugger::log(). Logger implements the interface Tracy\ILogger.

use Tracy\ILogger;

class SlackLogger implements ILogger
{
	public function log($value, $priority = ILogger::INFO)
	{
		// sends a request to Slack
	}
}

And then we activate it:

Tracy\Debugger::setLogger(new SlackLogger);

If we use the full Nette Framework, we can set it in the NEON configuration file:

services:
	tracy.logger: SlackLogger

nginx

If Tracy does not work on nginx, it is probably misconfigured. If there is something like

try_files $uri $uri/ /index.php;

change it to

try_files $uri $uri/ /index.php$is_args$args;
Improve this page