@ogcio/o11y-sdk-node 0.1.0-beta.12 → 0.1.0-beta.13

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.0-beta.13](https://github.com/ogcio/o11y/compare/@ogcio/o11y-sdk-node@v0.1.0-beta.12...@ogcio/o11y-sdk-node@v0.1.0-beta.13) (2025-06-16)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **sdk-node:** allow graceful shutdown of instrumentation on SIGTERM AB[#28329](https://github.com/ogcio/o11y/issues/28329) ([#151](https://github.com/ogcio/o11y/issues/151)) ([991ee15](https://github.com/ogcio/o11y/commit/991ee1559898b721823cb9d1e0490e2ad82e6d0a))
9
+
3
10
  ## [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
11
 
5
12
 
@@ -1,3 +1,4 @@
1
+ import process from "process";
1
2
  import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";
2
3
  import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
3
4
  import { W3CTraceContextPropagator } from "@opentelemetry/core";
@@ -60,6 +61,16 @@ export default async function buildNodeInstrumentation(config) {
60
61
  });
61
62
  sdk.start();
62
63
  console.log("NodeJS OpenTelemetry instrumentation started successfully.");
64
+ process.on("SIGTERM", async () => {
65
+ try {
66
+ // Flushing before shutdown is implemented on a per-exporter basis.
67
+ await sdk.shutdown();
68
+ console.log("NodeJS OpenTelemetry instrumentation shutdown successfully");
69
+ }
70
+ catch (error) {
71
+ console.error("Error shutting down NodeJS OpenTelemetry instrumentation:", error);
72
+ }
73
+ });
63
74
  return sdk;
64
75
  }
65
76
  catch (error) {
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ogcio/o11y-sdk-node",
3
- "version": "0.1.0-beta.12",
3
+ "version": "0.1.0-beta.13",
4
4
  "description": "Opentelemetry standard instrumentation SDK for NodeJS based project",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -46,11 +46,11 @@
46
46
  "@opentelemetry/sdk-trace-base": "^2.0.1"
47
47
  },
48
48
  "devDependencies": {
49
- "@types/node": "^22.15.29",
50
- "@vitest/coverage-v8": "^3.2.1",
49
+ "@types/node": "^22.15.30",
50
+ "@vitest/coverage-v8": "^3.2.2",
51
51
  "tsx": "^4.19.4",
52
52
  "typescript": "^5.8.3",
53
- "vitest": "^3.2.1"
53
+ "vitest": "^3.2.2"
54
54
  },
55
55
  "engines": {
56
56
  "node": ">=20.6.0"
@@ -21,7 +21,7 @@ export default defineConfig({
21
21
  reporters: ["default", ["junit", { outputFile: "test-report.xml" }]],
22
22
  environment: "node",
23
23
  pool: "threads",
24
- workspace: [
24
+ projects: [
25
25
  {
26
26
  test: {
27
27
  include: ["**/test/*.test.ts", "**/test/processor/*.test.ts"],
@@ -1,3 +1,4 @@
1
+ import process from "process";
1
2
  import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";
2
3
  import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
3
4
  import { W3CTraceContextPropagator } from "@opentelemetry/core";
@@ -89,6 +90,22 @@ export default async function buildNodeInstrumentation(
89
90
 
90
91
  sdk.start();
91
92
  console.log("NodeJS OpenTelemetry instrumentation started successfully.");
93
+
94
+ process.on("SIGTERM", async () => {
95
+ try {
96
+ // Flushing before shutdown is implemented on a per-exporter basis.
97
+ await sdk.shutdown();
98
+ console.log(
99
+ "NodeJS OpenTelemetry instrumentation shutdown successfully",
100
+ );
101
+ } catch (error) {
102
+ console.error(
103
+ "Error shutting down NodeJS OpenTelemetry instrumentation:",
104
+ error,
105
+ );
106
+ }
107
+ });
108
+
92
109
  return sdk;
93
110
  } catch (error) {
94
111
  console.error(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ogcio/o11y-sdk-node",
3
- "version": "0.1.0-beta.12",
3
+ "version": "0.1.0-beta.13",
4
4
  "description": "Opentelemetry standard instrumentation SDK for NodeJS based project",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -38,11 +38,11 @@
38
38
  "@opentelemetry/sdk-trace-base": "^2.0.1"
39
39
  },
40
40
  "devDependencies": {
41
- "@types/node": "^22.15.29",
42
- "@vitest/coverage-v8": "^3.2.1",
41
+ "@types/node": "^22.15.30",
42
+ "@vitest/coverage-v8": "^3.2.2",
43
43
  "tsx": "^4.19.4",
44
44
  "typescript": "^5.8.3",
45
- "vitest": "^3.2.1"
45
+ "vitest": "^3.2.2"
46
46
  },
47
47
  "engines": {
48
48
  "node": ">=20.6.0"
@@ -1,10 +1,19 @@
1
- import { describe, test, expect, vi, beforeEach } from "vitest";
1
+ import { describe, test, expect, vi, beforeEach, afterEach } from "vitest";
2
2
  import { NodeSDKConfig } from "../index";
3
3
  import { instrumentNode } from "../index";
4
4
  import * as buildNodeInstrumentationModule from "../lib/instrumentation.node";
5
+ import { metrics } from "@opentelemetry/sdk-node";
5
6
 
6
7
  describe("instrumentNode", () => {
7
8
  beforeEach(() => {
9
+ // @ts-ignore Avoid actually running exporters at any time in tests (overriding private method)
10
+ vi.spyOn(
11
+ metrics.PeriodicExportingMetricReader.prototype,
12
+ "_doRun",
13
+ ).mockImplementation(vi.fn());
14
+ });
15
+
16
+ afterEach(() => {
8
17
  vi.restoreAllMocks();
9
18
  });
10
19
 
@@ -33,7 +42,29 @@ describe("instrumentNode", () => {
33
42
  expect(instrumentationMock).toHaveBeenCalledWith(config);
34
43
  });
35
44
 
36
- test("should not throw when called without arguments", () => {
37
- expect(instrumentNode()).resolves.not.toThrow();
45
+ test("should not throw when called without arguments", async () => {
46
+ await expect(instrumentNode()).resolves.not.toThrow();
47
+ });
48
+
49
+ test("should invoke instrumentation shutdown on SIGTERM", async () => {
50
+ const config: NodeSDKConfig = {
51
+ serviceName: "custom-service",
52
+ collectorUrl: "http://custom-collector.com",
53
+ protocol: "grpc",
54
+ resourceAttributes: {
55
+ "team.infra.cluster": "dev-01",
56
+ "team.infra.pod": "01",
57
+ "team.service.type": "fastify",
58
+ },
59
+ spanAttributes: {
60
+ "signal.namespace": "example",
61
+ "signal.number": () => "callback",
62
+ },
63
+ };
64
+
65
+ const sdk = await instrumentNode(config);
66
+ const shutdownMock = vi.spyOn(sdk, "shutdown");
67
+ process.emit("SIGTERM");
68
+ expect(shutdownMock).toHaveBeenCalled();
38
69
  });
39
70
  });
package/vitest.config.ts CHANGED
@@ -22,7 +22,7 @@ export default defineConfig({
22
22
  reporters: ["default", ["junit", { outputFile: "test-report.xml" }]],
23
23
  environment: "node",
24
24
  pool: "threads",
25
- workspace: [
25
+ projects: [
26
26
  {
27
27
  test: {
28
28
  include: ["**/test/*.test.ts", "**/test/processor/*.test.ts"],