Skip to content

Commit fdb1a45

Browse files
fix/saving timestamp for browser perfs
1 parent c13e3d7 commit fdb1a45

22 files changed

Lines changed: 43 additions & 37 deletions

File tree

packages/browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@traceo-sdk/browser",
3-
"version": "0.32.0",
3+
"version": "0.32.1",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"license": "MIT",

packages/browser/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,6 @@ export abstract class BrowserClient implements IBrowserClient {
167167
}
168168

169169
private get incidentsUrl() {
170-
return `/api/worker/incident/${this.configs.options.appId}`;
170+
return `/api/worker/incident/${this.configs.options.projectId}`;
171171
}
172172
}

packages/browser/src/performance/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { Batch } from "../transport/batch";
22
import { BrowserClientConfigType } from "../types/client";
33
import { BrowserPerformanceType, LargestContentfulPaint, LayoutShift, ObserverType } from "../types/performance";
4+
import { utils } from "../utils";
45

56
export class Performance {
67
private batch: Batch;
78

89
constructor(configs: BrowserClientConfigType) {
910
this.batch = new Batch(configs, {
1011
headers: configs?.headers,
11-
url: `/api/worker/browser/perf/${configs?.options?.appId}`
12+
url: `/api/worker/browser/perf/${configs?.options?.projectId}`
1213
});
1314
}
1415

@@ -24,6 +25,7 @@ export class Performance {
2425
// first-paint, first-contentful-paint
2526
private handlePaintEntry() {
2627
const handle = (entries: PerformancePaintTiming[]): void => {
28+
// const now = dayjs
2729
for (const entry of entries) {
2830
const entryName = entry.name === "first-paint"
2931
? "FP"
@@ -33,6 +35,7 @@ export class Performance {
3335

3436
const payload: BrowserPerformanceType = {
3537
event: entry.entryType,
38+
timestamp: utils.currentUnix(),
3639
performance: [{
3740
name: entryName,
3841
unit: "miliseconds",
@@ -58,6 +61,7 @@ export class Performance {
5861
const entry = entries[entries.length - 1];
5962
const payload: BrowserPerformanceType = {
6063
event: entry.entryType,
64+
timestamp: utils.currentUnix(),
6165
performance: [{
6266
value: entry.startTime,
6367
unit: 'millisecond',
@@ -81,6 +85,7 @@ export class Performance {
8185

8286
const payload: BrowserPerformanceType = {
8387
event: entry.entryType,
88+
timestamp: utils.currentUnix(),
8489
performance: [{
8590
name: "CLS",
8691
unit: " ",
@@ -101,6 +106,7 @@ export class Performance {
101106
for (const entry of entries) {
102107
const payload: BrowserPerformanceType = {
103108
event: entry.entryType,
109+
timestamp: utils.currentUnix(),
104110
performance: [{
105111
name: "FID",
106112
unit: "miliseconds",
@@ -119,6 +125,7 @@ export class Performance {
119125
for (const entry of entries) {
120126
const payload: BrowserPerformanceType = {
121127
event: entry.entryType,
128+
timestamp: utils.currentUnix(),
122129
performance: [
123130
{
124131
name: "domCompleted",

packages/browser/src/types/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export type BrowserClientConfigType = {
55

66
export interface TraceoOptions {
77
apiKey: string;
8-
appId: string;
8+
projectId: string;
99
url: string;
1010
offline?: boolean;
1111
performance?: boolean;

packages/browser/src/types/performance.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type MeasureType = {
1515

1616
export type BrowserPerformanceType = {
1717
event: string;
18+
timestamp: number;
1819
performance: MeasureType[];
1920
}
2021

packages/browser/src/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ const getGlobalConfigs = (): BrowserClientConfigType => {
3636
headers: undefined,
3737
options: undefined
3838
}
39+
};
40+
41+
const currentUnix = (): number => {
42+
return Math.floor(Date.now() / 1000);
3943
}
4044

4145
export const utils = {
4246
browserDetails,
4347
getGlobalConfigs,
44-
toBytes
48+
toBytes,
49+
currentUnix
4550
};

packages/node/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ First what you need is to initialize `TraceoClient` in your application.
1818
import { TraceoClient } from "@traceo-sdk/node";
1919

2020
new TraceoClient({
21-
appId: <your_application_id>,
21+
projectId: <your_project_id>,
2222
url: <you_traceo_instance_url>
2323
});
2424
```
2525

26-
`TraceoClient` options require two 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. `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`.
26+
`TraceoClient` options require two parameters. `projectId` 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. `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`.
2727

2828
### Incidents handling
2929
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`.

packages/node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@traceo-sdk/node",
3-
"version": "0.31.9",
3+
"version": "0.32.1",
44
"author": "Traceo",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/node/src/core/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class HttpModule {
6464
port: reqUrl.port,
6565
host: reqUrl.hostname,
6666
method,
67-
path: `${path.pathname}/${Client.config.appId}`
67+
path: `${path.pathname}/${Client.config.projectId}`
6868
};
6969
}
7070

packages/node/src/exceptions/handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const prepareException = async (error: TraceoError): Promise<NodeIncidentType> =
4747

4848
const { message, name, traces } = await stacktrace.parse(error);
4949
const event: NodeIncidentType = {
50-
type: name,
50+
name,
5151
message,
5252
traces,
5353
stack,

0 commit comments

Comments
 (0)