Skip to content

Commit e83494a

Browse files
fix
1 parent daae94f commit e83494a

4 files changed

Lines changed: 31 additions & 24 deletions

File tree

packages/node-core/src/client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ export abstract class CoreClient implements INodeClient {
55
public options: TraceoOptions;
66
public headers: { [key: string]: any; };
77

8-
constructor(apiKey: string, options: Omit<TraceoOptions, "apiKey">) {
8+
constructor(apiKey: string, { collectMetrics = true, offline = false, ...opts }: Omit<TraceoOptions, "apiKey">) {
99
this.configGlobalClient();
1010

1111
this.options = {
12-
...options,
12+
...opts,
13+
collectMetrics,
14+
offline,
1315
apiKey
1416
};
1517

packages/node-core/src/types/options.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
/**
2-
* Interface with data provided by client
2+
* Interface with data provided by client.
33
*/
44
export interface TraceoOptions {
55
apiKey: string;
6+
7+
/**
8+
* In offline mode no data is collected by the SDK.
9+
*/
10+
611
offline?: boolean;
12+
13+
/**
14+
* Host address to your Traceo Platform.
15+
*/
716
host: string;
17+
818
/*
9-
Determining if Traceo should collect metrics from the application.
10-
*/
19+
* Determining if Traceo should collect metrics from the application.
20+
* Default set to true.
21+
*/
1122
collectMetrics?: boolean;
23+
1224
/*
13-
The number of seconds that the metrics are downloaded.
14-
The minimum value for this field is 15. If the value is set below this value,
15-
then the data will be downloaded just for this time.
16-
*/
17-
scrapMetricsInterval?: number;
18-
/*
19-
Default is 60s.
20-
Value can't be smaller than 15.
21-
*/
22-
scrapLogsInterval?: number;
25+
* The number of miliseconds to scrap metrics and logs.
26+
*/
27+
exportIntervalMillis?: number;
2328
}
2429

2530
export interface ErrorMiddlewareOptions {

packages/node/src/logger.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ import { format } from "util";
22
import { CAPTURE_ENDPOINT, LogLevel, transport } from "@traceo-sdk/node-core";
33
import { getGlobalTraceo } from "@traceo-sdk/node-core/dist/utils";
44

5+
const DEFAULT_EXPORT_INTERVAL = 15000;
56
export class Logger {
67
private logsQueue = [];
7-
private INTERVAL = 60;
8+
private INTERVAL = DEFAULT_EXPORT_INTERVAL;
89

910
constructor() {
1011
this.logsQueue = [];
1112

1213
const client = getGlobalTraceo();
1314

14-
const scrapLogsInterval = client.options.scrapLogsInterval;
15-
if (scrapLogsInterval && scrapLogsInterval >= 15) {
15+
const scrapLogsInterval = client.options.exportIntervalMillis;
16+
if (scrapLogsInterval && scrapLogsInterval >= DEFAULT_EXPORT_INTERVAL) {
1617
this.INTERVAL = scrapLogsInterval;
1718
}
1819

packages/node/src/metrics/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import { Client } from "../client";
21
import { CpuUsageMetrics } from "./default/cpu-usage";
32
import { EventLoopMetrics } from "./default/event-loop";
43
import { HeapMetrics } from "./default/heap";
54
import { MemoryUsageMetrics } from "./default/memory-usage";
6-
import { transport, CAPTURE_ENDPOINT, utils, MetricType, InstrumentType, ValueType } from "@traceo-sdk/node-core";
5+
import { transport, CAPTURE_ENDPOINT, utils, MetricType, InstrumentType, ValueType, INodeClient } from "@traceo-sdk/node-core";
76
import * as os from "os";
87

98
/**
109
* Runner for metrics collecting
1110
*/
1211

13-
const DEFAULT_INTERVAL = 30; //seconds
12+
const DEFAULT_INTERVAL = 15000; //ms -> 15s
1413

1514
export class MetricsRunner {
16-
private client: Client;
15+
private client: INodeClient;
1716

1817
private readonly interval: number;
1918

@@ -28,13 +27,13 @@ export class MetricsRunner {
2827
public clientMeauserementMetrics: Record<string, number[]>;
2928

3029
constructor() {
31-
this.client = global["__TRACEO__"];
30+
this.client = utils.getGlobalTraceo();
3231

3332
if (!this.client.options.collectMetrics) {
3433
return;
3534
}
3635

37-
this.interval = this.client.options.scrapMetricsInterval || DEFAULT_INTERVAL;
36+
this.interval = this.client.options.exportIntervalMillis || DEFAULT_INTERVAL;
3837

3938
this.cpuUsage = new CpuUsageMetrics();
4039
this.eventLoop = new EventLoopMetrics();

0 commit comments

Comments
 (0)