jQuery
Quick Start

jQuery Quick Start

Integrate Traceway into your jQuery application with the @tracewayapp/jquery package.

Installation

Via npm

npm install @tracewayapp/jquery
import { init } from "@tracewayapp/jquery";
 
init("your-token@https://cloud.tracewayapp.com/api/report");

Session recording is on by default — the last ~30s of DOM events ship with every captured exception.

Via CDN

No build step needed — add two script tags after jQuery:

<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tracewayapp/jquery@1/dist/traceway-jquery.iife.global.js"></script>
<script>
  TracewayJQuery.init("your-token@https://cloud.tracewayapp.com/api/report");
</script>

What It Does

Once initialized, the SDK automatically:

This automatically:

  • Captures uncaught JavaScript errors and unhandled promise rejections
  • Captures jQuery AJAX errors via $(document).ajaxError()
  • Injects traceway-trace-id headers into same-origin $.ajax() requests
  • Injects traceway-trace-id headers into same-origin fetch() requests

AJAX Error Capture

jQuery AJAX errors are captured automatically. When $.ajax() fails, Traceway records the URL, HTTP method, status code, and error message.

// This error is captured automatically
$.ajax({
  url: "/api/users",
  method: "GET",
  error: function (jqXHR, textStatus, errorThrown) {
    // Your error handling — Traceway also captures this
  },
});

Manual Error Capture

Capture errors explicitly in try/catch blocks:

import { captureException } from "@tracewayapp/jquery";
 
try {
  riskyOperation();
} catch (error) {
  captureException(error);
}

With Options

import { init } from "@tracewayapp/jquery";
 
init("your-token@https://cloud.tracewayapp.com/api/report", {
  debug: true,
  version: "1.0.0",
});

Options Reference

OptionTypeDefaultDescription
debugbooleanfalseLog captured events to the browser console
debounceMsnumber1500Batch delay in milliseconds
retryDelayMsnumber10000Retry delay for failed uploads
versionstringundefinedYour application version
ignoreErrorsArray<string | RegExp>DEFAULT_IGNORE_PATTERNSError patterns to ignore. Pass [] to capture all errors. See Error Filtering
beforeCapture(exception) => booleanundefinedReturn false to suppress an error. See Error Filtering
sessionRecordingbooleantrueEnable the rrweb session recorder
sessionRecordingSegmentDurationnumber30000rrweb segment length in ms
recordAllSessionsbooleanfalseAlways-on session recording. See Sessions
captureLogsbooleantrueMirror console.* calls into the rolling log buffer
captureNetworkbooleantrueRecord fetch / XHR calls as network actions
captureNavigationbooleantrueRecord History API push / replace / pop transitions

Error Filtering

By default, 4xx AJAX errors (e.g., 401, 422), network errors, and timeouts are not captured. This means $.ajax() calls that return 4xx status codes will not appear in your Traceway dashboard unless you opt in.

To capture all AJAX errors including 4xx:

init("your-token@https://cloud.tracewayapp.com/api/report", {
  ignoreErrors: [],
});

The jQuery SDK records HTTP status codes as attributes on captured errors. You can use beforeCapture to selectively filter by status:

init("your-token@https://cloud.tracewayapp.com/api/report", {
  ignoreErrors: [],
  beforeCapture: (exception) => {
    // Only capture 5xx server errors from AJAX
    const status = Number(exception.attributes?.status);
    if (status >= 400 && status < 500) return false;
    return true;
  },
});

Custom Attributes

Attach app-level identifiers (userId, tenant, feature flags, etc.) to every session and exception:

import {
  setAttribute,
  setAttributes,
  removeAttribute,
  clearAttributes,
} from "@tracewayapp/jquery";
 
setAttribute("userId", "u_42");
setAttributes({ tenant: "acme", plan: "pro" });
 
// On logout / tenant switch:
clearAttributes();

Layering on each event: defaults < global scope < per-call. See Sessions for the full attribute model.

Distributed Tracing

The SDK automatically instruments both XMLHttpRequest (used by $.ajax()) and fetch to propagate a traceway-trace-id header on same-origin requests. This links frontend errors to the backend requests that caused them.

With Symfony + OpenTelemetry

If your backend uses the Symfony OpenTelemetry Bundle, distributed tracing works out of the box. The bundle reads the traceway-trace-id header from incoming requests and attaches it as a span attribute, linking your jQuery frontend errors to Symfony backend traces.

// Frontend — trace header is injected automatically
$.post("/api/orders", { item: "widget" });
// Backend — the bundle reads traceway-trace-id automatically
// No extra configuration needed in your Symfony controllers

Test Your Integration

import { captureException } from "@tracewayapp/jquery";
 
$("#test-button").on("click", function () {
  captureException(new Error("Test error from jQuery"));
});

Click the button and check your Traceway dashboard to verify the error appears.

Next Steps