Skip to content

Commit cf7c798

Browse files
Merge pull request #5 from traceo-dev/develop
0.31.9
2 parents cac25df + 5403571 commit cf7c798

Some content is hidden

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

47 files changed

+806
-222
lines changed
File renamed without changes.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ lerna-debug.log
3232
#firebase
3333
ui-debug.log
3434

35-
.vscode
3635
.idea
3736

3837
#tarballs

.prettierrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"trailingComma": "none",
3+
"tabWidth": 2,
4+
"printWidth": 98,
5+
"semi": true,
6+
"quoteProps": "as-needed",
7+
"bracketSpacing": true,
8+
"arrowParens": "always",
9+
"endOfLine": "lf",
10+
"singleQuote": false
11+
}

.vscode/.gitkeep

Whitespace-only changes.

README.md

Lines changed: 8 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,15 @@
1-
# Traceo SDK for Node.js
2-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
1+
# Traceo SDKs for JavaScript
32

4-
Library for integration with the [Traceo Platform](https://github.com/traceo-dev/traceo).
3+
A set of SDKS for integration with the [Traceo Platform](https://github.com/traceo-dev/traceo).
54

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-
```
5+
# Platforms
6+
This repository contains all the SDKs needed for integration in Javascript/Typescript projects. Detailed instructions for the SDK implementation process can be found in the individual README for each SDK.
157

16-
### Usage
17-
First what you need is to initialize `TraceoClient` in your application.
18-
```ts
19-
import { TraceoClient } from "@traceo-sdk/node";
8+
- [`@traceo-sdk/node`](https://github.com/traceo-dev/traceo-sdk/tree/develop/packages/node): SDK for NodeJS.
9+
- [`@traceo-sdk/react`](https://github.com/traceo-dev/traceo-sdk/tree/develop/packages/react): SDK for ReactJS.
2010

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.
11+
# Other
12+
- [`@traceo-sdk/browser`](https://github.com/traceo/traceo-sdk/tree/develop/packages/browser): A package that contains common logic used by all SDKs running in the browser.
13813

13914
## Support
14015
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-

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
3+
"version": "0.31.8",
34
"npmClient": "yarn",
4-
"version": "0.31.5",
55
"useWorkspaces": true
66
}

package.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
"name": "traceo-sdk",
44
"private": true,
55
"scripts": {
6+
"bootstrap": "lerna bootstrap",
67
"build": "lerna run build",
7-
"build:tarball": "lerna run build:tarball"
8+
"build:tarball": "lerna run build:tarball",
9+
"lint:prettier": "lerna run lint:prettier"
810
},
911
"workspaces": [
10-
"packages/node"
12+
"packages/node",
13+
"packages/browser",
14+
"packages/react"
1115
],
1216
"devDependencies": {
1317
"@types/node": "10.17.0",
@@ -20,14 +24,20 @@
2024
"@types/jest": "^29.2.0",
2125
"eslint": "^8.8.0",
2226
"jest": "^26.5.5",
23-
"npm-run-all": "^4.1.2",
2427
"os": "^0.1.2",
25-
"prettier": "^2.5.1",
2628
"prettier-check": "^2.0.0",
27-
"rimraf": "^3.0.2",
2829
"rollup": "^2.66.1",
2930
"ts-node": "^10.4.0",
30-
"tslint": "^5.11.0"
31+
"tslint": "^5.11.0",
32+
"@types/react": "^16.9.49",
33+
"@types/react-dom": "^16.9.8",
34+
"lint-staged": "^10.5.3",
35+
"npm-run-all": "^4.1.5",
36+
"prettier": "2.1.2",
37+
"react": "^18.1.0",
38+
"react-dom": "^18.1.0",
39+
"rimraf": "^3.0.2",
40+
"webpack": "^5.11.0"
3141
},
3242
"jest": {
3343
"verbose": false,

packages/browser/.eslintrc.js

Whitespace-only changes.

packages/browser/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Traceo SDK Browser

packages/browser/package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "@traceo-sdk/browser",
3+
"version": "0.31.8",
4+
"main": "dist/index.js",
5+
"types": "dist/index.d.ts",
6+
"license": "MIT",
7+
"files": [
8+
"dist"
9+
],
10+
"homepage": "https://github.com/traceo-dev/traceo-sdk",
11+
"repository": {
12+
"type": "git",
13+
"url": "git://github.com/traceo-dev/traceo-sdk.git"
14+
},
15+
"scripts": {
16+
"build": "tsc -p ./tsconfig.json --outDir dist",
17+
"build:tarball": "yarn build && npm pack",
18+
"prebuild": "rimraf ./dist",
19+
"lint": "run-s lint:prettier",
20+
"lint:prettier": "prettier ./src/**/*.{js,ts,tsx} --write",
21+
"prepack": "yarn lint",
22+
"test": "jest",
23+
"test:watch": "jest --watch --notify"
24+
},
25+
"dependencies": {
26+
"bowser": "2.11.0"
27+
},
28+
"publishConfig": {
29+
"access": "public"
30+
},
31+
"browser": {
32+
"http": false,
33+
"https": false
34+
}
35+
}

0 commit comments

Comments
 (0)