@ogcio/o11y-sdk-node 0.1.0-beta.3 → 0.1.0-beta.4

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/coverage/cobertura-coverage.xml +310 -0
  3. package/coverage/lcov-report/base.css +224 -0
  4. package/coverage/lcov-report/block-navigation.js +87 -0
  5. package/coverage/lcov-report/favicon.png +0 -0
  6. package/coverage/lcov-report/index.html +131 -0
  7. package/coverage/lcov-report/prettify.css +1 -0
  8. package/coverage/lcov-report/prettify.js +2 -0
  9. package/coverage/lcov-report/sdk-node/index.html +116 -0
  10. package/coverage/lcov-report/sdk-node/index.ts.html +112 -0
  11. package/coverage/lcov-report/sdk-node/lib/console.ts.html +130 -0
  12. package/coverage/lcov-report/sdk-node/lib/grpc.ts.html +178 -0
  13. package/coverage/lcov-report/sdk-node/lib/http.ts.html +190 -0
  14. package/coverage/lcov-report/sdk-node/lib/index.html +221 -0
  15. package/coverage/lcov-report/sdk-node/lib/index.ts.html +256 -0
  16. package/coverage/lcov-report/sdk-node/lib/instrumentation.node.ts.html +334 -0
  17. package/coverage/lcov-report/sdk-node/lib/metrics.ts.html +295 -0
  18. package/coverage/lcov-report/sdk-node/lib/options.ts.html +106 -0
  19. package/coverage/lcov-report/sdk-node/lib/utils.ts.html +115 -0
  20. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  21. package/coverage/lcov-report/sorter.js +196 -0
  22. package/coverage/lcov.info +312 -0
  23. package/dist/index.d.ts +7 -0
  24. package/dist/index.js +3 -0
  25. package/dist/lib/console.d.ts +3 -0
  26. package/dist/lib/console.js +12 -0
  27. package/dist/lib/grpc.d.ts +3 -0
  28. package/dist/lib/grpc.js +26 -0
  29. package/dist/lib/http.d.ts +3 -0
  30. package/dist/lib/http.js +29 -0
  31. package/dist/lib/index.d.ts +46 -0
  32. package/dist/lib/index.js +1 -0
  33. package/dist/lib/instrumentation.node.d.ts +3 -0
  34. package/dist/lib/instrumentation.node.js +62 -0
  35. package/dist/lib/metrics.d.ts +18 -0
  36. package/dist/lib/metrics.js +28 -0
  37. package/dist/lib/options.d.ts +6 -0
  38. package/dist/lib/options.js +1 -0
  39. package/dist/lib/utils.d.ts +3 -0
  40. package/dist/lib/utils.js +5 -0
  41. package/dist/package.json +50 -0
  42. package/dist/vitest.config.d.ts +2 -0
  43. package/dist/vitest.config.js +25 -0
  44. package/package.json +1 -1
  45. package/test-report.xml +71 -0
@@ -0,0 +1,62 @@
1
+ import { NodeSDK, resources } from "@opentelemetry/sdk-node";
2
+ import isUrl from "is-url";
3
+ import buildHttpExporters from "./http.js";
4
+ import buildGrpcExporters from "./grpc.js";
5
+ import buildConsoleExporters from "./console.js";
6
+ import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";
7
+ import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
8
+ import { W3CTraceContextPropagator } from "@opentelemetry/core";
9
+ import packageJson from "../package.json" with { type: "json" };
10
+ export default function buildNodeInstrumentation(config) {
11
+ if (!config) {
12
+ console.warn("observability config not set. Skipping NodeJS OpenTelemetry instrumentation.");
13
+ return;
14
+ }
15
+ if (!config.collectorUrl) {
16
+ console.warn("collectorUrl not set. Skipping NodeJS OpenTelemetry instrumentation.");
17
+ return;
18
+ }
19
+ if (!isUrl(config.collectorUrl)) {
20
+ console.error("collectorUrl does not use a valid format. Skipping NodeJS OpenTelemetry instrumentation.");
21
+ return;
22
+ }
23
+ let exporter;
24
+ if (config.protocol === "http") {
25
+ exporter = buildHttpExporters(config);
26
+ }
27
+ else if (config.protocol === "console") {
28
+ exporter = buildConsoleExporters(config);
29
+ }
30
+ else {
31
+ exporter = buildGrpcExporters(config);
32
+ }
33
+ try {
34
+ diag.setLogger(new DiagConsoleLogger(), config.diagLogLevel
35
+ ? DiagLogLevel[config.diagLogLevel]
36
+ : DiagLogLevel.INFO);
37
+ const sdk = new NodeSDK({
38
+ resource: new resources.Resource({
39
+ "o11y.sdk.name": packageJson.name,
40
+ "o11y.sdk.version": packageJson.version,
41
+ }),
42
+ serviceName: config.serviceName,
43
+ traceExporter: exporter.traces,
44
+ metricReader: exporter.metrics,
45
+ logRecordProcessors: exporter.logs,
46
+ textMapPropagator: new W3CTraceContextPropagator(),
47
+ instrumentations: [
48
+ getNodeAutoInstrumentations({
49
+ "@opentelemetry/instrumentation-fs": {
50
+ enabled: config.enableFS ?? false,
51
+ },
52
+ }),
53
+ ],
54
+ });
55
+ sdk.start();
56
+ console.log("NodeJS OpenTelemetry instrumentation started successfully.");
57
+ return sdk;
58
+ }
59
+ catch (error) {
60
+ console.error("Error starting NodeJS OpenTelemetry instrumentation:", error);
61
+ }
62
+ }
@@ -0,0 +1,18 @@
1
+ import { Counter, Gauge, Histogram, MetricOptions, ObservableCounter, ObservableGauge, ObservableUpDownCounter, UpDownCounter } from "@opentelemetry/api";
2
+ declare const MetricsMap: {
3
+ gauge: Gauge;
4
+ histogram: Histogram;
5
+ counter: Counter;
6
+ updowncounter: UpDownCounter;
7
+ "async-counter": ObservableCounter;
8
+ "async-updowncounter": ObservableUpDownCounter;
9
+ "async-gauge": ObservableGauge;
10
+ };
11
+ type MetricType = keyof typeof MetricsMap;
12
+ export interface MetricsParams {
13
+ metricName: string;
14
+ attributeName: string;
15
+ options?: MetricOptions;
16
+ }
17
+ export declare function getMetric<T extends MetricType>(type: T, p: MetricsParams): (typeof MetricsMap)[T];
18
+ export {};
@@ -0,0 +1,28 @@
1
+ import { createNoopMeter, metrics, } from "@opentelemetry/api";
2
+ const MetricsFactoryMap = {
3
+ gauge: (meter) => meter.createGauge,
4
+ histogram: (meter) => meter.createHistogram,
5
+ counter: (meter) => meter.createCounter,
6
+ updowncounter: (meter) => meter.createUpDownCounter,
7
+ "async-counter": (meter) => meter.createObservableCounter,
8
+ "async-updowncounter": (meter) => meter.createObservableUpDownCounter,
9
+ "async-gauge": (meter) => meter.createObservableGauge,
10
+ };
11
+ function getMeter({ metricName, attributeName }) {
12
+ let meter;
13
+ if (!metricName || !attributeName) {
14
+ console.error("Invaid metric configuration!");
15
+ meter = createNoopMeter();
16
+ }
17
+ else {
18
+ meter = metrics.getMeter(`custom_metric.${metricName}`);
19
+ }
20
+ return meter;
21
+ }
22
+ export function getMetric(type, p) {
23
+ const meter = getMeter(p);
24
+ if (!MetricsFactoryMap[type]) {
25
+ throw new Error(`Unsupported metric type: ${type}`);
26
+ }
27
+ return MetricsFactoryMap[type](meter).bind(meter)(p.attributeName, p.options);
28
+ }
@@ -0,0 +1,6 @@
1
+ import type { logs, tracing, metrics } from "@opentelemetry/sdk-node";
2
+ export type Exporters = {
3
+ traces: tracing.SpanExporter;
4
+ metrics: metrics.MetricReader;
5
+ logs: logs.LogRecordProcessor[];
6
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { SDKCollectorMode } from "./index.js";
2
+ import { logs } from "@opentelemetry/sdk-node";
3
+ export declare const LogRecordProcessorMap: Record<SDKCollectorMode, typeof logs.SimpleLogRecordProcessor | typeof logs.BatchLogRecordProcessor>;
@@ -0,0 +1,5 @@
1
+ import { logs } from "@opentelemetry/sdk-node";
2
+ export const LogRecordProcessorMap = {
3
+ single: logs.SimpleLogRecordProcessor,
4
+ batch: logs.BatchLogRecordProcessor,
5
+ };
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@ogcio/o11y-sdk-node",
3
+ "version": "0.1.0-beta.4",
4
+ "description": "Opentelemetry standard instrumentation SDK for NodeJS based project",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "build": "rm -rf dist && tsc -p tsconfig.json",
9
+ "test": "vitest",
10
+ "prepublishOnly": "pnpm i && pnpm build && pnpm test"
11
+ },
12
+ "exports": {
13
+ ".": "./dist/index.js",
14
+ "./*": "./dist/*.js"
15
+ },
16
+ "keywords": [
17
+ "observability",
18
+ "o11y",
19
+ "opentelemetry",
20
+ "node",
21
+ "nodejs",
22
+ "ogcio"
23
+ ],
24
+ "author": "team:ogcio/observability",
25
+ "license": "ISC",
26
+ "dependencies": {
27
+ "@opentelemetry/api": "^1.9.0",
28
+ "@opentelemetry/auto-instrumentations-node": "^0.55.3",
29
+ "@opentelemetry/core": "1.30.1",
30
+ "@opentelemetry/exporter-logs-otlp-grpc": "^0.57.1",
31
+ "@opentelemetry/exporter-logs-otlp-http": "^0.57.1",
32
+ "@opentelemetry/exporter-metrics-otlp-grpc": "^0.57.1",
33
+ "@opentelemetry/exporter-metrics-otlp-http": "^0.57.1",
34
+ "@opentelemetry/exporter-trace-otlp-grpc": "^0.57.1",
35
+ "@opentelemetry/exporter-trace-otlp-http": "^0.57.1",
36
+ "@opentelemetry/instrumentation": "^0.57.1",
37
+ "@opentelemetry/otlp-exporter-base": "^0.57.1",
38
+ "@opentelemetry/sdk-metrics": "^1.30.1",
39
+ "@opentelemetry/sdk-node": "^0.57.1",
40
+ "is-url": "^1.2.4"
41
+ },
42
+ "devDependencies": {
43
+ "@types/is-url": "^1.2.32",
44
+ "@types/node": "^22.12.0",
45
+ "@vitest/coverage-v8": "^3.0.4",
46
+ "tsx": "^4.19.2",
47
+ "typescript": "^5.7.3",
48
+ "vitest": "^3.0.4"
49
+ }
50
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vite").UserConfig;
2
+ export default _default;
@@ -0,0 +1,25 @@
1
+ import { defineConfig } from "vitest/config";
2
+ export default defineConfig({
3
+ test: {
4
+ globals: true,
5
+ watch: false,
6
+ include: ["**/test/*.test.ts"],
7
+ exclude: ["**/fixtures/**", "**/dist/**"],
8
+ poolOptions: {
9
+ threads: {
10
+ maxThreads: 8,
11
+ },
12
+ },
13
+ clearMocks: true,
14
+ testTimeout: 30_000,
15
+ coverage: {
16
+ enabled: true,
17
+ provider: "v8",
18
+ reportsDirectory: "coverage",
19
+ reporter: ["lcov", "cobertura"],
20
+ clean: true,
21
+ },
22
+ reporters: ["default", ["junit", { outputFile: "test-report.xml" }]],
23
+ environment: "node",
24
+ },
25
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ogcio/o11y-sdk-node",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.4",
4
4
  "description": "Opentelemetry standard instrumentation SDK for NodeJS based project",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -0,0 +1,71 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <testsuites name="vitest tests" tests="20" failures="0" errors="0" time="0.189321701">
3
+ <testsuite name="test/index.test.ts" timestamp="2025-01-28T15:28:22.386Z" hostname="fv-az367-418" tests="2" failures="0" errors="0" skipped="0" time="0.008525973">
4
+ <testcase classname="test/index.test.ts" name="instrumentNode &gt; should call buildNodeInstrumentation with the provided config" time="0.004943385">
5
+ </testcase>
6
+ <testcase classname="test/index.test.ts" name="instrumentNode &gt; should not throw when called without arguments" time="0.001780995">
7
+ </testcase>
8
+ </testsuite>
9
+ <testsuite name="test/metrics.test.ts" timestamp="2025-01-28T15:28:22.388Z" hostname="fv-az367-418" tests="9" failures="0" errors="0" skipped="0" time="0.016880947">
10
+ <testcase classname="test/metrics.test.ts" name="MetricsFactoryMap &gt; should call createGauge when type is &apos;gauge&apos;" time="0.005396083">
11
+ </testcase>
12
+ <testcase classname="test/metrics.test.ts" name="MetricsFactoryMap &gt; should call createHistogram when type is &apos;histogram&apos;" time="0.000557498">
13
+ </testcase>
14
+ <testcase classname="test/metrics.test.ts" name="MetricsFactoryMap &gt; should call createCounter when type is &apos;counter&apos;" time="0.000447099">
15
+ </testcase>
16
+ <testcase classname="test/metrics.test.ts" name="MetricsFactoryMap &gt; should call createUpDownCounter when type is &apos;updowncounter&apos;" time="0.000433999">
17
+ </testcase>
18
+ <testcase classname="test/metrics.test.ts" name="MetricsFactoryMap &gt; should call createObservableCounter when type is &apos;async-counter&apos;" time="0.000520098">
19
+ </testcase>
20
+ <testcase classname="test/metrics.test.ts" name="MetricsFactoryMap &gt; should call createObservableUpDownCounter when type is &apos;async-updowncounter&apos;" time="0.000518598">
21
+ </testcase>
22
+ <testcase classname="test/metrics.test.ts" name="MetricsFactoryMap &gt; should call createObservableGauge when type is &apos;async-gauge&apos;" time="0.000397299">
23
+ </testcase>
24
+ <testcase classname="test/metrics.test.ts" name="MetricsFactoryMap &gt; should throw an error for unsupported metric types" time="0.001743294">
25
+ </testcase>
26
+ <testcase classname="test/metrics.test.ts" name="MetricsFactoryMap &gt; should return noop metric fallback for null config" time="0.004466986">
27
+ <system-err>
28
+ Invaid metric configuration!
29
+
30
+ </system-err>
31
+ </testcase>
32
+ </testsuite>
33
+ <testsuite name="test/node-config.test.ts" timestamp="2025-01-28T15:28:22.391Z" hostname="fv-az367-418" tests="5" failures="0" errors="0" skipped="0" time="0.146814435">
34
+ <testcase classname="test/node-config.test.ts" name="verify config settings &gt; grpc config" time="0.056207422">
35
+ <system-out>
36
+ NodeJS OpenTelemetry instrumentation started successfully.
37
+
38
+ </system-out>
39
+ </testcase>
40
+ <testcase classname="test/node-config.test.ts" name="verify config settings &gt; http config" time="0.04112677">
41
+ <system-out>
42
+ NodeJS OpenTelemetry instrumentation started successfully.
43
+
44
+ </system-out>
45
+ </testcase>
46
+ <testcase classname="test/node-config.test.ts" name="verify config settings &gt; console - console config" time="0.01881204">
47
+ <system-out>
48
+ NodeJS OpenTelemetry instrumentation started successfully.
49
+
50
+ </system-out>
51
+ </testcase>
52
+ <testcase classname="test/node-config.test.ts" name="verify config settings &gt; single log sending config" time="0.027214414">
53
+ <system-out>
54
+ NodeJS OpenTelemetry instrumentation started successfully.
55
+
56
+ </system-out>
57
+ </testcase>
58
+ <testcase classname="test/node-config.test.ts" name="verify config settings &gt; check if clear base endpoint final slash" time="0.001299795">
59
+ </testcase>
60
+ </testsuite>
61
+ <testsuite name="test/validation.test.ts" timestamp="2025-01-28T15:28:22.394Z" hostname="fv-az367-418" tests="4" failures="0" errors="0" skipped="0" time="0.017100346">
62
+ <testcase classname="test/validation.test.ts" name="validation config: should return without breaking the execution &gt; should call buildNodeInstrumentation without config and skip instrumentation" time="0.005204683">
63
+ </testcase>
64
+ <testcase classname="test/validation.test.ts" name="validation config: should return without breaking the execution &gt; node instrumentation: url undefined" time="0.002382393">
65
+ </testcase>
66
+ <testcase classname="test/validation.test.ts" name="validation config: should return without breaking the execution &gt; node instrumentation: invalid url" time="0.000839897">
67
+ </testcase>
68
+ <testcase classname="test/validation.test.ts" name="validation config: should return without breaking the execution &gt; node instrumentation: verify no instrumentation if exception occurs" time="0.006574379">
69
+ </testcase>
70
+ </testsuite>
71
+ </testsuites>