Skip to content

The only tool you need to know what is happening and how to fix it.

3.8 KB
Raw Blame
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Distributed Trace Test (CDN)</title>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@tracewayapp/[email protected]/dist/traceway-jquery.iife.global.js"></script>
    <style>
        body { font-family: system-ui, -apple-system, sans-serif; max-width: 700px; margin: 40px auto; padding: 0 20px; }
        h1 { margin-bottom: 8px; }
        p { color: #555; line-height: 1.5; }
        code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 13px; }
        .badge { display: inline-block; background: #dbeafe; color: #1d4ed8; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 9999px; margin-left: 8px; vertical-align: middle; }
        .buttons { display: flex; gap: 12px; margin-bottom: 24px; }
        .btn { color: #fff; border: none; padding: 10px 18px; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 600; }
        .btn:hover { opacity: 0.9; }
        .btn-error { background: #dc2626; }
        .btn-success { background: #16a34a; }
        .btn-clear { background: #6b7280; }
        #log { background: #111; color: #0f0; padding: 16px; border-radius: 8px; font-family: monospace; font-size: 13px; min-height: 200px; white-space: pre-wrap; }
    </style>
</head>
<body>
    <h1>Distributed Trace Test <span class="badge">CDN</span></h1>
    <p>
        This page loads <code>@tracewayapp/jquery</code> directly from the jsdelivr CDN — no npm install or build step needed.
        Click the error button to trigger a backend 500 error. The
        <code>traceway-trace-id</code> header links the frontend exception
        to the backend error in the dashboard.
    </p>

    <div class="buttons">
        <button class="btn btn-error" id="btn-error">Call Backend Error Endpoint</button>
        <button class="btn btn-success" id="btn-success">Call Backend Success Endpoint</button>
        <button class="btn btn-clear" id="btn-clear">Clear Log</button>
    </div>

    <div id="log">Waiting for actions...</div>

    <script>
    TracewayJQuery.init("frontend-dev-token@http://localhost:8082/api/report", {
        recordAllSessions: true,
    });

    function addLog(msg) {
        var time = new Date().toLocaleTimeString();
        var $log = $('#log');
        var text = $log.text();
        if (text === 'Waiting for actions...') text = '';
        $log.text(text + '[' + time + '] ' + msg + '\n');
    }

    $(function () {
        $('#btn-error').on('click', function () {
            addLog('Calling GET /api/test-error ...');
            $.ajax({
                url: '/api/test-error',
                method: 'GET',
                complete: function (jqXHR) {
                    var traceId = jqXHR.getResponseHeader('traceway-trace-id');
                    addLog('Response: ' + jqXHR.status + ' \u2014 traceway-trace-id: ' + (traceId || 'not present'));
                    if (jqXHR.status >= 400) {
                        addLog('Exception auto-captured by @tracewayapp/jquery with distributedTraceId=' + traceId);
                    }
                }
            });
        });

        $('#btn-success').on('click', function () {
            addLog('Calling GET /api/test-success ...');
            $.ajax({
                url: '/api/test-success',
                method: 'GET',
                complete: function (jqXHR) {
                    var traceId = jqXHR.getResponseHeader('traceway-trace-id');
                    addLog('Response: ' + jqXHR.status + ' \u2014 traceway-trace-id: ' + (traceId || 'not present'));
                }
            });
        });

        $('#btn-clear').on('click', function () {
            $('#log').text('Waiting for actions...');
        });
    });
    </script>
</body>
</html>