@foam-ai/node 0.1.0-alpha.2 → 0.1.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node/src/index.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { captureException } from './capture-exception';
|
|
2
2
|
import { init } from './init';
|
|
3
|
-
|
|
3
|
+
import { incrementCounter, recordHistogram, recordGauge } from './metrics';
|
|
4
|
+
export { captureException, init, incrementCounter, recordHistogram, recordGauge };
|
|
4
5
|
export type { FoamNodeInitOptions } from './init';
|
|
5
6
|
declare const foam: {
|
|
6
7
|
captureException: (error: unknown) => void;
|
|
7
8
|
init: (options: import("./init").FoamNodeInitOptions) => void;
|
|
9
|
+
incrementCounter: (name: string, value?: number, attributes?: import("@opentelemetry/api").Attributes) => void;
|
|
10
|
+
recordHistogram: (name: string, value: number, attributes?: import("@opentelemetry/api").Attributes) => void;
|
|
11
|
+
recordGauge: (name: string, value: number, attributes?: import("@opentelemetry/api").Attributes) => void;
|
|
8
12
|
};
|
|
9
13
|
export default foam;
|
package/dist/node/src/index.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.init = exports.captureException = void 0;
|
|
3
|
+
exports.recordGauge = exports.recordHistogram = exports.incrementCounter = exports.init = exports.captureException = void 0;
|
|
4
4
|
const capture_exception_1 = require("./capture-exception");
|
|
5
5
|
Object.defineProperty(exports, "captureException", { enumerable: true, get: function () { return capture_exception_1.captureException; } });
|
|
6
6
|
const init_1 = require("./init");
|
|
7
7
|
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return init_1.init; } });
|
|
8
|
+
const metrics_1 = require("./metrics");
|
|
9
|
+
Object.defineProperty(exports, "incrementCounter", { enumerable: true, get: function () { return metrics_1.incrementCounter; } });
|
|
10
|
+
Object.defineProperty(exports, "recordHistogram", { enumerable: true, get: function () { return metrics_1.recordHistogram; } });
|
|
11
|
+
Object.defineProperty(exports, "recordGauge", { enumerable: true, get: function () { return metrics_1.recordGauge; } });
|
|
8
12
|
const foam = {
|
|
9
13
|
captureException: capture_exception_1.captureException,
|
|
10
14
|
init: init_1.init,
|
|
15
|
+
incrementCounter: metrics_1.incrementCounter,
|
|
16
|
+
recordHistogram: metrics_1.recordHistogram,
|
|
17
|
+
recordGauge: metrics_1.recordGauge,
|
|
11
18
|
};
|
|
12
19
|
exports.default = foam;
|
package/dist/node/src/init.js
CHANGED
|
@@ -190,11 +190,16 @@ function patchConsole() {
|
|
|
190
190
|
const original = console[method].bind(console);
|
|
191
191
|
console[method] = (...args) => {
|
|
192
192
|
original(...args);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
193
|
+
let ctx;
|
|
194
|
+
let traceAttributes;
|
|
195
|
+
try {
|
|
196
|
+
ctx = api_1.context.active();
|
|
197
|
+
const spanContext = api_1.trace.getSpanContext(ctx);
|
|
198
|
+
if (spanContext && (0, api_1.isSpanContextValid)(spanContext)) {
|
|
199
|
+
traceAttributes = { 'trace.id': spanContext.traceId, 'span.id': spanContext.spanId };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch { /* never break the caller's console.log */ }
|
|
198
203
|
logger.emit({
|
|
199
204
|
context: ctx,
|
|
200
205
|
severityNumber,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Attributes } from '@opentelemetry/api';
|
|
2
|
+
/**
|
|
3
|
+
* Increments a counter metric by the given value (default 1).
|
|
4
|
+
*
|
|
5
|
+
* Counters are monotonically increasing — use for things like request counts,
|
|
6
|
+
* items processed, or errors encountered.
|
|
7
|
+
*
|
|
8
|
+
* Safe to call before `init()` — silently no-ops via the OTel noop meter.
|
|
9
|
+
*/
|
|
10
|
+
export declare const incrementCounter: (name: string, value?: number, attributes?: Attributes) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Records a value on a histogram metric.
|
|
13
|
+
*
|
|
14
|
+
* Histograms capture distributions — use for latencies, request sizes,
|
|
15
|
+
* or any measurement where percentiles and averages matter.
|
|
16
|
+
*
|
|
17
|
+
* Safe to call before `init()` — silently no-ops via the OTel noop meter.
|
|
18
|
+
*/
|
|
19
|
+
export declare const recordHistogram: (name: string, value: number, attributes?: Attributes) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Records a point-in-time gauge value.
|
|
22
|
+
*
|
|
23
|
+
* Gauges represent a current measurement that can go up or down — use for
|
|
24
|
+
* things like queue depth, active connections, or memory usage.
|
|
25
|
+
*
|
|
26
|
+
* Safe to call before `init()` — silently no-ops via the OTel noop meter.
|
|
27
|
+
*/
|
|
28
|
+
export declare const recordGauge: (name: string, value: number, attributes?: Attributes) => void;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.recordGauge = exports.recordHistogram = exports.incrementCounter = void 0;
|
|
4
|
+
const api_1 = require("@opentelemetry/api");
|
|
5
|
+
const util_1 = require("../../shared/util");
|
|
6
|
+
const METER_NAME = 'foam';
|
|
7
|
+
const counters = new Map();
|
|
8
|
+
const histograms = new Map();
|
|
9
|
+
const gauges = new Map();
|
|
10
|
+
function getMeter() {
|
|
11
|
+
return api_1.metrics.getMeter(METER_NAME);
|
|
12
|
+
}
|
|
13
|
+
function getOrCreateCounter(name) {
|
|
14
|
+
let counter = counters.get(name);
|
|
15
|
+
if (!counter) {
|
|
16
|
+
counter = getMeter().createCounter(name);
|
|
17
|
+
counters.set(name, counter);
|
|
18
|
+
}
|
|
19
|
+
return counter;
|
|
20
|
+
}
|
|
21
|
+
function getOrCreateHistogram(name) {
|
|
22
|
+
let histogram = histograms.get(name);
|
|
23
|
+
if (!histogram) {
|
|
24
|
+
histogram = getMeter().createHistogram(name);
|
|
25
|
+
histograms.set(name, histogram);
|
|
26
|
+
}
|
|
27
|
+
return histogram;
|
|
28
|
+
}
|
|
29
|
+
function getOrCreateGauge(name) {
|
|
30
|
+
let gauge = gauges.get(name);
|
|
31
|
+
if (!gauge) {
|
|
32
|
+
gauge = getMeter().createGauge(name);
|
|
33
|
+
gauges.set(name, gauge);
|
|
34
|
+
}
|
|
35
|
+
return gauge;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Increments a counter metric by the given value (default 1).
|
|
39
|
+
*
|
|
40
|
+
* Counters are monotonically increasing — use for things like request counts,
|
|
41
|
+
* items processed, or errors encountered.
|
|
42
|
+
*
|
|
43
|
+
* Safe to call before `init()` — silently no-ops via the OTel noop meter.
|
|
44
|
+
*/
|
|
45
|
+
exports.incrementCounter = (0, util_1.safe)((name, value, attributes) => {
|
|
46
|
+
getOrCreateCounter(name).add(value ?? 1, attributes);
|
|
47
|
+
});
|
|
48
|
+
/**
|
|
49
|
+
* Records a value on a histogram metric.
|
|
50
|
+
*
|
|
51
|
+
* Histograms capture distributions — use for latencies, request sizes,
|
|
52
|
+
* or any measurement where percentiles and averages matter.
|
|
53
|
+
*
|
|
54
|
+
* Safe to call before `init()` — silently no-ops via the OTel noop meter.
|
|
55
|
+
*/
|
|
56
|
+
exports.recordHistogram = (0, util_1.safe)((name, value, attributes) => {
|
|
57
|
+
getOrCreateHistogram(name).record(value, attributes);
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Records a point-in-time gauge value.
|
|
61
|
+
*
|
|
62
|
+
* Gauges represent a current measurement that can go up or down — use for
|
|
63
|
+
* things like queue depth, active connections, or memory usage.
|
|
64
|
+
*
|
|
65
|
+
* Safe to call before `init()` — silently no-ops via the OTel noop meter.
|
|
66
|
+
*/
|
|
67
|
+
exports.recordGauge = (0, util_1.safe)((name, value, attributes) => {
|
|
68
|
+
getOrCreateGauge(name).record(value, attributes);
|
|
69
|
+
});
|