rn-debug-trail
v1.9.11
Published
Log monitoring SDK for debug trail.
Readme
SDK for react native debug trail log monitoring
Installation
yarn add rn-debug-trailInstall dependencies
yarn add @react-native-async-storage/async-storage axios react-native-device-info react-native-uuidUsage
import RNDebugTrail from "rn-debug-trail";To use the same code both on Android and iOS use init() to initialize debug trail.
RNDebugTrail.init({
uri: "<Websocket_url>",
api_key: "<API KEY>",
});Parameters
| Parameter | Description |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| uri | WebSocket URL used for connecting to the Debug Trail server. |
| api_key | Secret key generated from the Debug Trail portal. This key is used to authenticate your device with the server. |
| secret_words | Array of strings that denote sensitive data contained in logs. If any of the specified words are found in the log, that log entry will be prevented from being sent. |
| setexception | A boolean flag that determines whether device exception handling is required. It is recommended to set this to false in development and true in production for robust error handling. |
| api_monitoring | (optional, boolean) Indicates whether API monitoring is required. Set to true to enable monitoring of API interactions. |
| app_state_monitoring | (optional, boolean) Indicates whether monitoring of the application state data is necessary. Set to true to track and log application state changes. |
| log_monitoring | (optional, boolean) Indicates whether console log monitoring is required. It monitors the use of console.log() in your application. |
Exported Functions
init
Description: Initializes the DebugTrail logging and monitoring process.
DebugTrail.init({
uri: "<Websocket_url>",
api_key: "<API KEY>",
secret_words: ["password", "token"],
setexception: true,
api_monitoring: true,
app_state_monitoring: true,
log_monitoring: true,
});- Parameters:
InitParams - Returns:
Promise<void>
sendLog
Description: Sends logs through WebSocket to the DebugTrail server.
DebugTrail.sendLog({ message: "Log message", level: "info" });- Parameters:
DebugTrailLog(e.g.,{ message: string, level: string }) - Returns:
void
closeConnection
Description: Closes the WebSocket connection to the DebugTrail server.
DebugTrail.closeConnection();- Parameters: None
- Returns:
void
storeLogs
Description: Stores logs in the browser's localStorage under the key "logs".
DebugTrail.storeLogs();- Parameters: None
- Returns:
void
hibernate
Description: Suspends the log sending process. Logs will be held in the log_stack and not sent until activate is called.
DebugTrail.hibernate();- Parameters: None
- Returns:
void
activate
Description: Resumes the log sending process and sends any pending logs stored in log_stack.
DebugTrail.activate();- Parameters: None
- Returns:
void
setUser
Description: Sets the user for the logs. All subsequent logs will include this user data.
DebugTrail.setUser("john_doe");- Parameters:
name: string(The name of the user) - Returns:
void
setTenant
Description: Sets the tenant name for the logs. All subsequent logs will include this tenant data.
DebugTrail.setTenant("tenant_123");- Parameters:
name: string(The name of the tenant) - Returns:
void
setJSExceptionHandler
Description: Sets a custom JavaScript exception handler for logging errors.
DebugTrail.setJSExceptionHandler((error, isFatal) => {
console.error(error, isFatal);
});- Parameters:
customHandler: (error: Error, isFatal: boolean) => void(The custom error handler)allowedInDevMode: boolean(Optional flag to allow in development mode)
- Returns:
void
Additional Notes
- WebSocket Management: All log data is sent via a WebSocket connection to the specified
uri. The connection is automatically managed, and logs are sent when the WebSocket is open. - Exception Handling: You can configure custom handlers for JavaScript exceptions using
setJSExceptionHandler. In production, this ensures that errors are logged automatically. - Log Monitoring: Log data is captured in real-time via
console.log(). If enabled (log_monitoring: true), console logs are sent automatically. - API & App State Monitoring: Enable monitoring for API interactions and app state changes by setting
api_monitoringandapp_state_monitoringtotrue.
