React
The official Streply library for the React framework.
This package is a wrapper around @streply/browser
, with added functionality related to React.
To use this SDK, call init()
as early in your application as possible.
Install
The first step is to install the streply/react
package.
- NPM
- YARN
npm install --save @streply/react
yarn add @streply/react
Then initialize Streply:
import React from 'react';
import ReactDOM from 'react-dom';
import * as Streply from '@streply/react';
Streply.init({
dsn: 'https://clientPublicKey@api.streply.com/projectId',
});
ReactDOM.render(, rootNode);
You can find the DSN code of the project in the Projects tab of your Streply account.
Capture events
Errors
Streply automatically finds all errors in your code, but you can also identify exceptions yourself.
try {
nonExistsFunc("Welcome!");
} catch(err) {
Streply.Exception(err);
}
Also, you can trigger errors in this way:
<button
type="button"
onClick={() => {
throw new Error("This is an error");
}}
>Trigger error</button>
If needed, you can manually send an error to Streply:
Streply.Error('This is an error', {'userId': 1}, Streply.Level.Critical);
Reade more about Capture errors in JS.
Logs
To send a log to Streply, use the Streply.Log
function.
let createUser = function(userName) {
// ...
Streply.Log('users.create', {'userName': userName});
}
createUser('Joey Tribbiani');
Reade more about Capture logs in JS.
Configuration
Configuration should happen as early as possible in your code.
Streply.init({
dsn: 'https://clientPublicKey@api.streply.com/projectId',
environment: 'local'
});
// or
Streply.Config.Environment('local');
Reade more about Streply configuration in Configuration page.