@blaxel/telemetry 0.2.26-preview.60 → 0.2.27-dev.177

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.
@@ -26,6 +26,7 @@ declare class TelemetryManager {
26
26
  private meterProvider;
27
27
  private initialized;
28
28
  private configured;
29
+ private shuttingDown;
29
30
  constructor();
30
31
  initialize(): void;
31
32
  setConfiguration(): Promise<void>;
package/dist/telemetry.js CHANGED
@@ -62,11 +62,13 @@ class TelemetryManager {
62
62
  meterProvider;
63
63
  initialized;
64
64
  configured;
65
+ shuttingDown;
65
66
  constructor() {
66
67
  this.nodeTracerProvider = null;
67
68
  this.meterProvider = null;
68
69
  this.initialized = false;
69
70
  this.configured = false;
71
+ this.shuttingDown = false;
70
72
  }
71
73
  // This method need to stay sync to avoid non booted instrumentations
72
74
  initialize() {
@@ -123,15 +125,37 @@ class TelemetryManager {
123
125
  }
124
126
  }
125
127
  setupSignalHandler() {
126
- const signals = ["SIGINT", "SIGTERM", "uncaughtException", "exit"];
127
- for (const signal of signals) {
128
- process.on(signal, () => {
129
- this.shutdownApp().catch((error) => {
130
- core_1.logger.debug("Fatal error during shutdown:", error);
131
- process.exit(0);
128
+ const forward = (sig) => {
129
+ if (this.shuttingDown)
130
+ return;
131
+ this.shuttingDown = true;
132
+ this.shutdownApp()
133
+ .catch((error) => {
134
+ core_1.logger.debug("Fatal error during shutdown:", error);
135
+ })
136
+ .finally(() => {
137
+ try {
138
+ // Re-send the original signal to let the default handler terminate the process with the correct code
139
+ process.kill(process.pid, sig);
140
+ }
141
+ catch {
142
+ process.exit(1);
143
+ }
144
+ });
145
+ };
146
+ process.once("SIGINT", () => forward("SIGINT"));
147
+ process.once("SIGTERM", () => forward("SIGTERM"));
148
+ process.once("uncaughtException", (err) => {
149
+ core_1.logger.error("Uncaught exception:", err);
150
+ this.shutdownApp().catch((error) => {
151
+ core_1.logger.debug("Fatal error during shutdown:", error);
152
+ }).finally(() => {
153
+ // Re-throw on next tick so Node's default handler sets exit code and prints stack
154
+ setImmediate(() => {
155
+ throw (err instanceof Error ? err : new Error(String(err)));
132
156
  });
133
157
  });
134
- }
158
+ });
135
159
  }
136
160
  /**
137
161
  * Get resource attributes for OpenTelemetry.
@@ -246,11 +270,9 @@ class TelemetryManager {
246
270
  new Promise((resolve) => setTimeout(resolve, 5000)), // 5 second timeout
247
271
  ]);
248
272
  core_1.logger.debug("Instrumentation shutdown complete");
249
- process.exit(0);
250
273
  }
251
274
  catch (error) {
252
275
  core_1.logger.error("Error during shutdown:", error);
253
- process.exit(1);
254
276
  }
255
277
  }
256
278
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/telemetry",
3
- "version": "0.2.26-preview.60",
3
+ "version": "0.2.27-dev.177",
4
4
  "description": "Blaxel SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",
@@ -71,7 +71,7 @@
71
71
  "@opentelemetry/sdk-trace-base": "^2.0.0",
72
72
  "@opentelemetry/sdk-trace-node": "^2.0.0",
73
73
  "ai": "^4.3.13",
74
- "@blaxel/core": "0.2.26-preview.60"
74
+ "@blaxel/core": "0.2.27-dev.177"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@eslint/js": "^9.26.0",