@ogcio/o11y-sdk-node 0.1.0-beta.10 → 0.1.0-beta.12
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 +35 -0
- package/dist/lib/exporter/grpc.d.ts +1 -1
- package/dist/lib/exporter/grpc.js +10 -1
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/instrumentation.node.d.ts +1 -1
- package/dist/lib/instrumentation.node.js +18 -21
- package/dist/package.json +21 -20
- package/lib/exporter/grpc.ts +14 -1
- package/lib/index.ts +9 -0
- package/lib/instrumentation.node.ts +23 -25
- package/package.json +21 -20
- package/test/index.test.ts +13 -12
- package/test/integration/README.md +1 -1
- package/test/node-config.test.ts +10 -17
- package/test/resource.test.ts +1 -1
- package/test/validation.test.ts +22 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.1.0-beta.12](https://github.com/ogcio/o11y/compare/@ogcio/o11y-sdk-node@v0.1.0-beta.11...@ogcio/o11y-sdk-node@v0.1.0-beta.12) (2025-06-04)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add custom log processor for span enrich ([#102](https://github.com/ogcio/o11y/issues/102)) ([bbf8334](https://github.com/ogcio/o11y/commit/bbf83340940ed651dff63bbe7aaa52881d1e8c8c))
|
|
9
|
+
* add opentelemetry sampler ([#66](https://github.com/ogcio/o11y/issues/66)) ([48a1761](https://github.com/ogcio/o11y/commit/48a1761d68fbccf7b63e4232a62376caecf01fbc))
|
|
10
|
+
* april depedency upgrade AB[#27200](https://github.com/ogcio/o11y/issues/27200) ([#116](https://github.com/ogcio/o11y/issues/116)) ([d792fe5](https://github.com/ogcio/o11y/commit/d792fe5a783b0b495912b5bef2babfe11ef5e01d))
|
|
11
|
+
* june deps update ([#147](https://github.com/ogcio/o11y/issues/147)) ([b365a40](https://github.com/ogcio/o11y/commit/b365a4099cdfd8533ffa4948620d29f0044bbd70))
|
|
12
|
+
* may deps update ([#136](https://github.com/ogcio/o11y/issues/136)) ([3edd8b1](https://github.com/ogcio/o11y/commit/3edd8b1d823740d555fc4d93be427e9dc1438a95))
|
|
13
|
+
* o11y sdk repo setup ([#15](https://github.com/ogcio/o11y/issues/15)) ([c5816ba](https://github.com/ogcio/o11y/commit/c5816baff1454353f12539949959e84964ed6401))
|
|
14
|
+
* 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))
|
|
15
|
+
* remove pnpm test on prepublishOnly script ([#68](https://github.com/ogcio/o11y/issues/68)) ([41f6f57](https://github.com/ogcio/o11y/commit/41f6f57fa415c4f7adc29f49f983539274ef7320))
|
|
16
|
+
* **sdk-node:** add span customization AB[#25358](https://github.com/ogcio/o11y/issues/25358) ([46ba97b](https://github.com/ogcio/o11y/commit/46ba97bac4004ff326a954592f45213ce0e4d683))
|
|
17
|
+
* **sdk-node:** custom metrics ([#53](https://github.com/ogcio/o11y/issues/53)) ([3cb40b1](https://github.com/ogcio/o11y/commit/3cb40b1add3d80615c8d123d233724094559c7ff))
|
|
18
|
+
* **sdk-node:** renaming MetricsParams interface properties AB[#26188](https://github.com/ogcio/o11y/issues/26188) ([#96](https://github.com/ogcio/o11y/issues/96)) ([244aee0](https://github.com/ogcio/o11y/commit/244aee01ae6e7f319ae7f9fdeff27eb40ee3c863))
|
|
19
|
+
* upgrade to opentelemetry 2 AB[#25863](https://github.com/ogcio/o11y/issues/25863) ([#106](https://github.com/ogcio/o11y/issues/106)) ([3ff0314](https://github.com/ogcio/o11y/commit/3ff0314fef9f4d7b5db76da3b94e9035801384c7))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* add readme file inside submodule ([#27](https://github.com/ogcio/o11y/issues/27)) ([dc518d5](https://github.com/ogcio/o11y/commit/dc518d5dde573368443bc0f8619e80e331880c78))
|
|
25
|
+
* default attributes in resource ([#112](https://github.com/ogcio/o11y/issues/112)) ([f0f0b9d](https://github.com/ogcio/o11y/commit/f0f0b9d555ef321d31f7171e25dc4b8a5b044522))
|
|
26
|
+
* improve getMetric attributes types ([#76](https://github.com/ogcio/o11y/issues/76)) ([243649c](https://github.com/ogcio/o11y/commit/243649c4bfe750687a729fbd836772cce16e0cb1))
|
|
27
|
+
* prepublishOnly hook ([#60](https://github.com/ogcio/o11y/issues/60)) ([9fbd3ad](https://github.com/ogcio/o11y/commit/9fbd3ad0b45a1604cf2eccc26b2f8855640417a1))
|
|
28
|
+
* **sdk-node:** add waitForReady for grpc-client to handle transient init connection errors AB[#28329](https://github.com/ogcio/o11y/issues/28329) ([#144](https://github.com/ogcio/o11y/issues/144)) ([6f260da](https://github.com/ogcio/o11y/commit/6f260da15fcbcd2c629ec6d4bb9fb3592803f399))
|
|
29
|
+
* **sdk-node:** update sdk init examples AB[#28329](https://github.com/ogcio/o11y/issues/28329) ([#146](https://github.com/ogcio/o11y/issues/146)) ([81de295](https://github.com/ogcio/o11y/commit/81de2957a7bef7430a46c6677f3c876255ef7c88))
|
|
30
|
+
|
|
31
|
+
## [0.1.0-beta.11](https://github.com/ogcio/o11y/compare/@ogcio/o11y-sdk-node@v0.1.0-beta.10...@ogcio/o11y-sdk-node@v0.1.0-beta.11) (2025-05-21)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Features
|
|
35
|
+
|
|
36
|
+
* may deps update ([#136](https://github.com/ogcio/o11y/issues/136)) ([3edd8b1](https://github.com/ogcio/o11y/commit/3edd8b1d823740d555fc4d93be427e9dc1438a95))
|
|
37
|
+
|
|
3
38
|
## [0.1.0-beta.10](https://github.com/ogcio/o11y/compare/@ogcio/o11y-sdk-node@v0.1.0-beta.9...@ogcio/o11y-sdk-node@v0.1.0-beta.10) (2025-04-09)
|
|
4
39
|
|
|
5
40
|
|
|
@@ -6,12 +6,19 @@ import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-grpc";
|
|
|
6
6
|
import { LogRecordProcessorMap, SpanProcessorMap } from "../utils.js";
|
|
7
7
|
import { EnrichSpanProcessor } from "../processor/enrich-span-processor.js";
|
|
8
8
|
import { EnrichLogProcessor } from "../processor/enrich-logger-processor.js";
|
|
9
|
-
|
|
9
|
+
async function defaultMetadata() {
|
|
10
|
+
const { Metadata } = await import("@grpc/grpc-js");
|
|
11
|
+
return new Metadata({
|
|
12
|
+
waitForReady: true,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export default async function buildGrpcExporters(config) {
|
|
10
16
|
return {
|
|
11
17
|
spans: [
|
|
12
18
|
new SpanProcessorMap[config.collectorMode ?? "batch"](new OTLPTraceExporter({
|
|
13
19
|
url: `${config.collectorUrl}`,
|
|
14
20
|
compression: CompressionAlgorithm.GZIP,
|
|
21
|
+
metadata: config.grpcMetadata ?? (await defaultMetadata()),
|
|
15
22
|
})),
|
|
16
23
|
new EnrichSpanProcessor(config.spanAttributes),
|
|
17
24
|
],
|
|
@@ -19,6 +26,7 @@ export default function buildGrpcExporters(config) {
|
|
|
19
26
|
exporter: new OTLPMetricExporter({
|
|
20
27
|
url: `${config.collectorUrl}`,
|
|
21
28
|
compression: CompressionAlgorithm.GZIP,
|
|
29
|
+
metadata: config.grpcMetadata ?? (await defaultMetadata()),
|
|
22
30
|
}),
|
|
23
31
|
}),
|
|
24
32
|
logs: [
|
|
@@ -26,6 +34,7 @@ export default function buildGrpcExporters(config) {
|
|
|
26
34
|
new LogRecordProcessorMap[config.collectorMode ?? "batch"](new OTLPLogExporter({
|
|
27
35
|
url: `${config.collectorUrl}`,
|
|
28
36
|
compression: CompressionAlgorithm.GZIP,
|
|
37
|
+
metadata: config.grpcMetadata ?? (await defaultMetadata()),
|
|
29
38
|
})),
|
|
30
39
|
],
|
|
31
40
|
};
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Metadata } from "@grpc/grpc-js";
|
|
1
2
|
export interface NodeSDKConfig {
|
|
2
3
|
/**
|
|
3
4
|
* The opentelemetry collector entrypoint GRPC url.
|
|
@@ -58,6 +59,12 @@ export interface NodeSDKConfig {
|
|
|
58
59
|
* @default grpc
|
|
59
60
|
*/
|
|
60
61
|
protocol?: SDKProtocol;
|
|
62
|
+
/**
|
|
63
|
+
* Grpc Metadata for the grpc-js client.
|
|
64
|
+
*
|
|
65
|
+
* @default { waitForReady: true }
|
|
66
|
+
*/
|
|
67
|
+
grpcMetadata?: Metadata;
|
|
61
68
|
}
|
|
62
69
|
export interface SamplerCondition {
|
|
63
70
|
type: "endsWith" | "includes" | "equals";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { NodeSDK } from "@opentelemetry/sdk-node";
|
|
2
2
|
import type { NodeSDKConfig } from "./index.js";
|
|
3
|
-
export default function buildNodeInstrumentation(config?: NodeSDKConfig): NodeSDK | undefined
|
|
3
|
+
export default function buildNodeInstrumentation(config?: NodeSDKConfig): Promise<NodeSDK | undefined>;
|
|
@@ -8,7 +8,7 @@ import buildGrpcExporters from "./exporter/grpc.js";
|
|
|
8
8
|
import buildHttpExporters from "./exporter/http.js";
|
|
9
9
|
import { ObservabilityResourceDetector } from "./resource.js";
|
|
10
10
|
import { UrlSampler } from "./url-sampler.js";
|
|
11
|
-
export default function buildNodeInstrumentation(config) {
|
|
11
|
+
export default async function buildNodeInstrumentation(config) {
|
|
12
12
|
if (!config) {
|
|
13
13
|
console.warn("observability config not set. Skipping NodeJS OpenTelemetry instrumentation.");
|
|
14
14
|
return;
|
|
@@ -21,16 +21,6 @@ export default function buildNodeInstrumentation(config) {
|
|
|
21
21
|
console.error("collectorUrl does not use a valid format. Skipping NodeJS OpenTelemetry instrumentation.");
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
let exporter;
|
|
25
|
-
if (config.protocol === "http") {
|
|
26
|
-
exporter = buildHttpExporters(config);
|
|
27
|
-
}
|
|
28
|
-
else if (config.protocol === "console") {
|
|
29
|
-
exporter = buildConsoleExporters(config);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
exporter = buildGrpcExporters(config);
|
|
33
|
-
}
|
|
34
24
|
const urlSampler = new UrlSampler(config.ignoreUrls, new TraceIdRatioBasedSampler(config.traceRatio ?? 1));
|
|
35
25
|
const mainSampler = new ParentBasedSampler({
|
|
36
26
|
root: urlSampler,
|
|
@@ -39,10 +29,23 @@ export default function buildNodeInstrumentation(config) {
|
|
|
39
29
|
localParentSampled: urlSampler,
|
|
40
30
|
localParentNotSampled: new AlwaysOffSampler(),
|
|
41
31
|
});
|
|
32
|
+
diag.setLogger(new DiagConsoleLogger(), config.diagLogLevel ? DiagLogLevel[config.diagLogLevel] : DiagLogLevel.INFO);
|
|
42
33
|
try {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
const nodeSdkInstrumentation = getNodeAutoInstrumentations({
|
|
35
|
+
"@opentelemetry/instrumentation-fs": {
|
|
36
|
+
enabled: config.enableFS ?? false,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
let exporter;
|
|
40
|
+
if (config.protocol === "http") {
|
|
41
|
+
exporter = buildHttpExporters(config);
|
|
42
|
+
}
|
|
43
|
+
else if (config.protocol === "console") {
|
|
44
|
+
exporter = buildConsoleExporters(config);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
exporter = await buildGrpcExporters(config);
|
|
48
|
+
}
|
|
46
49
|
const sdk = new NodeSDK({
|
|
47
50
|
resourceDetectors: [
|
|
48
51
|
new ObservabilityResourceDetector(config.resourceAttributes),
|
|
@@ -53,13 +56,7 @@ export default function buildNodeInstrumentation(config) {
|
|
|
53
56
|
logRecordProcessors: exporter.logs,
|
|
54
57
|
sampler: mainSampler,
|
|
55
58
|
textMapPropagator: new W3CTraceContextPropagator(),
|
|
56
|
-
instrumentations: [
|
|
57
|
-
getNodeAutoInstrumentations({
|
|
58
|
-
"@opentelemetry/instrumentation-fs": {
|
|
59
|
-
enabled: config.enableFS ?? false,
|
|
60
|
-
},
|
|
61
|
-
}),
|
|
62
|
-
],
|
|
59
|
+
instrumentations: [nodeSdkInstrumentation],
|
|
63
60
|
});
|
|
64
61
|
sdk.start();
|
|
65
62
|
console.log("NodeJS OpenTelemetry instrumentation started successfully.");
|
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.12",
|
|
4
4
|
"description": "Opentelemetry standard instrumentation SDK for NodeJS based project",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -27,29 +27,30 @@
|
|
|
27
27
|
"author": "team:ogcio/observability",
|
|
28
28
|
"license": "ISC",
|
|
29
29
|
"dependencies": {
|
|
30
|
+
"@grpc/grpc-js": "^1.13.4",
|
|
30
31
|
"@opentelemetry/api": "^1.9.0",
|
|
31
|
-
"@opentelemetry/auto-instrumentations-node": "^0.
|
|
32
|
-
"@opentelemetry/core": "^2.0.
|
|
33
|
-
"@opentelemetry/exporter-logs-otlp-grpc": "^0.
|
|
34
|
-
"@opentelemetry/exporter-logs-otlp-http": "^0.
|
|
35
|
-
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.
|
|
36
|
-
"@opentelemetry/exporter-metrics-otlp-http": "^0.
|
|
37
|
-
"@opentelemetry/exporter-trace-otlp-grpc": "^0.
|
|
38
|
-
"@opentelemetry/exporter-trace-otlp-http": "^0.
|
|
39
|
-
"@opentelemetry/instrumentation": "^0.
|
|
40
|
-
"@opentelemetry/otlp-exporter-base": "^0.
|
|
41
|
-
"@opentelemetry/resources": "^2.0.
|
|
42
|
-
"@opentelemetry/sdk-logs": "^0.
|
|
43
|
-
"@opentelemetry/sdk-metrics": "^2.0.
|
|
44
|
-
"@opentelemetry/sdk-node": "^0.
|
|
45
|
-
"@opentelemetry/sdk-trace-base": "^2.0.
|
|
32
|
+
"@opentelemetry/auto-instrumentations-node": "^0.60.0",
|
|
33
|
+
"@opentelemetry/core": "^2.0.1",
|
|
34
|
+
"@opentelemetry/exporter-logs-otlp-grpc": "^0.202.0",
|
|
35
|
+
"@opentelemetry/exporter-logs-otlp-http": "^0.202.0",
|
|
36
|
+
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.202.0",
|
|
37
|
+
"@opentelemetry/exporter-metrics-otlp-http": "^0.202.0",
|
|
38
|
+
"@opentelemetry/exporter-trace-otlp-grpc": "^0.202.0",
|
|
39
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.202.0",
|
|
40
|
+
"@opentelemetry/instrumentation": "^0.202.0",
|
|
41
|
+
"@opentelemetry/otlp-exporter-base": "^0.202.0",
|
|
42
|
+
"@opentelemetry/resources": "^2.0.1",
|
|
43
|
+
"@opentelemetry/sdk-logs": "^0.202.0",
|
|
44
|
+
"@opentelemetry/sdk-metrics": "^2.0.1",
|
|
45
|
+
"@opentelemetry/sdk-node": "^0.202.0",
|
|
46
|
+
"@opentelemetry/sdk-trace-base": "^2.0.1"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
|
-
"@types/node": "^22.
|
|
49
|
-
"@vitest/coverage-v8": "^3.
|
|
50
|
-
"tsx": "^4.19.
|
|
49
|
+
"@types/node": "^22.15.29",
|
|
50
|
+
"@vitest/coverage-v8": "^3.2.1",
|
|
51
|
+
"tsx": "^4.19.4",
|
|
51
52
|
"typescript": "^5.8.3",
|
|
52
|
-
"vitest": "^3.
|
|
53
|
+
"vitest": "^3.2.1"
|
|
53
54
|
},
|
|
54
55
|
"engines": {
|
|
55
56
|
"node": ">=20.6.0"
|
package/lib/exporter/grpc.ts
CHANGED
|
@@ -9,13 +9,24 @@ import { LogRecordProcessorMap, SpanProcessorMap } from "../utils.js";
|
|
|
9
9
|
import { EnrichSpanProcessor } from "../processor/enrich-span-processor.js";
|
|
10
10
|
import { EnrichLogProcessor } from "../processor/enrich-logger-processor.js";
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
async function defaultMetadata() {
|
|
13
|
+
const { Metadata } = await import("@grpc/grpc-js");
|
|
14
|
+
|
|
15
|
+
return new Metadata({
|
|
16
|
+
waitForReady: true,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default async function buildGrpcExporters(
|
|
21
|
+
config: NodeSDKConfig,
|
|
22
|
+
): Promise<Exporters> {
|
|
13
23
|
return {
|
|
14
24
|
spans: [
|
|
15
25
|
new SpanProcessorMap[config.collectorMode ?? "batch"](
|
|
16
26
|
new OTLPTraceExporter({
|
|
17
27
|
url: `${config.collectorUrl}`,
|
|
18
28
|
compression: CompressionAlgorithm.GZIP,
|
|
29
|
+
metadata: config.grpcMetadata ?? (await defaultMetadata()),
|
|
19
30
|
}),
|
|
20
31
|
),
|
|
21
32
|
new EnrichSpanProcessor(config.spanAttributes),
|
|
@@ -24,6 +35,7 @@ export default function buildGrpcExporters(config: NodeSDKConfig): Exporters {
|
|
|
24
35
|
exporter: new OTLPMetricExporter({
|
|
25
36
|
url: `${config.collectorUrl}`,
|
|
26
37
|
compression: CompressionAlgorithm.GZIP,
|
|
38
|
+
metadata: config.grpcMetadata ?? (await defaultMetadata()),
|
|
27
39
|
}),
|
|
28
40
|
}),
|
|
29
41
|
logs: [
|
|
@@ -32,6 +44,7 @@ export default function buildGrpcExporters(config: NodeSDKConfig): Exporters {
|
|
|
32
44
|
new OTLPLogExporter({
|
|
33
45
|
url: `${config.collectorUrl}`,
|
|
34
46
|
compression: CompressionAlgorithm.GZIP,
|
|
47
|
+
metadata: config.grpcMetadata ?? (await defaultMetadata()),
|
|
35
48
|
}),
|
|
36
49
|
),
|
|
37
50
|
],
|
package/lib/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Metadata } from "@grpc/grpc-js";
|
|
2
|
+
|
|
1
3
|
export interface NodeSDKConfig {
|
|
2
4
|
/**
|
|
3
5
|
* The opentelemetry collector entrypoint GRPC url.
|
|
@@ -66,6 +68,13 @@ export interface NodeSDKConfig {
|
|
|
66
68
|
* @default grpc
|
|
67
69
|
*/
|
|
68
70
|
protocol?: SDKProtocol;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Grpc Metadata for the grpc-js client.
|
|
74
|
+
*
|
|
75
|
+
* @default { waitForReady: true }
|
|
76
|
+
*/
|
|
77
|
+
grpcMetadata?: Metadata;
|
|
69
78
|
}
|
|
70
79
|
|
|
71
80
|
export interface SamplerCondition {
|
|
@@ -15,9 +15,9 @@ import type { NodeSDKConfig } from "./index.js";
|
|
|
15
15
|
import { ObservabilityResourceDetector } from "./resource.js";
|
|
16
16
|
import { UrlSampler } from "./url-sampler.js";
|
|
17
17
|
|
|
18
|
-
export default function buildNodeInstrumentation(
|
|
18
|
+
export default async function buildNodeInstrumentation(
|
|
19
19
|
config?: NodeSDKConfig,
|
|
20
|
-
): NodeSDK | undefined {
|
|
20
|
+
): Promise<NodeSDK | undefined> {
|
|
21
21
|
if (!config) {
|
|
22
22
|
console.warn(
|
|
23
23
|
"observability config not set. Skipping NodeJS OpenTelemetry instrumentation.",
|
|
@@ -39,16 +39,6 @@ export default function buildNodeInstrumentation(
|
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
let exporter: Exporters;
|
|
43
|
-
|
|
44
|
-
if (config.protocol === "http") {
|
|
45
|
-
exporter = buildHttpExporters(config);
|
|
46
|
-
} else if (config.protocol === "console") {
|
|
47
|
-
exporter = buildConsoleExporters(config);
|
|
48
|
-
} else {
|
|
49
|
-
exporter = buildGrpcExporters(config);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
42
|
const urlSampler = new UrlSampler(
|
|
53
43
|
config.ignoreUrls,
|
|
54
44
|
new TraceIdRatioBasedSampler(config.traceRatio ?? 1),
|
|
@@ -62,13 +52,27 @@ export default function buildNodeInstrumentation(
|
|
|
62
52
|
localParentNotSampled: new AlwaysOffSampler(),
|
|
63
53
|
});
|
|
64
54
|
|
|
55
|
+
diag.setLogger(
|
|
56
|
+
new DiagConsoleLogger(),
|
|
57
|
+
config.diagLogLevel ? DiagLogLevel[config.diagLogLevel] : DiagLogLevel.INFO,
|
|
58
|
+
);
|
|
59
|
+
|
|
65
60
|
try {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
const nodeSdkInstrumentation = getNodeAutoInstrumentations({
|
|
62
|
+
"@opentelemetry/instrumentation-fs": {
|
|
63
|
+
enabled: config.enableFS ?? false,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
let exporter: Exporters;
|
|
68
|
+
|
|
69
|
+
if (config.protocol === "http") {
|
|
70
|
+
exporter = buildHttpExporters(config);
|
|
71
|
+
} else if (config.protocol === "console") {
|
|
72
|
+
exporter = buildConsoleExporters(config);
|
|
73
|
+
} else {
|
|
74
|
+
exporter = await buildGrpcExporters(config);
|
|
75
|
+
}
|
|
72
76
|
|
|
73
77
|
const sdk = new NodeSDK({
|
|
74
78
|
resourceDetectors: [
|
|
@@ -80,13 +84,7 @@ export default function buildNodeInstrumentation(
|
|
|
80
84
|
logRecordProcessors: exporter.logs,
|
|
81
85
|
sampler: mainSampler,
|
|
82
86
|
textMapPropagator: new W3CTraceContextPropagator(),
|
|
83
|
-
instrumentations: [
|
|
84
|
-
getNodeAutoInstrumentations({
|
|
85
|
-
"@opentelemetry/instrumentation-fs": {
|
|
86
|
-
enabled: config.enableFS ?? false,
|
|
87
|
-
},
|
|
88
|
-
}),
|
|
89
|
-
],
|
|
87
|
+
instrumentations: [nodeSdkInstrumentation],
|
|
90
88
|
});
|
|
91
89
|
|
|
92
90
|
sdk.start();
|
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.12",
|
|
4
4
|
"description": "Opentelemetry standard instrumentation SDK for NodeJS based project",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -19,29 +19,30 @@
|
|
|
19
19
|
"author": "team:ogcio/observability",
|
|
20
20
|
"license": "ISC",
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@grpc/grpc-js": "^1.13.4",
|
|
22
23
|
"@opentelemetry/api": "^1.9.0",
|
|
23
|
-
"@opentelemetry/auto-instrumentations-node": "^0.
|
|
24
|
-
"@opentelemetry/core": "^2.0.
|
|
25
|
-
"@opentelemetry/exporter-logs-otlp-grpc": "^0.
|
|
26
|
-
"@opentelemetry/exporter-logs-otlp-http": "^0.
|
|
27
|
-
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.
|
|
28
|
-
"@opentelemetry/exporter-metrics-otlp-http": "^0.
|
|
29
|
-
"@opentelemetry/exporter-trace-otlp-grpc": "^0.
|
|
30
|
-
"@opentelemetry/exporter-trace-otlp-http": "^0.
|
|
31
|
-
"@opentelemetry/instrumentation": "^0.
|
|
32
|
-
"@opentelemetry/otlp-exporter-base": "^0.
|
|
33
|
-
"@opentelemetry/resources": "^2.0.
|
|
34
|
-
"@opentelemetry/sdk-logs": "^0.
|
|
35
|
-
"@opentelemetry/sdk-metrics": "^2.0.
|
|
36
|
-
"@opentelemetry/sdk-node": "^0.
|
|
37
|
-
"@opentelemetry/sdk-trace-base": "^2.0.
|
|
24
|
+
"@opentelemetry/auto-instrumentations-node": "^0.60.0",
|
|
25
|
+
"@opentelemetry/core": "^2.0.1",
|
|
26
|
+
"@opentelemetry/exporter-logs-otlp-grpc": "^0.202.0",
|
|
27
|
+
"@opentelemetry/exporter-logs-otlp-http": "^0.202.0",
|
|
28
|
+
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.202.0",
|
|
29
|
+
"@opentelemetry/exporter-metrics-otlp-http": "^0.202.0",
|
|
30
|
+
"@opentelemetry/exporter-trace-otlp-grpc": "^0.202.0",
|
|
31
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.202.0",
|
|
32
|
+
"@opentelemetry/instrumentation": "^0.202.0",
|
|
33
|
+
"@opentelemetry/otlp-exporter-base": "^0.202.0",
|
|
34
|
+
"@opentelemetry/resources": "^2.0.1",
|
|
35
|
+
"@opentelemetry/sdk-logs": "^0.202.0",
|
|
36
|
+
"@opentelemetry/sdk-metrics": "^2.0.1",
|
|
37
|
+
"@opentelemetry/sdk-node": "^0.202.0",
|
|
38
|
+
"@opentelemetry/sdk-trace-base": "^2.0.1"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@types/node": "^22.
|
|
41
|
-
"@vitest/coverage-v8": "^3.
|
|
42
|
-
"tsx": "^4.19.
|
|
41
|
+
"@types/node": "^22.15.29",
|
|
42
|
+
"@vitest/coverage-v8": "^3.2.1",
|
|
43
|
+
"tsx": "^4.19.4",
|
|
43
44
|
"typescript": "^5.8.3",
|
|
44
|
-
"vitest": "^3.
|
|
45
|
+
"vitest": "^3.2.1"
|
|
45
46
|
},
|
|
46
47
|
"engines": {
|
|
47
48
|
"node": ">=20.6.0"
|
package/test/index.test.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import { describe, test, expect, vi } from "vitest";
|
|
1
|
+
import { describe, test, expect, vi, beforeEach } from "vitest";
|
|
2
2
|
import { NodeSDKConfig } from "../index";
|
|
3
3
|
import { instrumentNode } from "../index";
|
|
4
|
-
|
|
5
|
-
vi.mock("../lib/instrumentation.node", () => ({
|
|
6
|
-
default: vi.fn(),
|
|
7
|
-
}));
|
|
4
|
+
import * as buildNodeInstrumentationModule from "../lib/instrumentation.node";
|
|
8
5
|
|
|
9
6
|
describe("instrumentNode", () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
vi.restoreAllMocks();
|
|
9
|
+
});
|
|
10
|
+
|
|
10
11
|
test("should call buildNodeInstrumentation with the provided config", async () => {
|
|
12
|
+
const instrumentationMock = vi
|
|
13
|
+
.spyOn(buildNodeInstrumentationModule, "default")
|
|
14
|
+
.mockImplementation(vi.fn());
|
|
15
|
+
|
|
11
16
|
const config: NodeSDKConfig = {
|
|
12
17
|
serviceName: "custom-service",
|
|
13
18
|
collectorUrl: "http://custom-collector.com",
|
|
@@ -23,16 +28,12 @@ describe("instrumentNode", () => {
|
|
|
23
28
|
},
|
|
24
29
|
};
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
"../lib/instrumentation.node"
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
instrumentNode(config);
|
|
31
|
+
await instrumentNode(config);
|
|
31
32
|
|
|
32
|
-
expect(
|
|
33
|
+
expect(instrumentationMock).toHaveBeenCalledWith(config);
|
|
33
34
|
});
|
|
34
35
|
|
|
35
36
|
test("should not throw when called without arguments", () => {
|
|
36
|
-
expect(
|
|
37
|
+
expect(instrumentNode()).resolves.not.toThrow();
|
|
37
38
|
});
|
|
38
39
|
});
|
|
@@ -22,5 +22,5 @@ The `run.sh` script performs the following steps:
|
|
|
22
22
|
- run fastify app in a docker container
|
|
23
23
|
- ensure is running otherwise exit process
|
|
24
24
|
- execute some curl to the fastify microservice
|
|
25
|
-
-
|
|
25
|
+
- persist alloy log to a file and save to following path `/packages/sdk-node/test/integration/`
|
|
26
26
|
- docker turn down process (containers/network/image)
|
package/test/node-config.test.ts
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { test, describe, assert, expect } from "vitest";
|
|
2
2
|
import buildNodeInstrumentation from "../lib/instrumentation.node.js";
|
|
3
|
-
import { NodeSDK,
|
|
4
|
-
|
|
5
|
-
import { OTLPMetricExporter as GRPC_OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-grpc";
|
|
6
|
-
import { OTLPLogExporter as GRPC_OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-grpc";
|
|
7
|
-
|
|
8
|
-
import { OTLPTraceExporter as HTTP_OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
9
|
-
import { OTLPMetricExporter as HTTP_OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
|
|
10
|
-
import { OTLPLogExporter as HTTP_OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
3
|
+
import { NodeSDK, metrics } from "@opentelemetry/sdk-node";
|
|
4
|
+
|
|
11
5
|
import { NodeSDKConfig } from "../lib/index.js";
|
|
12
6
|
import buildHttpExporters from "../lib/exporter/http.js";
|
|
13
7
|
import {
|
|
14
8
|
BatchSpanProcessor,
|
|
15
|
-
ConsoleSpanExporter,
|
|
16
9
|
SimpleSpanProcessor,
|
|
17
10
|
} from "@opentelemetry/sdk-trace-base";
|
|
18
11
|
import {
|
|
@@ -27,7 +20,7 @@ describe("verify config settings", () => {
|
|
|
27
20
|
serviceName: "test",
|
|
28
21
|
};
|
|
29
22
|
|
|
30
|
-
test("grpc config", () => {
|
|
23
|
+
test("grpc config", async () => {
|
|
31
24
|
const config: NodeSDKConfig = {
|
|
32
25
|
...commonConfig,
|
|
33
26
|
protocol: "grpc",
|
|
@@ -35,7 +28,7 @@ describe("verify config settings", () => {
|
|
|
35
28
|
diagLogLevel: "NONE",
|
|
36
29
|
};
|
|
37
30
|
|
|
38
|
-
const sdk: NodeSDK | undefined = buildNodeInstrumentation(config);
|
|
31
|
+
const sdk: NodeSDK | undefined = await buildNodeInstrumentation(config);
|
|
39
32
|
|
|
40
33
|
assert.ok(sdk);
|
|
41
34
|
|
|
@@ -59,14 +52,14 @@ describe("verify config settings", () => {
|
|
|
59
52
|
);
|
|
60
53
|
});
|
|
61
54
|
|
|
62
|
-
test("http config", () => {
|
|
55
|
+
test("http config", async () => {
|
|
63
56
|
const config: NodeSDKConfig = {
|
|
64
57
|
...commonConfig,
|
|
65
58
|
protocol: "http",
|
|
66
59
|
diagLogLevel: "NONE",
|
|
67
60
|
};
|
|
68
61
|
|
|
69
|
-
const sdk: NodeSDK | undefined = buildNodeInstrumentation(config);
|
|
62
|
+
const sdk: NodeSDK | undefined = await buildNodeInstrumentation(config);
|
|
70
63
|
assert.ok(sdk);
|
|
71
64
|
|
|
72
65
|
const _configuration = sdk["_configuration"];
|
|
@@ -89,14 +82,14 @@ describe("verify config settings", () => {
|
|
|
89
82
|
);
|
|
90
83
|
});
|
|
91
84
|
|
|
92
|
-
test("console - console config", () => {
|
|
85
|
+
test("console - console config", async () => {
|
|
93
86
|
const config: NodeSDKConfig = {
|
|
94
87
|
...commonConfig,
|
|
95
88
|
protocol: "console",
|
|
96
89
|
diagLogLevel: "NONE",
|
|
97
90
|
};
|
|
98
91
|
|
|
99
|
-
const sdk: NodeSDK = buildNodeInstrumentation(config)!;
|
|
92
|
+
const sdk: NodeSDK = await buildNodeInstrumentation(config)!;
|
|
100
93
|
assert.ok(sdk);
|
|
101
94
|
|
|
102
95
|
const _configuration = sdk["_configuration"];
|
|
@@ -121,7 +114,7 @@ describe("verify config settings", () => {
|
|
|
121
114
|
);
|
|
122
115
|
});
|
|
123
116
|
|
|
124
|
-
test("single log sending config", () => {
|
|
117
|
+
test("single log sending config", async () => {
|
|
125
118
|
const config: NodeSDKConfig = {
|
|
126
119
|
...commonConfig,
|
|
127
120
|
protocol: "grpc",
|
|
@@ -129,7 +122,7 @@ describe("verify config settings", () => {
|
|
|
129
122
|
collectorMode: "single",
|
|
130
123
|
};
|
|
131
124
|
|
|
132
|
-
const sdk: NodeSDK | undefined = buildNodeInstrumentation(config);
|
|
125
|
+
const sdk: NodeSDK | undefined = await buildNodeInstrumentation(config);
|
|
133
126
|
|
|
134
127
|
assert.ok(sdk);
|
|
135
128
|
|
package/test/resource.test.ts
CHANGED
package/test/validation.test.ts
CHANGED
|
@@ -10,7 +10,7 @@ describe("validation config: should return without breaking the execution", () =
|
|
|
10
10
|
.spyOn(console, "warn")
|
|
11
11
|
.mockImplementation(vi.fn());
|
|
12
12
|
|
|
13
|
-
instrumentNode();
|
|
13
|
+
await instrumentNode();
|
|
14
14
|
|
|
15
15
|
expect(consoleWarnSpy).toHaveBeenCalled();
|
|
16
16
|
expect(consoleWarnSpy).toHaveBeenCalledWith(
|
|
@@ -26,11 +26,13 @@ describe("validation config: should return without breaking the execution", () =
|
|
|
26
26
|
.mockImplementation(vi.fn());
|
|
27
27
|
const consoleLogSpy = vi.spyOn(console, "log").mockImplementation(vi.fn());
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
collectorUrl: undefined
|
|
32
|
-
})
|
|
33
|
-
|
|
29
|
+
await expect(
|
|
30
|
+
buildNodeInstrumentation({
|
|
31
|
+
collectorUrl: undefined,
|
|
32
|
+
}).then((result) => {
|
|
33
|
+
sdk = result;
|
|
34
|
+
}),
|
|
35
|
+
).resolves.not.toThrowError();
|
|
34
36
|
|
|
35
37
|
assert.equal(sdk, undefined);
|
|
36
38
|
|
|
@@ -41,7 +43,7 @@ describe("validation config: should return without breaking the execution", () =
|
|
|
41
43
|
expect(consoleLogSpy).not.toHaveBeenCalled();
|
|
42
44
|
});
|
|
43
45
|
|
|
44
|
-
test("node instrumentation: invalid url", () => {
|
|
46
|
+
test("node instrumentation: invalid url", async () => {
|
|
45
47
|
let sdk: NodeSDK | undefined = undefined;
|
|
46
48
|
|
|
47
49
|
const consoleErrorSpy = vi
|
|
@@ -49,11 +51,13 @@ describe("validation config: should return without breaking the execution", () =
|
|
|
49
51
|
.mockImplementation(vi.fn());
|
|
50
52
|
const consoleLogSpy = vi.spyOn(console, "log").mockImplementation(vi.fn());
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
await expect(
|
|
55
|
+
buildNodeInstrumentation({
|
|
54
56
|
collectorUrl: "notavalidURL",
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
+
}).then((result) => {
|
|
58
|
+
sdk = result;
|
|
59
|
+
}),
|
|
60
|
+
).resolves.not.toThrowError();
|
|
57
61
|
|
|
58
62
|
assert.equal(sdk, undefined);
|
|
59
63
|
|
|
@@ -64,7 +68,7 @@ describe("validation config: should return without breaking the execution", () =
|
|
|
64
68
|
expect(consoleLogSpy).not.toHaveBeenCalled();
|
|
65
69
|
});
|
|
66
70
|
|
|
67
|
-
test("node instrumentation: verify no instrumentation if exception occurs", () => {
|
|
71
|
+
test("node instrumentation: verify no instrumentation if exception occurs", async () => {
|
|
68
72
|
let sdk: NodeSDK | undefined = undefined;
|
|
69
73
|
|
|
70
74
|
const consoleErrorSpy = vi
|
|
@@ -78,12 +82,14 @@ describe("validation config: should return without breaking the execution", () =
|
|
|
78
82
|
}),
|
|
79
83
|
}));
|
|
80
84
|
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
await expect(
|
|
86
|
+
buildNodeInstrumentation({
|
|
83
87
|
collectorUrl: "https://testurl.com",
|
|
84
88
|
serviceName: "test",
|
|
85
|
-
})
|
|
86
|
-
|
|
89
|
+
}).then((result) => {
|
|
90
|
+
sdk = result;
|
|
91
|
+
}),
|
|
92
|
+
).resolves.not.toThrowError();
|
|
87
93
|
|
|
88
94
|
assert.equal(sdk, undefined);
|
|
89
95
|
|