Skip to content

Commit 1473c6a

Browse files
feat/scrapping browser data while catching incident
1 parent 56bd073 commit 1473c6a

15 files changed

Lines changed: 130 additions & 65 deletions

File tree

packages/browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"test:watch": "jest --watch --notify"
2424
},
2525
"dependencies": {
26-
"stacktrace-parser-node": "1.1.4"
26+
"bowser": "2.11.0"
2727
},
2828
"publishConfig": {
2929
"access": "public"

packages/browser/src/client.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IBrowserClient, TraceoOptions } from "./types/client";
22
import { Transport } from "./transport";
3+
import { utils } from "./utils";
34

45
export abstract class BrowserClient implements IBrowserClient {
56
public headers!: { [key: string]: any };
@@ -16,18 +17,16 @@ export abstract class BrowserClient implements IBrowserClient {
1617
public abstract postInitSDK(): void;
1718

1819
public sendError(error: Error): void {
19-
const event = {
20+
const browser = utils.browserDetails();
21+
this.transport.send({
2022
type: error.name,
2123
message: error.message,
22-
traces: [],
23-
stack: error.stack,
24-
platform: {}
25-
};
26-
this.transport.send(event, this.headers);
24+
stack: error.stack as string,
25+
browser
26+
}, this.headers);
2727
}
2828

2929
private initSDK(): void {
30-
// TODO: we need to make something here?
3130
this.postInitSDK();
3231
}
3332
}

packages/browser/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
export { BrowserClient } from "./client";
2-
export type { Dictionary, IBrowserClient, TraceoOptions, TraceoError } from "./types/client";
2+
export type {
3+
Dictionary,
4+
IBrowserClient,
5+
TraceoOptions,
6+
TraceoBrowserError as TraceoError
7+
} from "./types/client";

packages/browser/src/transport/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class Transport {
1515
const options = this.requestOptions(body, headers);
1616
this.transport(options).request();
1717
} catch (error) {
18-
console.log("Error on send data: ", error);
18+
console.log("Error sending data to traceo: ", error);
1919
}
2020
}
2121

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export type BrowserInfoType = {
2+
browser: {
3+
name?: string;
4+
version?: string;
5+
};
6+
os: {
7+
name?: string;
8+
version?: string;
9+
versionName?: string;
10+
};
11+
platform: {
12+
type?: string;
13+
};
14+
engine: {
15+
name?: string;
16+
version?: string;
17+
};
18+
url: string;
19+
};

packages/browser/src/types/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ export interface TraceoOptions {
44
url: string;
55
}
66

7-
export interface TraceoError extends Error {}
7+
export interface TraceoBrowserError extends Error {}
88

99
export interface IBrowserClient {
10-
sendError(error: TraceoError): void;
10+
sendError(error: TraceoBrowserError): void;
1111
}
1212

1313
export type Dictionary<T> = {

packages/browser/src/types/transport.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { BrowserInfoType } from "./browser";
12
import { Dictionary } from "./client";
23

34
export interface ITransport {
@@ -13,3 +14,10 @@ export type RequestOptions = {
1314
host: string;
1415
method: "POST" | "GET" | "PATCH" | "DELETE";
1516
};
17+
18+
export type BrowserIncidentType = {
19+
type: string;
20+
message: string;
21+
stack: string;
22+
browser: BrowserInfoType;
23+
};

packages/browser/src/utils.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Bowser from "bowser";
2+
import { BrowserInfoType } from "./types/browser";
3+
4+
const bowser = Bowser.getParser(window.navigator.userAgent);
5+
6+
const browserDetails = (): BrowserInfoType => {
7+
const browser = bowser.getBrowser();
8+
const engine = bowser.getEngine();
9+
const platform = bowser.getPlatform();
10+
const os = bowser.getOS();
11+
const url = window.location.href;
12+
13+
return {
14+
browser,
15+
engine,
16+
platform,
17+
os,
18+
url
19+
};
20+
};
21+
22+
export const utils = {
23+
browserDetails
24+
};

packages/node/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class Client {
1818

1919
this.options = options;
2020
this.headers = {
21-
"x-sdk-name": "Node.js",
21+
"x-sdk-name": "node",
2222
"x-sdk-version": TRACEO_SDK_VERSION,
2323
"x-sdk-key": this.options.apiKey
2424
};

packages/node/src/exceptions/handler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { stacktrace } from "stacktrace-parser-node";
22
import { HttpModule } from "../core/http";
33
import { isClientConnected } from "../core/is";
4-
import { TraceoError, Incident } from "../types";
4+
import { TraceoError, NodeIncidentType } from "../types";
55
import { getOsDetails } from "../helpers";
66

77
/**
@@ -27,7 +27,7 @@ export const catchException = async (error: any) => {
2727
};
2828

2929
const handleException = async (error: TraceoError) => {
30-
const event: Incident = await prepareException(error);
30+
const event: NodeIncidentType = await prepareException(error);
3131
const httpModule = HttpModule.getInstance();
3232
httpModule.request({
3333
url: "/api/worker/incident",
@@ -41,12 +41,12 @@ const handleException = async (error: TraceoError) => {
4141
});
4242
};
4343

44-
const prepareException = async (error: TraceoError): Promise<Incident> => {
44+
const prepareException = async (error: TraceoError): Promise<NodeIncidentType> => {
4545
const { stack } = error;
4646
const platform = getOsDetails();
4747

4848
const { message, name, traces } = await stacktrace.parse(error);
49-
const event: Incident = {
49+
const event: NodeIncidentType = {
5050
type: name,
5151
message,
5252
traces,

0 commit comments

Comments
 (0)