Pages
Contents
API
Trace ID Workflow
@xpulse/httpgenerates atraceIdper request.traceIdis attached toreq.traceIdand emitted inhttp:*events.@xpulse/controllerforwards it into templates as_traceId.@xpulse/templateincludestraceIdin render events.@xpulse/debugaggregates everything per trace and stores it undervar/cache/debug/_<traceId>/.
Web Profiler Config
debug can be a boolean or an object. When debug is true, the profiler is enabled.
You can also configure the web profiler and exclude routes:
| { |
| "debug": { |
| "enabled": true, |
| "web-profiler": { |
| "enabled": true, |
| "excluded-routes": [ |
| "*._debug.*", |
| "*.get._debug.web-profiler.*" |
| ] |
| } |
| } |
| } |
excluded-routes supports * wildcards and matches against the request path,
route name, and a normalized key like get._debug.web-profiler.traceId.dashboard.
Package defaults are defined in @xpulse/debug/xpulse.json and can be overridden
by your app xpulse.json.
Template Method
When debug is enabled, a debug(value) template method is registered (via
@xpulse/template). It renders a safe HTML dump:
| {{ debug(user) }} |
debug:events:list
Lists all registered events and listeners.
debug:config:show
Shows loaded configuration from @xpulse/config.
debug:routes:list
Lists registered routes (when @xpulse/router is installed).
debug:packages:list
Lists installed @xpulse/* packages with versions.
debug:app:bootstrap
Bootstraps the app (or simulates bootstrap) and registers routes.
DataCollector API
Any @xpulse/* package can display its own data in the Web Profiler by implementing a DataCollector and placing it under src/datacollectors/. @xpulse/debug discovers these files automatically β no configuration required.
Setup
| // src/datacollectors/my-collector.js |
| import { DataCollector } from '@xpulse/debug/collector'; |
| export default class MyCollector extends DataCollector { |
| configure() { |
| this.setName('my-package') |
| .setIcon('π§') |
| .setPackage('@xpulse/my-package'); |
| } |
| async collect() { |
| this.on('my:event', (payload) => { |
| this.setBadge('active'); |
| this.addArea({ |
| title: 'Result', |
| rows: [{ label: 'Value', value: payload.value }] |
| }); |
| }); |
| } |
| } |
@xpulse/debug must be listed in optionalDependencies:
| "optionalDependencies": { |
| "@xpulse/debug": "^1.0.11" |
| } |
configure()
Called before collect(). Sets panel metadata.
| Method | Description |
|---|---|
this.setName(name) |
Panel ID and file name (name.json) |
this.setIcon(icon) |
Emoji or icon string for the toolbar |
this.setPackage(pkg) |
Package name shown in the panel |
collect()
Registers event listeners via this.on(). Called once at startup.
| this.on('my:event', (payload, traceId) => { |
| // traceId is the active request ID |
| // payload is the event payload |
| }); |
Listeners are only executed when an active traceId is present (i.e. within the context of an HTTP request). Events outside a request are ignored.
Data methods (inside listeners)
| Method | Description |
|---|---|
this.setBadge(text) |
Badge text in the debug toolbar |
this.addArea(area) |
Add a section to the panel |
this.addSubPanel(panel) |
Add a sub-panel |
this.addSpan(span) |
Add a waterfall span to the central timeline |
this.addTraceEvent(evt) |
Add an event entry to the timeline |
Area format
| this.addArea({ |
| title: 'Section Title', |
| rows: [ |
| { label: 'Key', value: 'Value' }, |
| { label: 'Count', value: 42 }, |
| ] |
| }); |
SubPanel format
| this.addSubPanel({ |
| title: 'Detail Panel', |
| rows: [...] |
| }); |
Panel output
After each http:response event, the collector automatically writes:
| var/cache/debug/_<traceId>/packages/<name>.json |
This file is read by the Web Profiler and displayed as a panel tab.
appInit(options)
| import debug from '@xpulse/debug'; |
| await debug.appInit({ http: true, cli: false, debug: true }); |
Simulates app bootstrap based on installed packages. If @xpulse/app
is installed, app.init(...) is used.