Gathering detailed insights and metrics for @traceo-sdk/node
Gathering detailed insights and metrics for @traceo-sdk/node
Gathering detailed insights and metrics for @traceo-sdk/node
Gathering detailed insights and metrics for @traceo-sdk/node
npm install @traceo-sdk/node
Typescript
Module System
Min. Node Version
Node Version
NPM Version
71.9
Supply Chain
96.8
Quality
75.5
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
2,286
Last Day
1
Last Week
5
Last Month
29
Last Year
1,279
MIT License
10 Stars
137 Commits
1 Forks
2 Watchers
6 Branches
2 Contributors
Updated on Jun 04, 2024
Minified
Minified + Gzipped
Latest Version
0.34.1
Package Id
@traceo-sdk/node@0.34.1
Unpacked Size
58.20 kB
Size
17.82 kB
File Count
23
NPM Version
9.3.1
Node Version
18.14.0
Published on
Aug 17, 2023
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-16.7%
5
Compared to previous week
Last Month
-17.1%
29
Compared to previous month
Last Year
31.9%
1,279
Compared to previous year
3
1
Library for integration with the Traceo Platform.
To install this SDK add this package to your package.json like below:
yarn add @traceo-sdk/node
or
npm install @traceo-sdk/node
First what you need is to initialize TraceoClient
in your application.
1import { TraceoClient } from "@traceo-sdk/node";
2
3new TraceoClient(<project_api_key>, {
4 host: <traceo_host>
5});
TraceoClient
constructor required two attribtues. First one in api key which you can generate in project settings. Second is an object contains required attribute host
which specifies the address where your Traceo Platform instance is located. Address should be passed in the format <protocol>://<domain>:<port>
, eq. http://localhost:3000
.
Incidents are all the exceptions and other problems that occur in your application. After each exception occurs, the Traceo SDK catches the exception and sends it to the Traceo Platform. This package provide the two main ways to catch exceptions in your application - Handlers
and Middlewares
.
The easiest way is to use ExceptionsHandlers.catchException()
in try-catch
clause like below:
1import { ExceptionHandlers } from "@traceo-sdk/node"; 2 3try { 4 //your code 5} catch (error) { 6 ExceptionHandlers.catchException(error); 7}
If you use NestJS framework then you can also create Interceptor to catch exceptions like below:
traceo.interceptor.ts
1import { ExceptionHandlers } from "@traceo-sdk/node"; 2//other imports 3 4@Injectable() 5export class TraceoInterceptor implements NestInterceptor { 6 intercept(context: ExecutionContext, next: CallHandler): Observable<any> { 7 return next.handle().pipe( 8 tap(null, (exception) => { 9 ExceptionHandlers.catchException(exception); 10 }), 11 ); 12 } 13}
main.ts
1 app.useGlobalInterceptors(new TraceoInterceptor());
Another approach is to use ExceptionMiddlewares.errorMiddleware()
. If you use the Express.js framework, you can use our middleware like below:
Javascript:
1import { ExceptionMiddlewares } from "@traceo-sdk/node"; 2 3app.use(ExceptionMiddlewares.errorMiddleware());
Typescript:
1const { ExceptionMiddlewares } from "@traceo-sdk/node"; 2 3app.use(ExceptionMiddlewares.errorMiddleware() as express.ErrorRequestHandler);
Remember that ExceptionMiddlwares.errorMiddleware()
should be before any other error middlewares and after all routes/controllers.
Parameter | Description | Default |
---|---|---|
allowLocalhost | If false then middleware doesn't catch exceptions from requests coming from localhost | true |
allowHttp | If false then middleware doesn't catch exceptions received from requests where req.protocol = http and catch only exception received with https | true |
The Traceo SDK can be used also as a logger. Each log is saved on the Traceo Platform, thanks to which it is possible to later easily access the recorded information. Logs are sent to Traceo in every 60 seconds. To change this behavior, set a custom value (measured in seconds) in the scrapLogsInterval
field inside traceo client properties like below:
1import { TraceoClient } from "@traceo-sdk/node";
2
3new TraceoClient(<project_api_key>, {
4 host: <traceo_host>,
5 scrapLogsInterval: 120 //in seconds
6});
Example of using logger:
1import { Logger } from "@traceo-sdk/node"; 2 3const traceo = new TraceoClient({...}); 4 5traceo.logger.log("Traceo");
The logger
can use 5 different types of log: log
, info
, debug
, warn
, error
. Each function responsible for logging the appropriate log type accepts a list of arguments in the parameter.
1traceo.logger.log("Traceo", "Example", "Log"); 2// [TraceoLogger][LOG] - 31.10.2022, 13:55:45 - Traceo Example Log 3 4traceo.logger.debug("Traceo", { 5 hello: "World" 6}); 7// [TraceoLogger][DEBUG] - 31.10.2022, 13:58:00 - Traceo { hello: 'World' }
To activate the collection of metrics from your application, set the parameter collectMetrics
in your TraceoClient
to true:
1new TraceoClient({ collectMetrics: true });
Metrics are collected from the application every 30 seconds. If you want to collect metrics at a different time interval then you can use the scrapMetricsInterval
parameter.
1new TraceoClient({ scrapMetricsInterval: <interval_in_seconds> });
Remember that provided scrapMetricsInterval
can't be less than 15
seconds.
Feel free to create Issues, Pull Request and Discussion. If you want to contact with the developer working on this package click here.
No vulnerabilities found.
No security vulnerabilities found.