taist 0.2.1 → 0.2.2
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 +20 -1
- package/package.json +1 -1
package/instrument.js
CHANGED
|
@@ -165,6 +165,7 @@ export function instrumentExpress(app, options = {}) {
|
|
|
165
165
|
|
|
166
166
|
// Add early middleware to set up correlation ID for ALL requests
|
|
167
167
|
// This runs before any route handlers or other middleware
|
|
168
|
+
const debug = process.env.TAIST_DEBUG === 'true';
|
|
168
169
|
app.use((req, res, next) => {
|
|
169
170
|
// Only set up if not already set (avoid double-instrumentation)
|
|
170
171
|
if (!req.taistCorrelationId) {
|
|
@@ -172,10 +173,19 @@ export function instrumentExpress(app, options = {}) {
|
|
|
172
173
|
req.taistCorrelationId = correlationId;
|
|
173
174
|
setCorrelationId(correlationId);
|
|
174
175
|
|
|
176
|
+
if (debug) {
|
|
177
|
+
logger.log('[taist middleware] Set correlationId:', correlationId, 'for', req.method, req.path);
|
|
178
|
+
}
|
|
179
|
+
|
|
175
180
|
// Clear correlation ID when response finishes
|
|
176
181
|
res.on('finish', () => {
|
|
182
|
+
if (debug) {
|
|
183
|
+
logger.log('[taist middleware] Clearing correlationId for', req.method, req.path);
|
|
184
|
+
}
|
|
177
185
|
clearCorrelationId();
|
|
178
186
|
});
|
|
187
|
+
} else if (debug) {
|
|
188
|
+
logger.log('[taist middleware] Already has correlationId:', req.taistCorrelationId, 'for', req.method, req.path);
|
|
179
189
|
}
|
|
180
190
|
next();
|
|
181
191
|
});
|
|
@@ -347,7 +357,16 @@ export function instrumentServiceWithContext(service, name) {
|
|
|
347
357
|
* };
|
|
348
358
|
*/
|
|
349
359
|
export function bridgeContext(req) {
|
|
350
|
-
const
|
|
360
|
+
const debug = process.env.TAIST_DEBUG === 'true';
|
|
361
|
+
const reqCorrelationId = req?.taistCorrelationId;
|
|
362
|
+
const fallbackCorrelationId = getCorrelationId();
|
|
363
|
+
const correlationId = reqCorrelationId || fallbackCorrelationId;
|
|
364
|
+
|
|
365
|
+
if (debug) {
|
|
366
|
+
logger.log('[bridgeContext] req.taistCorrelationId:', reqCorrelationId);
|
|
367
|
+
logger.log('[bridgeContext] getCorrelationId():', fallbackCorrelationId);
|
|
368
|
+
logger.log('[bridgeContext] using:', correlationId);
|
|
369
|
+
}
|
|
351
370
|
|
|
352
371
|
// Also set the fallback so resolvers can access it even without context prop-drilling
|
|
353
372
|
if (correlationId) {
|