@ogcio/o11y-sdk-node 0.1.0-beta.7 → 0.1.0-beta.8
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/CHANGELOG.md +12 -0
- package/dist/lib/instrumentation.node.js +1 -2
- package/dist/lib/metrics.d.ts +12 -12
- package/dist/lib/metrics.js +6 -10
- package/dist/package.json +7 -7
- package/lib/instrumentation.node.ts +1 -2
- package/lib/metrics.ts +34 -29
- package/package.json +7 -7
- package/test/integration/run.sh +3 -0
- package/test/metrics.test.ts +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.1.0-beta.8](https://github.com/ogcio/o11y/compare/@ogcio/o11y-sdk-node@v0.1.0-beta.7...@ogcio/o11y-sdk-node@v0.1.0-beta.8) (2025-03-07)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* o11y showcase AB[#25895](https://github.com/ogcio/o11y/issues/25895) ([#84](https://github.com/ogcio/o11y/issues/84)) ([f8f10af](https://github.com/ogcio/o11y/commit/f8f10af97d9f5c188e3e65f7d62d5c673edce25a))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* improve getMetric attributes types ([#76](https://github.com/ogcio/o11y/issues/76)) ([243649c](https://github.com/ogcio/o11y/commit/243649c4bfe750687a729fbd836772cce16e0cb1))
|
|
14
|
+
|
|
3
15
|
## [0.1.0-beta.7](https://github.com/ogcio/o11y/compare/@ogcio/o11y-sdk-node@v0.1.0-beta.6...@ogcio/o11y-sdk-node@v0.1.0-beta.7) (2025-02-18)
|
|
4
16
|
|
|
5
17
|
|
package/dist/lib/metrics.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { Counter, Gauge, Histogram, MetricOptions, ObservableCounter, ObservableGauge, ObservableUpDownCounter, UpDownCounter } from "@opentelemetry/api";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
histogram: Histogram
|
|
5
|
-
|
|
6
|
-
updowncounter: UpDownCounter
|
|
7
|
-
"async-counter": ObservableCounter
|
|
8
|
-
"async-updowncounter": ObservableUpDownCounter
|
|
9
|
-
"async-gauge": ObservableGauge
|
|
1
|
+
import { Counter, Gauge, Histogram, MetricOptions, ObservableCounter, ObservableGauge, ObservableUpDownCounter, UpDownCounter, Attributes } from "@opentelemetry/api";
|
|
2
|
+
type MetricTypeMap<TAttributes extends Attributes> = {
|
|
3
|
+
counter: Counter<TAttributes>;
|
|
4
|
+
histogram: Histogram<TAttributes>;
|
|
5
|
+
gauge: Gauge<TAttributes>;
|
|
6
|
+
updowncounter: UpDownCounter<TAttributes>;
|
|
7
|
+
"async-counter": ObservableCounter<TAttributes>;
|
|
8
|
+
"async-updowncounter": ObservableUpDownCounter<TAttributes>;
|
|
9
|
+
"async-gauge": ObservableGauge<TAttributes>;
|
|
10
10
|
};
|
|
11
|
-
type MetricType = keyof
|
|
11
|
+
export type MetricType = keyof MetricTypeMap<Attributes>;
|
|
12
12
|
export interface MetricsParams {
|
|
13
|
+
meterName: string;
|
|
13
14
|
metricName: string;
|
|
14
|
-
attributeName: string;
|
|
15
15
|
options?: MetricOptions;
|
|
16
16
|
}
|
|
17
|
-
export declare function getMetric<T extends MetricType>(type: T, p: MetricsParams):
|
|
17
|
+
export declare function getMetric<T extends MetricType, TAttributes extends Attributes = Attributes>(type: T, p: MetricsParams): MetricTypeMap<TAttributes>[T];
|
|
18
18
|
export {};
|
package/dist/lib/metrics.js
CHANGED
|
@@ -8,21 +8,17 @@ const MetricsFactoryMap = {
|
|
|
8
8
|
"async-updowncounter": (meter) => meter.createObservableUpDownCounter,
|
|
9
9
|
"async-gauge": (meter) => meter.createObservableGauge,
|
|
10
10
|
};
|
|
11
|
-
function getMeter({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
meter = createNoopMeter();
|
|
11
|
+
function getMeter({ meterName }) {
|
|
12
|
+
if (!meterName) {
|
|
13
|
+
console.error("Invalid metric name!");
|
|
14
|
+
return createNoopMeter();
|
|
16
15
|
}
|
|
17
|
-
|
|
18
|
-
meter = metrics.getMeter(`custom_metric.${metricName}`);
|
|
19
|
-
}
|
|
20
|
-
return meter;
|
|
16
|
+
return metrics.getMeter(`custom_metric.${meterName}`);
|
|
21
17
|
}
|
|
22
18
|
export function getMetric(type, p) {
|
|
23
19
|
const meter = getMeter(p);
|
|
24
20
|
if (!MetricsFactoryMap[type]) {
|
|
25
21
|
throw new Error(`Unsupported metric type: ${type}`);
|
|
26
22
|
}
|
|
27
|
-
return MetricsFactoryMap[type](meter).bind(meter)(p.
|
|
23
|
+
return MetricsFactoryMap[type](meter).bind(meter)(p.metricName, p.options);
|
|
28
24
|
}
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ogcio/o11y-sdk-node",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.8",
|
|
4
4
|
"description": "Opentelemetry standard instrumentation SDK for NodeJS based project",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"license": "ISC",
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@opentelemetry/api": "^1.9.0",
|
|
31
|
-
"@opentelemetry/auto-instrumentations-node": "^0.56.
|
|
31
|
+
"@opentelemetry/auto-instrumentations-node": "^0.56.1",
|
|
32
32
|
"@opentelemetry/core": "1.30.1",
|
|
33
33
|
"@opentelemetry/exporter-logs-otlp-grpc": "^0.57.2",
|
|
34
34
|
"@opentelemetry/exporter-logs-otlp-http": "^0.57.2",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"@opentelemetry/sdk-trace-base": "^1.30.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@types/node": "^22.13.
|
|
48
|
-
"@vitest/coverage-v8": "^3.0.
|
|
49
|
-
"tsx": "^4.19.
|
|
50
|
-
"typescript": "^5.
|
|
51
|
-
"vitest": "^3.0.
|
|
47
|
+
"@types/node": "^22.13.9",
|
|
48
|
+
"@vitest/coverage-v8": "^3.0.8",
|
|
49
|
+
"tsx": "^4.19.3",
|
|
50
|
+
"typescript": "^5.8.2",
|
|
51
|
+
"vitest": "^3.0.8"
|
|
52
52
|
}
|
|
53
53
|
}
|
package/lib/metrics.ts
CHANGED
|
@@ -10,26 +10,30 @@ import {
|
|
|
10
10
|
ObservableGauge,
|
|
11
11
|
ObservableUpDownCounter,
|
|
12
12
|
UpDownCounter,
|
|
13
|
+
Attributes,
|
|
13
14
|
} from "@opentelemetry/api";
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"async-
|
|
22
|
-
"async-
|
|
23
|
-
"async-gauge": ObservableGauge;
|
|
16
|
+
type MetricTypeMap<TAttributes extends Attributes> = {
|
|
17
|
+
counter: Counter<TAttributes>;
|
|
18
|
+
histogram: Histogram<TAttributes>;
|
|
19
|
+
gauge: Gauge<TAttributes>;
|
|
20
|
+
updowncounter: UpDownCounter<TAttributes>;
|
|
21
|
+
"async-counter": ObservableCounter<TAttributes>;
|
|
22
|
+
"async-updowncounter": ObservableUpDownCounter<TAttributes>;
|
|
23
|
+
"async-gauge": ObservableGauge<TAttributes>;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
type MetricType = keyof
|
|
26
|
+
export type MetricType = keyof MetricTypeMap<Attributes>;
|
|
27
27
|
|
|
28
|
-
const MetricsFactoryMap:
|
|
29
|
-
|
|
28
|
+
const MetricsFactoryMap: Record<
|
|
29
|
+
MetricType,
|
|
30
|
+
(
|
|
30
31
|
meter: Meter,
|
|
31
|
-
) => (
|
|
32
|
-
|
|
32
|
+
) => (
|
|
33
|
+
name: string,
|
|
34
|
+
options?: MetricOptions,
|
|
35
|
+
) => MetricTypeMap<Attributes>[MetricType]
|
|
36
|
+
> = {
|
|
33
37
|
gauge: (meter: Meter) => meter.createGauge,
|
|
34
38
|
histogram: (meter: Meter) => meter.createHistogram,
|
|
35
39
|
counter: (meter: Meter) => meter.createCounter,
|
|
@@ -37,34 +41,35 @@ const MetricsFactoryMap: {
|
|
|
37
41
|
"async-counter": (meter: Meter) => meter.createObservableCounter,
|
|
38
42
|
"async-updowncounter": (meter: Meter) => meter.createObservableUpDownCounter,
|
|
39
43
|
"async-gauge": (meter: Meter) => meter.createObservableGauge,
|
|
40
|
-
};
|
|
44
|
+
} as const;
|
|
41
45
|
|
|
42
46
|
export interface MetricsParams {
|
|
47
|
+
meterName: string;
|
|
43
48
|
metricName: string;
|
|
44
|
-
attributeName: string;
|
|
45
49
|
options?: MetricOptions;
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
function getMeter({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
meter = createNoopMeter();
|
|
53
|
-
} else {
|
|
54
|
-
meter = metrics.getMeter(`custom_metric.${metricName}`);
|
|
52
|
+
function getMeter({ meterName }: MetricsParams) {
|
|
53
|
+
if (!meterName) {
|
|
54
|
+
console.error("Invalid metric name!");
|
|
55
|
+
return createNoopMeter();
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
+
|
|
58
|
+
return metrics.getMeter(`custom_metric.${meterName}`);
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
export function getMetric<
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
export function getMetric<
|
|
62
|
+
T extends MetricType,
|
|
63
|
+
TAttributes extends Attributes = Attributes,
|
|
64
|
+
>(type: T, p: MetricsParams): MetricTypeMap<TAttributes>[T] {
|
|
63
65
|
const meter = getMeter(p);
|
|
64
66
|
|
|
65
67
|
if (!MetricsFactoryMap[type]) {
|
|
66
68
|
throw new Error(`Unsupported metric type: ${type}`);
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
return MetricsFactoryMap[type](meter).bind(meter)(
|
|
71
|
+
return MetricsFactoryMap[type](meter).bind(meter)(
|
|
72
|
+
p.metricName,
|
|
73
|
+
p.options,
|
|
74
|
+
) as MetricTypeMap<TAttributes>[T];
|
|
70
75
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ogcio/o11y-sdk-node",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.8",
|
|
4
4
|
"description": "Opentelemetry standard instrumentation SDK for NodeJS based project",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"license": "ISC",
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@opentelemetry/api": "^1.9.0",
|
|
23
|
-
"@opentelemetry/auto-instrumentations-node": "^0.56.
|
|
23
|
+
"@opentelemetry/auto-instrumentations-node": "^0.56.1",
|
|
24
24
|
"@opentelemetry/core": "1.30.1",
|
|
25
25
|
"@opentelemetry/exporter-logs-otlp-grpc": "^0.57.2",
|
|
26
26
|
"@opentelemetry/exporter-logs-otlp-http": "^0.57.2",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"@opentelemetry/sdk-trace-base": "^1.30.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^22.13.
|
|
40
|
-
"@vitest/coverage-v8": "^3.0.
|
|
41
|
-
"tsx": "^4.19.
|
|
42
|
-
"typescript": "^5.
|
|
43
|
-
"vitest": "^3.0.
|
|
39
|
+
"@types/node": "^22.13.9",
|
|
40
|
+
"@vitest/coverage-v8": "^3.0.8",
|
|
41
|
+
"tsx": "^4.19.3",
|
|
42
|
+
"typescript": "^5.8.2",
|
|
43
|
+
"vitest": "^3.0.8"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "rm -rf dist && tsc -p tsconfig.json",
|
package/test/integration/run.sh
CHANGED
|
@@ -37,6 +37,9 @@ if [[ $ERROR_CODE -eq 0 ]]; then
|
|
|
37
37
|
docker run --detach \
|
|
38
38
|
--network $NETWORK_NAME \
|
|
39
39
|
--name $NODE_CONTAINER_NAME \
|
|
40
|
+
-e DB_DISABLED="true" \
|
|
41
|
+
-e SERVER_HOST="0.0.0.0" \
|
|
42
|
+
-e OTEL_COLLECTOR_URL="http://integrationalloy:4317" \
|
|
40
43
|
--health-cmd="curl -f http://${NODE_CONTAINER_NAME}:9091/api/health > /dev/null || exit 1" \
|
|
41
44
|
--health-start-period=1s \
|
|
42
45
|
--health-retries=10 \
|
package/test/metrics.test.ts
CHANGED
|
@@ -29,7 +29,7 @@ describe("MetricsFactoryMap", () => {
|
|
|
29
29
|
|
|
30
30
|
const validMetricParams: MetricsParams = {
|
|
31
31
|
metricName: "test-metric",
|
|
32
|
-
|
|
32
|
+
meterName: "test-meter",
|
|
33
33
|
options: { description: "A test metric" },
|
|
34
34
|
};
|
|
35
35
|
|
|
@@ -40,7 +40,7 @@ describe("MetricsFactoryMap", () => {
|
|
|
40
40
|
|
|
41
41
|
expect(result).toBe("mocked-gauge");
|
|
42
42
|
expect(mockMeter.createGauge).toHaveBeenCalledWith(
|
|
43
|
-
validMetricParams.
|
|
43
|
+
validMetricParams.metricName,
|
|
44
44
|
validMetricParams.options,
|
|
45
45
|
);
|
|
46
46
|
});
|
|
@@ -52,7 +52,7 @@ describe("MetricsFactoryMap", () => {
|
|
|
52
52
|
|
|
53
53
|
expect(result).toBe("mocked-histogram");
|
|
54
54
|
expect(mockMeter.createHistogram).toHaveBeenCalledWith(
|
|
55
|
-
validMetricParams.
|
|
55
|
+
validMetricParams.metricName,
|
|
56
56
|
validMetricParams.options,
|
|
57
57
|
);
|
|
58
58
|
});
|
|
@@ -64,7 +64,7 @@ describe("MetricsFactoryMap", () => {
|
|
|
64
64
|
|
|
65
65
|
expect(result).toBe("mocked-counter");
|
|
66
66
|
expect(mockMeter.createCounter).toHaveBeenCalledWith(
|
|
67
|
-
validMetricParams.
|
|
67
|
+
validMetricParams.metricName,
|
|
68
68
|
validMetricParams.options,
|
|
69
69
|
);
|
|
70
70
|
});
|
|
@@ -76,7 +76,7 @@ describe("MetricsFactoryMap", () => {
|
|
|
76
76
|
|
|
77
77
|
expect(result).toBe("mocked-updowncounter");
|
|
78
78
|
expect(mockMeter.createUpDownCounter).toHaveBeenCalledWith(
|
|
79
|
-
validMetricParams.
|
|
79
|
+
validMetricParams.metricName,
|
|
80
80
|
validMetricParams.options,
|
|
81
81
|
);
|
|
82
82
|
});
|
|
@@ -88,7 +88,7 @@ describe("MetricsFactoryMap", () => {
|
|
|
88
88
|
|
|
89
89
|
expect(result).toBe("mocked-async-counter");
|
|
90
90
|
expect(mockMeter.createObservableCounter).toHaveBeenCalledWith(
|
|
91
|
-
validMetricParams.
|
|
91
|
+
validMetricParams.metricName,
|
|
92
92
|
validMetricParams.options,
|
|
93
93
|
);
|
|
94
94
|
});
|
|
@@ -102,7 +102,7 @@ describe("MetricsFactoryMap", () => {
|
|
|
102
102
|
|
|
103
103
|
expect(result).toBe("mocked-async-updowncounter");
|
|
104
104
|
expect(mockMeter.createObservableUpDownCounter).toHaveBeenCalledWith(
|
|
105
|
-
validMetricParams.
|
|
105
|
+
validMetricParams.metricName,
|
|
106
106
|
validMetricParams.options,
|
|
107
107
|
);
|
|
108
108
|
});
|
|
@@ -114,7 +114,7 @@ describe("MetricsFactoryMap", () => {
|
|
|
114
114
|
|
|
115
115
|
expect(result).toBe("mocked-async-gauge");
|
|
116
116
|
expect(mockMeter.createObservableGauge).toHaveBeenCalledWith(
|
|
117
|
-
validMetricParams.
|
|
117
|
+
validMetricParams.metricName,
|
|
118
118
|
validMetricParams.options,
|
|
119
119
|
);
|
|
120
120
|
});
|
|
@@ -131,7 +131,7 @@ describe("MetricsFactoryMap", () => {
|
|
|
131
131
|
test("should return noop metric fallback for null config", async () => {
|
|
132
132
|
const nullMetricParams: MetricsParams = {
|
|
133
133
|
metricName: null!,
|
|
134
|
-
|
|
134
|
+
meterName: "",
|
|
135
135
|
};
|
|
136
136
|
|
|
137
137
|
const result = getMetric("async-gauge", nullMetricParams);
|