taist 0.1.6 → 0.1.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/instrument.js +3 -1
- package/lib/trace-reporter.js +10 -2
- package/package.json +1 -1
- package/types/instrument.d.ts +22 -0
package/instrument.js
CHANGED
|
@@ -46,7 +46,8 @@ import {
|
|
|
46
46
|
instrumentDirectory,
|
|
47
47
|
instrumentModules,
|
|
48
48
|
wrapWithContext,
|
|
49
|
-
instrumentClassWithContext
|
|
49
|
+
instrumentClassWithContext,
|
|
50
|
+
instrumentModule
|
|
50
51
|
} from './lib/instrument-all.js';
|
|
51
52
|
|
|
52
53
|
// Initialize global reporter for cross-process trace collection
|
|
@@ -277,6 +278,7 @@ export {
|
|
|
277
278
|
instrumentAll,
|
|
278
279
|
instrumentDirectory,
|
|
279
280
|
instrumentModules,
|
|
281
|
+
instrumentModule,
|
|
280
282
|
wrapWithContext,
|
|
281
283
|
startTrace,
|
|
282
284
|
getContext,
|
package/lib/trace-reporter.js
CHANGED
|
@@ -30,6 +30,7 @@ export class TraceReporter extends EventEmitter {
|
|
|
30
30
|
this.flushTimer = null;
|
|
31
31
|
this.workerId = options.workerId || process.pid;
|
|
32
32
|
this.closed = false;
|
|
33
|
+
this.shuttingDown = false; // Prevents race between shutdown signal and SIGTERM
|
|
33
34
|
|
|
34
35
|
logger.debug("[reporter] Created with socketPath:", this.socketPath);
|
|
35
36
|
|
|
@@ -41,7 +42,12 @@ export class TraceReporter extends EventEmitter {
|
|
|
41
42
|
|
|
42
43
|
_setupExitHandlers() {
|
|
43
44
|
const cleanup = (signal) => {
|
|
44
|
-
logger.debug("[reporter] Cleanup triggered by:", signal, "buffer size:", this.buffer.length);
|
|
45
|
+
logger.debug("[reporter] Cleanup triggered by:", signal, "buffer size:", this.buffer.length, "shuttingDown:", this.shuttingDown);
|
|
46
|
+
// If shutdown signal handler is already handling graceful shutdown, don't interfere
|
|
47
|
+
if (this.shuttingDown) {
|
|
48
|
+
logger.debug("[reporter] Shutdown already in progress, skipping cleanup");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
45
51
|
if (!this.closed) {
|
|
46
52
|
this.flushSync();
|
|
47
53
|
this.close();
|
|
@@ -155,8 +161,10 @@ export class TraceReporter extends EventEmitter {
|
|
|
155
161
|
* Flushes buffer and waits for data to be sent before closing.
|
|
156
162
|
*/
|
|
157
163
|
_handleShutdown() {
|
|
158
|
-
if (this.closed) return;
|
|
164
|
+
if (this.closed || this.shuttingDown) return;
|
|
159
165
|
|
|
166
|
+
// Set flag immediately to prevent exit handlers from interfering
|
|
167
|
+
this.shuttingDown = true;
|
|
160
168
|
this._stopFlushTimer();
|
|
161
169
|
|
|
162
170
|
// Flush and wait for data to be sent
|
package/package.json
CHANGED
package/types/instrument.d.ts
CHANGED
|
@@ -199,6 +199,28 @@ export declare function instrumentModules(
|
|
|
199
199
|
options?: InstrumentAllOptions
|
|
200
200
|
): Promise<Record<string, unknown>>;
|
|
201
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Instrument all exports from a module object
|
|
204
|
+
*
|
|
205
|
+
* Wraps all function exports with context-aware tracing.
|
|
206
|
+
* Classes are wrapped so new instances are automatically instrumented.
|
|
207
|
+
*
|
|
208
|
+
* @param moduleExports Module exports object (e.g., from `import * as mod from './mod.js'`)
|
|
209
|
+
* @param moduleName Module name prefix for trace names
|
|
210
|
+
* @returns Object with same keys but instrumented values
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* import { instrumentModule } from 'taist/instrument';
|
|
214
|
+
* import * as orderServices from './services/order.js';
|
|
215
|
+
*
|
|
216
|
+
* export const Order = instrumentModule(orderServices, 'Order');
|
|
217
|
+
* // All functions in Order will now be traced
|
|
218
|
+
*/
|
|
219
|
+
export declare function instrumentModule<T extends Record<string, unknown>>(
|
|
220
|
+
moduleExports: T,
|
|
221
|
+
moduleName: string
|
|
222
|
+
): T;
|
|
223
|
+
|
|
202
224
|
/**
|
|
203
225
|
* Wrap a function with trace context
|
|
204
226
|
* @param fn Function to wrap
|