errorlens-sdk
v0.0.111
Published
## Overview ErrorLens SDK is a JavaScript library designed to capture and report errors in your web applications. It's built to be used with our error monitoring service, offering both free and subscription-based options. We also provide a basic open-sour
Downloads
302
Readme
ErrorLens SDK
Overview
ErrorLens SDK is a JavaScript library designed to capture and report errors in your web applications. It's built to be used with our error monitoring service, offering both free and subscription-based options. We also provide a basic open-source backend that can be self-hosted, while paid subscriptions unlock additional features and support.
Installation
To install the ErrorLens SDK, use npm:
npm install errorlens-sdk
Usage
Initialization
To initialize the ErrorLens SDK in your project, use the following code:
const ErrorLens = require('./src/index')({
sdk: "<YOUR_SDK_KEY>",
host: "<TEAM_NAME>.teams.errorlens.com",
});
ErrorLens.addContext({
appName: 'My Browser App',
version: '1.0.0',
environment: 'production',
});
ErrorLens.init();
ErrorLens.wrapConsole();
Capturing Errors
To capture errors manually, use the captureError
function:
ErrorLens.captureError(new Error('This is a test error'));
Building the Project
To build the project, use the following npm script:
npm run build
This will bundle your source files into dist/error-lens.bundle.js
.
Example
Here is an example of how to use the ErrorLens SDK in a web project:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ErrorLens Demo</title>
</head>
<body>
<button onclick="throwError()">Click me</button>
<script src="dist/error-lens.bundle.js"></script>
<script>
// Initialize ErrorLens with your SDK key and team name
const errorLens = ErrorLens({
sdk: "<YOUR_SDK_KEY>",
host: "<TEAM_NAME>.teams.errorlens.com"
});
// Add context information - in the future, this will be set on the dashboard for each project sdk-key.
errorLens.addContext({
appName: 'My Browser App',
version: '1.0.0',
environment: 'production'
});
// Initialize ErrorLens
errorLens.init();
// Wrap console functions to capture errors
errorLens.wrapConsole();
// This error will be reported to the ErrorLens dashboard
function throwError() {
throw new Error("Button click error");
}
</script>
</body>
</html>
Example of how to use the ErrorLens SDK in a Node.js project:
const ErrorLens = require('./src/index')({
sdk: "<YOUR_SDK_KEY>",
host: "<TEAM_NAME>.teams.errorlens.com"
});
ErrorLens.addContext({
appName: 'My Browser App',
version: '1.0.0',
environment: 'production',
});
ErrorLens.init();
ErrorLens.wrapConsole();
throw new Error("This is a test error");
Contributing
We welcome contributions to the ErrorLens SDK. To contribute, please follow these steps:
- Fork the repository
- Create a new branch
- Make your changes
- Test your changes
- Submit a pull request
- Wait for approval
- Merge your changes
- Celebrate!
Support
COMMUNITY-SUPPORT (AT) ERRORLENS (DOT) COM
is a dedicated email address for community support. Please feel free to reach out with any questions or concerns. Alternatively, you can open an issue on GitHub.
License
This project is licensed under the MIT License.