taist 0.2.3 → 0.2.5
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/lib/trace-reporter.js +18 -6
- package/lib/transform.js +13 -2
- package/package.json +1 -1
package/lib/trace-reporter.js
CHANGED
|
@@ -247,6 +247,15 @@ export class TraceReporter extends EventEmitter {
|
|
|
247
247
|
report(trace) {
|
|
248
248
|
if (this.closed) return;
|
|
249
249
|
|
|
250
|
+
// Update socketPath from env if not set (env may be set after construction)
|
|
251
|
+
// This handles the case where vitest-reporter sets TAIST_COLLECTOR_SOCKET
|
|
252
|
+
// after the reporter was created (e.g., in bundled code loaded early)
|
|
253
|
+
if (!this.socketPath && process.env.TAIST_COLLECTOR_SOCKET) {
|
|
254
|
+
this.socketPath = process.env.TAIST_COLLECTOR_SOCKET;
|
|
255
|
+
logger.debug("[reporter] Late socketPath update from env:", this.socketPath);
|
|
256
|
+
this._setupExitHandlers();
|
|
257
|
+
}
|
|
258
|
+
|
|
250
259
|
logger.debug("[reporter] report() called:", trace.name, trace.type);
|
|
251
260
|
|
|
252
261
|
this.buffer.push(trace);
|
|
@@ -412,17 +421,20 @@ export class TraceReporter extends EventEmitter {
|
|
|
412
421
|
}
|
|
413
422
|
}
|
|
414
423
|
|
|
415
|
-
// Global reporter instance for
|
|
416
|
-
|
|
424
|
+
// Global reporter instance key for cross-module singleton
|
|
425
|
+
// Using globalThis ensures the same instance is shared even when the module
|
|
426
|
+
// is bundled separately (e.g., in Rollup/Vite builds)
|
|
427
|
+
const TAIST_REPORTER_KEY = '__taist_global_reporter__';
|
|
417
428
|
|
|
418
429
|
/**
|
|
419
|
-
* Get or create the global reporter instance
|
|
430
|
+
* Get or create the global reporter instance.
|
|
431
|
+
* Uses globalThis to ensure singleton works across bundled modules.
|
|
420
432
|
*/
|
|
421
433
|
export function getGlobalReporter(options = {}) {
|
|
422
|
-
if (!
|
|
423
|
-
|
|
434
|
+
if (!globalThis[TAIST_REPORTER_KEY]) {
|
|
435
|
+
globalThis[TAIST_REPORTER_KEY] = new TraceReporter(options);
|
|
424
436
|
}
|
|
425
|
-
return
|
|
437
|
+
return globalThis[TAIST_REPORTER_KEY];
|
|
426
438
|
}
|
|
427
439
|
|
|
428
440
|
/**
|
package/lib/transform.js
CHANGED
|
@@ -150,6 +150,15 @@ const __taist_debug = process.env.TAIST_DEBUG === 'true';
|
|
|
150
150
|
if (process.env.TAIST_COLLECTOR_SOCKET && !__taist_reporter.isConnected()) {
|
|
151
151
|
__taist_reporter.connectEager();
|
|
152
152
|
}
|
|
153
|
+
// Helper to find correlationId from GraphQL context argument (Apollo: parent, args, context, info)
|
|
154
|
+
const __taist_findCorrelationIdInArgs = (args) => {
|
|
155
|
+
for (const arg of args) {
|
|
156
|
+
if (arg && typeof arg === 'object' && arg.taistCorrelationId) {
|
|
157
|
+
return arg.taistCorrelationId;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
161
|
+
};
|
|
153
162
|
const __taist_wrap = (fn, name) => {
|
|
154
163
|
if (typeof fn !== 'function') return fn;
|
|
155
164
|
if (__taist_debug) console.log('[taist] wrapping:', name);
|
|
@@ -158,8 +167,10 @@ const __taist_wrap = (fn, name) => {
|
|
|
158
167
|
const parentCtx = __taist_getContext();
|
|
159
168
|
const id = __taist_generateId();
|
|
160
169
|
const depth = parentCtx.depth;
|
|
161
|
-
// Get correlationId
|
|
162
|
-
const
|
|
170
|
+
// Get correlationId: 1) parent context, 2) GraphQL context arg, 3) fallback global
|
|
171
|
+
const argsCorrelationId = __taist_findCorrelationIdInArgs(args);
|
|
172
|
+
const correlationId = parentCtx.correlationId || argsCorrelationId || __taist_getCorrelationId();
|
|
173
|
+
if (__taist_debug && argsCorrelationId) console.log('[taist] Found correlationId in args:', argsCorrelationId);
|
|
163
174
|
const newCtx = {
|
|
164
175
|
depth: depth + 1,
|
|
165
176
|
traceId: parentCtx.traceId || id,
|