Skip to content

Commit 91d54c8

Browse files
feat/new constructor for sdk clients
1 parent 2c0b783 commit 91d54c8

13 files changed

Lines changed: 50 additions & 37 deletions

File tree

packages/browser/src/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export abstract class BrowserClient implements IBrowserClient {
8787
message,
8888
stack,
8989
traces,
90-
browser: this.browser
90+
details: this.browser
9191
};
9292

9393
return err;
@@ -155,7 +155,7 @@ export abstract class BrowserClient implements IBrowserClient {
155155
message,
156156
stack,
157157
traces,
158-
browser: this.browser
158+
details: this.browser
159159
};
160160

161161
this.sendError(err);
@@ -167,6 +167,6 @@ export abstract class BrowserClient implements IBrowserClient {
167167
}
168168

169169
private get incidentsUrl() {
170-
return `${CAPTURE_ENDPOINT.INCIDENT}/${this.configs.options.projectId}`;
170+
return CAPTURE_ENDPOINT.INCIDENT;
171171
}
172172
}

packages/browser/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export { BrowserClient } from "./client";
22
export type {
33
Dictionary,
44
IBrowserClient,
5-
TraceoOptions,
5+
ClientOptions,
66
TraceoBrowserError as TraceoError
77
} from "./types/client";
88
export { VERSION } from "./version";

packages/browser/src/performance/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class Performance {
1010
constructor(configs: BrowserClientConfigType) {
1111
this.batch = new Batch(configs, {
1212
headers: configs?.headers,
13-
url: `${CAPTURE_ENDPOINT.BROWSER_PERFS}/${configs?.options?.projectId}`
13+
url: CAPTURE_ENDPOINT.BROWSER_PERFS
1414
});
1515
}
1616

@@ -25,9 +25,17 @@ export class Performance {
2525
// overrride to this.batch.add which inlcude some necessary data for each perfs
2626
public addToBatch(payload: BatchPayload): void {
2727
const pathname = utils.pathname();
28+
const { browser, platform } = utils.browserDetails();
2829

2930
const batchPayload: BatchPayload = {
3031
view: pathname,
32+
browser: {
33+
name: browser.name,
34+
version: browser.version
35+
},
36+
platform: {
37+
type: platform?.type
38+
},
3139
...payload
3240
};
3341

packages/browser/src/transport/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ export class Transport {
4646
}
4747

4848
private get clientURL(): URL {
49-
return new URL(this._options.options.url);
49+
return new URL(this._options.options.host);
5050
}
5151
}

packages/browser/src/types/client.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ export type BrowserClientConfigType = {
55

66
export interface TraceoOptions {
77
apiKey: string;
8-
projectId: string;
9-
url: string;
8+
host: string;
109
offline?: boolean;
1110
performance?: boolean;
1211
}
1312

14-
export interface TraceoBrowserError extends Error {}
13+
export interface ClientOptions extends Omit<TraceoOptions, "apiKey"> { };
14+
15+
export interface TraceoBrowserError extends Error { }
1516

1617
export interface IBrowserClient {
1718
handleError(error: TraceoBrowserError): void;

packages/browser/src/types/transport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export type BrowserIncidentType = {
2525
type?: string;
2626
message?: string;
2727
stack?: string;
28-
browser: BrowserInfoType;
28+
details: object;
2929
traces?: Trace[];
3030
};
3131

packages/node/src/client.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Logger } from "./logger";
22
import { Metrics } from "./metrics";
33
import { Scrapper } from "./scrapper";
4-
import { TraceoOptions } from "./types";
4+
import { ClientOptions, TraceoOptions } from "./types";
55
import { TRACEO_SDK_VERSION } from "./version";
66

77
export class Client {
@@ -13,14 +13,18 @@ export class Client {
1313
public readonly logger: Logger;
1414
public options: TraceoOptions;
1515

16-
constructor(options: TraceoOptions) {
16+
constructor(apiKey: string, options: ClientOptions) {
1717
this.configGlobalClient();
1818

19-
this.options = options;
19+
this.options = {
20+
...options,
21+
apiKey
22+
};
23+
2024
this.headers = {
2125
"x-sdk-name": "node",
2226
"x-sdk-version": TRACEO_SDK_VERSION,
23-
"x-sdk-key": this.options.apiKey
27+
"x-sdk-key": apiKey
2428
};
2529

2630
this.logger = new Logger();
@@ -57,10 +61,6 @@ export class Client {
5761
}
5862
}
5963

60-
// private metrics(): IClientMetrics {
61-
// return this._metrics;
62-
// }
63-
6464
private configGlobalClient(): void {
6565
global["__TRACEO__"] = this;
6666
}

packages/node/src/core/http.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class HttpModule {
1515
private host: string;
1616

1717
constructor() {
18-
this.host = Client.config.url;
18+
this.host = Client.config.host;
1919
}
2020

2121
public static getInstance() {
@@ -64,7 +64,7 @@ export class HttpModule {
6464
port: reqUrl.port,
6565
host: reqUrl.hostname,
6666
method,
67-
path: `${path.pathname}/${Client.config.projectId}`
67+
path: path.pathname
6868
};
6969
}
7070

packages/node/src/types/base.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export interface TraceoGlobal {
2-
projectId?: number;
32
offline?: boolean;
43
connection?: {
54
host: string;

packages/node/src/types/options.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
export interface TraceoOptions {
22
apiKey: string;
3-
projectId: string;
43
offline?: boolean;
5-
url: string;
4+
host: string;
65
/*
76
Determining if Traceo should collect metrics from the application.
87
*/
@@ -20,6 +19,8 @@ export interface TraceoOptions {
2019
scrapLogsInterval?: number;
2120
}
2221

22+
export interface ClientOptions extends Omit<TraceoOptions, "apiKey"> { }
23+
2324
export interface ErrorMiddlewareOptions {
2425
allowLocalhost?: boolean;
2526
allowHttp?: boolean;

0 commit comments

Comments
 (0)