@autofleet/rabbit 3.0.1-alpha8 → 3.0.1-beta
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/dist/index.js +11 -3
- package/dist/lib/consts.d.ts +1 -0
- package/dist/lib/consts.js +1 -0
- package/dist/lib/types.d.ts +1 -0
- package/package.json +2 -2
- package/src/index.ts +11 -3
- package/src/lib/consts.ts +1 -0
- package/src/lib/types.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -321,7 +321,7 @@ class RabbitMq {
|
|
|
321
321
|
async consumeFromRabbit(queue, callback, options) {
|
|
322
322
|
const optionsWithDefaults = { ...consts_1.DEFAULT_OPTIONS, ...options };
|
|
323
323
|
RabbitMq.validateName('queue', queue);
|
|
324
|
-
const { limit, deadMessageTtl, useConsumeWithLock, lockTimeout, auditContext, } = optionsWithDefaults;
|
|
324
|
+
const { limit, deadMessageTtl, useConsumeWithLock, lockTimeout, auditContext, enableRabbitTrace, } = optionsWithDefaults;
|
|
325
325
|
if (useConsumeWithLock) {
|
|
326
326
|
if (!this.redisLock) {
|
|
327
327
|
throw new Error('Usage of consumeWithLock requires RedisInstance');
|
|
@@ -338,12 +338,20 @@ class RabbitMq {
|
|
|
338
338
|
}
|
|
339
339
|
const traceId = msg.properties.headers[consts_1.TRACING_HEADER];
|
|
340
340
|
const userId = msg.properties.headers[consts_1.USER_TRACING_HEADER];
|
|
341
|
+
logger_1.default.info('rabbit: consume', { traceId, userId, enableRabbitTrace });
|
|
341
342
|
if (traceId) {
|
|
342
343
|
const trace = zehut_1.newTrace(zehut_1.traceTypes.RABBIT);
|
|
343
344
|
trace?.context?.set(consts_1.TRACING_HEADER, traceId);
|
|
344
345
|
}
|
|
345
|
-
else if (userId &&
|
|
346
|
-
|
|
346
|
+
else if (userId && enableRabbitTrace) {
|
|
347
|
+
try {
|
|
348
|
+
await zehut_1.setRabbitTrace(userId);
|
|
349
|
+
}
|
|
350
|
+
catch (e) {
|
|
351
|
+
logger_1.default.error('rabbit: failed to setRabbitTrace', { userId, e });
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
if (auditContext) {
|
|
347
355
|
auditContext(queue);
|
|
348
356
|
}
|
|
349
357
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
package/dist/lib/consts.d.ts
CHANGED
package/dist/lib/consts.js
CHANGED
package/dist/lib/types.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export interface ConsumeOptions {
|
|
|
18
18
|
lockTimeout?: number;
|
|
19
19
|
useConsumeWithLock?: boolean;
|
|
20
20
|
auditContext?: any;
|
|
21
|
+
enableRabbitTrace?: boolean;
|
|
21
22
|
}
|
|
22
23
|
export declare type CallbackFunction = (msg: ConsumeMessage, ack: any, nack: any) => Promise<any>;
|
|
23
24
|
export declare type newChannelOpts = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/rabbit",
|
|
3
|
-
"version": "3.0.1-
|
|
3
|
+
"version": "3.0.1-beta",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@autofleet/logger": "^1.2.8",
|
|
19
|
-
"@autofleet/zehut": "^3.0.1-
|
|
19
|
+
"@autofleet/zehut": "^3.0.1-beta",
|
|
20
20
|
"@types/amqplib": "0.8.2",
|
|
21
21
|
"@types/uuid": "^8.3.3",
|
|
22
22
|
"amqp-connection-manager": "4.1.9",
|
package/src/index.ts
CHANGED
|
@@ -461,7 +461,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
461
461
|
const optionsWithDefaults = { ...DEFAULT_OPTIONS, ...options };
|
|
462
462
|
RabbitMq.validateName('queue', queue);
|
|
463
463
|
const {
|
|
464
|
-
limit, deadMessageTtl, useConsumeWithLock, lockTimeout, auditContext,
|
|
464
|
+
limit, deadMessageTtl, useConsumeWithLock, lockTimeout, auditContext, enableRabbitTrace,
|
|
465
465
|
} = optionsWithDefaults;
|
|
466
466
|
if (useConsumeWithLock) {
|
|
467
467
|
if (!this.redisLock) {
|
|
@@ -482,11 +482,19 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
482
482
|
|
|
483
483
|
const traceId = msg.properties.headers[TRACING_HEADER];
|
|
484
484
|
const userId = msg.properties.headers[USER_TRACING_HEADER];
|
|
485
|
+
logger.info('rabbit: consume', { traceId, userId, enableRabbitTrace });
|
|
485
486
|
if (traceId) {
|
|
486
487
|
const trace = newTrace(traceTypes.RABBIT);
|
|
487
488
|
(trace as any)?.context?.set(TRACING_HEADER, traceId);
|
|
488
|
-
} else if (userId &&
|
|
489
|
-
|
|
489
|
+
} else if (userId && enableRabbitTrace) {
|
|
490
|
+
try {
|
|
491
|
+
await setRabbitTrace(userId);
|
|
492
|
+
} catch (e) {
|
|
493
|
+
logger.error('rabbit: failed to setRabbitTrace', { userId, e });
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
if (auditContext) {
|
|
490
498
|
auditContext(queue);
|
|
491
499
|
}
|
|
492
500
|
|
package/src/lib/consts.ts
CHANGED
package/src/lib/types.ts
CHANGED