deltatrack
v0.1.3
Published
Lightweight JS error monitoring SDK
Downloads
175
Readme
delatrack
Lightweight JavaScript monitoring SDK for capturing errors, performance metrics, and network events in the browser.
## Features
- Automatic uncaught error and unhandled rejection capturing (via `init`).
- Manual error reporting via `captureError`.
- Small helper modules to capture network calls and performance metrics (see `src/network.js` and `src/performance.js`).
- Sends events to a backend ingest endpoint (`src/config.js`).
## Quick start- Install the package (example name from package.json):
npm install deltatrack
# or
yarn add deltatrack- Initialize the SDK in your app (example using ESM imports / bundler):
import { init, captureError } from 'deltatrack';
// Call once during app startup
init({ projectKey: 'YOUR_PROJECT_KEY' });
// Manually capture an error
try {
// some code that throws
} catch (err) {
captureError(err);
}If you use the built UMD bundle (dist/index.umd.js) you can also include the script directly and access the SDK from the global export (after you build/publish the package).
Public API
init({ projectKey })- projectKey: string (required) — sets the project API key used when sending events.
- Calls
initErrorTracking()which attacheswindow.onerrorandwindow.onunhandledrejectionhandlers.
captureError(error)- error:
Error— sends a manual error event to the ingest endpoint.
- error:
Notes:
- The library's entry file (
src/index.js) currently exports onlyinitandcaptureError. The helper modules for network and performance capture live insrc/network.jsandsrc/performance.js. You can import those directly from source during development or wire them into your bundler output if you want to enable automatic network/perf capture.
Example using the helper modules directly (when available in your bundle):
import { captureNetworkEvents } from 'deltatrack/src/network';
captureNetworkEvents( 'my-project-id');Development
- Install dev dependencies:
npm install- Build the library (the repo uses Rollup):
npm run build- The build outputs are configured in
package.json(dist/index.cjs.js,dist/index.esm.js,dist/index.umd.js).
Troubleshooting
Events not appearing in your backend?
- Ensure
INGEST_URLinsrc/config.jspoints to your ingest endpoint. - Confirm your backend is accepting POST requests with
Content-Type: application/jsonand thex-project-keyheader. - If
projectKeyis not set viainit, events will be dropped (the SDK logs a warning in that case).
- Ensure
Network/performance helpers not working?
- Those helpers rely on
windowglobals and must run in a browser environment. - Ensure your bundler includes those modules in the final bundle or import them directly from source during app initialization.
- Those helpers rely on
-## Next steps / suggestions
JavaScript usage
If you're using plain JavaScript, import just the functions you need from the package (for example,
initandcaptureError). If you want to enable the network and performance helpers, consider exportingcaptureNetworkEventsfrom the main entry file so they're easier to discover and import.TypeScript usage
To get proper typing when using TypeScript, add a declaration file named
deltatrack.d.tsto your project (or include types in the package). Here's a minimal, ready-to-use example you can copy and adapt to match your exported API:declare module 'deltatrack' { export interface InitOptions { // API key for your project (required) projectKey: string; // Optional: override the default ingest URL at runtime ingestUrl?: string; } export function init(options: InitOptions): void; export function getProjectKey(): string | null; export function captureError(error: Error | string, context?: Record<string, any>): void; // Helpers for network and performance capture. Signatures include // optional parameters so they match the helper modules in `src/`. export function captureNetworkEvents(backendUrl?: string, projectId?: string): void; }Note: adjust these declarations to exactly match the symbols you actually export from your package. If you don't expose
getProjectKeyfrom the public API, remove it from the declaration or add it tosrc/index.js.Recommended improvements
Consider exposing
captureNetworkEventsfrom the main entry (src/index.js) if you want them to be part of the documented public API.Make the ingest URL configurable at runtime (e.g., accept an
ingestUrloption ininit) instead of hard-coding it insrc/config.js.
License
MIT
