UNPKG

hytopia

Version:

The HYTOPIA SDK makes it easy for developers to create massively multiplayer games using JavaScript or TypeScript.

130 lines (68 loc) 2.46 kB
<!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [server](./server.md) &gt; [Telemetry](./server.telemetry.md) ## Telemetry class Manages performance telemetry and error tracking through your Sentry account. When to use: profiling and diagnosing slow ticks or runtime errors in production. Do NOT use for: high-volume custom metrics; use a dedicated metrics pipeline instead. **Signature:** ```typescript export default class Telemetry ``` ## Remarks Provides low-overhead performance monitoring and error tracking via Sentry. The system only sends telemetry data when errors or slow-tick performance issues are detected. Pattern: initialize once at server startup and wrap critical sections with `Telemetry.startSpan`<!-- -->. Anti-pattern: creating spans inside tight loops without filtering. ## Example ```typescript // Initialize Sentry for production telemetry Telemetry.initializeSentry('MY_SENTRY_PROJECT_DSN'); // Wrap performance-critical code in spans Telemetry.startSpan({ operation: TelemetrySpanOperation.CUSTOM_OPERATION, attributes: { playerCount: world.playerManager.connectedPlayers.length, entityCount: world.entityManager.entityCount, }, }, () => { performExpensiveOperation(); }); // Get current process statistics const stats = Telemetry.getProcessStats(); console.log(`Heap usage: ${stats.jsHeapUsagePercent * 100}%`); ``` \*\*Category:\*\* Telemetry ## Methods <table><thead><tr><th> Method </th><th> Modifiers </th><th> Description </th></tr></thead> <tbody><tr><td> [getProcessStats(asMeasurement)](./server.telemetry.getprocessstats.md) </td><td> `static` </td><td> Gets current process memory and performance statistics. </td></tr> <tr><td> [initializeSentry(sentryDsn, tickTimeMsThreshold)](./server.telemetry.initializesentry.md) </td><td> `static` </td><td> Initializes Sentry telemetry with the provided DSN. </td></tr> <tr><td> [sentry()](./server.telemetry.sentry.md) </td><td> `static` </td><td> Gets the Sentry SDK instance for advanced telemetry operations. </td></tr> <tr><td> [startSpan(options, callback)](./server.telemetry.startspan.md) </td><td> `static` </td><td> Executes a callback function within a performance monitoring span. </td></tr> </tbody></table>