Skip to content

Commit cac25df

Browse files
Merge pull request #1 from traceo-dev/develop
0.31.7
2 parents baaae7c + 5ef99f5 commit cac25df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1634
-8862
lines changed

.gitignore

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,39 @@
1+
# dependencies
12
node_modules/
2-
3-
build/
43
packages/*/dist/
4+
/.pnp
5+
.pnp.js
6+
7+
# testing
8+
/coverage
9+
10+
# production
11+
/dist
12+
13+
# misc
14+
.DS_Store
15+
*.pem
16+
517

6-
yarn-error.log
18+
19+
# debug
20+
npm-debug.log*
21+
yarn-debug.log*
22+
yarn-error.log*
23+
yarn.lock
24+
package-lock.json
725
npm-debug.log
826
lerna-debug.log
27+
28+
# local env files
29+
.env
30+
.env.*
31+
32+
#firebase
33+
ui-debug.log
34+
35+
.vscode
36+
.idea
37+
38+
#tarballs
39+
*.tgz

.npmignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is written to be a whitelist instead of a blacklist. Start by
2+
# ignoring everything, then add back the files we want to be included in the
3+
# final NPM package.
4+
*
5+
6+
# And these are the files that are allowed.
7+
!/CHANGELOG.md
8+
!/LICENSE
9+
!/README.md
10+
!/VERSION
11+
!/package.json
12+
!/build/**/*

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry = "https://registry.npmjs.com/"

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# CHANGELOG
2+
3+
## 0.0.3-alpha - 2022-03-23
4+
- Split transport file into few small files
5+
- removing try/catch from various functions
6+
- added options in parameters to `catchException` function
7+
- fixes for middleware and process of handling exceptions
8+
- fix for build script
9+
## 0.0.2-alpha - 2022-03-23
10+
- Migration from monorepo in lerna to single monolith
11+
- Bugfixes
12+
- Using rollup.js
13+
- First working version
14+
-
15+
16+
## 0.0.1-alpha - 2022-03-22
17+
- Initial release with base client library

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Piotr Szewczyk
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Traceo SDK for Node.js
2+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3+
4+
Library for integration with the [Traceo Platform](https://github.com/traceo-dev/traceo).
5+
6+
### Installation
7+
To install this SDK add this package to your project like below:
8+
```
9+
yarn add @traceo-sdk/node
10+
```
11+
or
12+
```
13+
npm install @traceo-sdk/node
14+
```
15+
16+
### Usage
17+
First what you need is to initialize `TraceoClient` in your application.
18+
```ts
19+
import { TraceoClient } from "@traceo-sdk/node";
20+
21+
new TraceoClient({
22+
appId: <your_application_id>,
23+
apiKey: <app_api_key>,
24+
url: <you_traceo_instance_url>
25+
});
26+
```
27+
28+
`TraceoClient` require three parameters. `appId` is a unique identifier of an application created on the Traceo platform. Information about application ID you can get from the Traceo Platform in `Settings|Details` tab. In this same place you can get `apiKey`. `url` parameter specifies the address where your Traceo Platform instance is located. Address should be passed in the format `<protocol>://<domain>:<port>`, eq. `http://localhost:3000`.
29+
30+
### Incidents handling
31+
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`.
32+
33+
##### Handlers
34+
The easiest way is to use `ExceptionsHandlers.catchException()` in `try-catch` clause like below:
35+
```ts
36+
import { ExceptionHandlers } from "@traceo-sdk/node";
37+
38+
try {
39+
//your code
40+
} catch (error) {
41+
ExceptionHandlers.catchException(error);
42+
}
43+
```
44+
45+
If you use [NestJS](https://nestjs.com/) framework then you can also create [Interceptor](https://docs.nestjs.com/interceptors) to catch exceptions like below:
46+
47+
traceo.interceptor.ts
48+
```ts
49+
import { ExceptionHandlers } from "@traceo-sdk/node";
50+
//other imports
51+
52+
@Injectable()
53+
export class TraceoInterceptor implements NestInterceptor {
54+
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
55+
return next.handle().pipe(
56+
tap(null, (exception) => {
57+
ExceptionHandlers.catchException(exception);
58+
}),
59+
);
60+
}
61+
}
62+
```
63+
64+
main.ts
65+
```ts
66+
app.useGlobalInterceptors(new TraceoInterceptor());
67+
```
68+
69+
##### Middleware
70+
Another approach is to use `ExceptionMiddlewares.errorMiddleware()`. If you use the [Express.js](https://expressjs.com/) framework, you can use our middl# Traceo SDK for Node.js
71+
72+
Javascript:
73+
```js
74+
import { ExceptionMiddlewares } from "@traceo-sdk/node";
75+
76+
app.use(ExceptionMiddlewares.errorMiddleware());
77+
```
78+
79+
Typescript:
80+
```ts
81+
const { ExceptionMiddlewares } from "@traceo-sdk/node";
82+
83+
app.use(ExceptionMiddlewares.errorMiddleware() as express.ErrorRequestHandler);
84+
```
85+
86+
Remember that `ExceptionMiddlwares.errorMiddleware()` should be before any other error middlewares and after all routes/controllers.
87+
88+
##### Middleware options
89+
90+
91+
| Parameter | Description | Default |
92+
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
93+
| `allowLocalhost` | If false then middleware doesn't catch exceptions from requests coming from `localhost` | true |
94+
| `allowHttp` | If false then middleware doesn't catch exceptions received from requests where `req.protocol = http` and catch only exception received with `https` | true |
95+
96+
### Logger
97+
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:
98+
```ts
99+
import { TraceoClient } from "@traceo-sdk/node";
100+
101+
new TraceoClient({
102+
scrapLogsInterval: 120 //in seconds
103+
});
104+
```
105+
106+
Example of using logger:
107+
```ts
108+
import { Logger } from "@traceo-sdk/node";
109+
110+
const traceo = new TraceoClient({...});
111+
112+
traceo.logger.log("Traceo");
113+
```
114+
115+
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.
116+
```ts
117+
traceo.logger.log("Traceo", "Example", "Log");
118+
// [TraceoLogger][LOG] - 31.10.2022, 13:55:45 - Traceo Example Log
119+
120+
traceo.logger.debug("Traceo", {
121+
hello: "World"
122+
});
123+
// [TraceoLogger][DEBUG] - 31.10.2022, 13:58:00 - Traceo { hello: 'World' }
124+
```
125+
### Metrics
126+
To activate the collection of metrics from your application, set the parameter `collectMetrics` in your `TraceoClient` to true:
127+
128+
```ts
129+
new TraceoClient({ collectMetrics: true });
130+
```
131+
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.
132+
133+
```ts
134+
new TraceoClient({ scrapMetricsInterval: <interval_in_seconds> });
135+
```
136+
137+
Remember that provided `scrapMetricsInterval` can't be less than `15` seconds.
138+
139+
## Support
140+
Feel free to create Issues, Pull Request and Discussion. If you want to contact with the developer working on this package click [here](mailto:piotr.szewczyk.software@gmail.com).
141+
eware like below:
142+

index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

lerna.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
2-
"packages": [
3-
"packages/*"
4-
],
5-
"version": "0.0.1",
6-
"npmClient": "yarn",
7-
"useWorkspaces": true,
8-
"lerna": "4.0.0"
9-
}
2+
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
3+
"npmClient": "yarn",
4+
"version": "0.31.5",
5+
"useWorkspaces": true
6+
}

package.json

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
11
{
2-
"name": "root",
2+
"version": "0.0.0",
3+
"name": "traceo-sdk",
34
"private": true,
4-
"workspaces": [
5-
"packages/node",
6-
"packages/transport"
7-
],
85
"scripts": {
9-
"build": "lerna run build"
6+
"build": "lerna run build",
7+
"build:tarball": "lerna run build:tarball"
108
},
11-
"dependencies": {},
9+
"workspaces": [
10+
"packages/node"
11+
],
1212
"devDependencies": {
13-
"@types/jest": "^27.4.1",
14-
"@types/node": "^17.0.21",
15-
"lerna": "^4.0.0",
16-
"jest": "^27.5.1",
13+
"@types/node": "10.17.0",
14+
"@types/rimraf": "^3.0.2",
15+
"jsdom": "^19.0.0",
16+
"lerna": "6.5.0-alpha.2",
17+
"tslib": "^2.3.1",
18+
"ts-loader": "^9.4.2",
19+
"typescript": "^4.5.5",
20+
"@types/jest": "^29.2.0",
21+
"eslint": "^8.8.0",
22+
"jest": "^26.5.5",
23+
"npm-run-all": "^4.1.2",
24+
"os": "^0.1.2",
1725
"prettier": "^2.5.1",
18-
"ts-jest": "^27.1.3",
19-
"tslint": "^6.1.3",
20-
"typescript": "^4.6.2"
26+
"prettier-check": "^2.0.0",
27+
"rimraf": "^3.0.2",
28+
"rollup": "^2.66.1",
29+
"ts-node": "^10.4.0",
30+
"tslint": "^5.11.0"
31+
},
32+
"jest": {
33+
"verbose": false,
34+
"transform": {
35+
"^.+\\.ts$": "ts-jest"
36+
},
37+
"moduleFileExtensions": [
38+
"js",
39+
"ts"
40+
],
41+
"testMatch": [
42+
"**/*.test.ts"
43+
]
2144
}
22-
}
45+
}

packages/commons/package.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/commons/tsconfig.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/config/tsconfig.json

Lines changed: 0 additions & 26 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)