@autofleet/rabbit 3.0.1-beta9 → 3.1.1
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 +5 -27
- package/package.json +5 -2
- package/src/index.ts +6 -29
package/dist/index.js
CHANGED
|
@@ -127,16 +127,7 @@ class RabbitMq {
|
|
|
127
127
|
const trace = zehut_1.getCurrentPayload();
|
|
128
128
|
const user = trace?.context?.get(consts_1.USER_OBJECT);
|
|
129
129
|
const traceId = trace?.context?.get(consts_1.TRACING_HEADER);
|
|
130
|
-
const outbreakTrace = zehut_1.
|
|
131
|
-
const obj = Object.fromEntries(trace?.context);
|
|
132
|
-
const jsonString = JSON.stringify(obj);
|
|
133
|
-
logger_1.default.info('getPublishOptions', {
|
|
134
|
-
traceId,
|
|
135
|
-
user,
|
|
136
|
-
traceId2: outbreakTrace?.context?.get(consts_1.TRACING_HEADER),
|
|
137
|
-
traceContextSize: trace?.context?.size,
|
|
138
|
-
jsonString,
|
|
139
|
-
});
|
|
130
|
+
const outbreakTrace = zehut_1.outbreak.getCurrentContext();
|
|
140
131
|
return {
|
|
141
132
|
timestamp: moment_1.default().unix(),
|
|
142
133
|
headers: {
|
|
@@ -349,11 +340,13 @@ class RabbitMq {
|
|
|
349
340
|
}
|
|
350
341
|
const traceId = msg.properties.headers[consts_1.TRACING_HEADER];
|
|
351
342
|
const userId = msg.properties.headers[consts_1.USER_TRACING_HEADER];
|
|
352
|
-
logger_1.default.info('rabbit: consume', { traceId, userId, enableRabbitTrace });
|
|
353
343
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
354
344
|
const releaseLock = await this.lockRedisIfNeeded(parsedMessage, optionsWithDefaults);
|
|
355
345
|
const trace = zehut_1.newTrace(zehut_1.traceTypes.RABBIT);
|
|
356
|
-
|
|
346
|
+
// setting also outbreak trace as part of legacy code
|
|
347
|
+
const outbreakTrace = zehut_1.outbreak.newTrace(zehut_1.traceTypes.RABBIT);
|
|
348
|
+
// enableRabbitTrace is a flag to protect from different flows that doesn't work with permission
|
|
349
|
+
// and we don't want to fail the flow because of it
|
|
357
350
|
if (userId && enableRabbitTrace) {
|
|
358
351
|
try {
|
|
359
352
|
await Promise.all([
|
|
@@ -366,25 +359,10 @@ class RabbitMq {
|
|
|
366
359
|
await this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }, msg, releaseLock)(msg);
|
|
367
360
|
}
|
|
368
361
|
}
|
|
369
|
-
logger_1.default.info('rabbit consume - first trace', {
|
|
370
|
-
trace,
|
|
371
|
-
outbreakTrace,
|
|
372
|
-
user: trace?.context?.get(consts_1.USER_OBJECT),
|
|
373
|
-
});
|
|
374
362
|
if (traceId) {
|
|
375
363
|
trace?.context?.set(consts_1.TRACING_HEADER, traceId);
|
|
376
364
|
outbreakTrace?.context.set(consts_1.TRACING_HEADER, traceId);
|
|
377
|
-
logger_1.default.info('rabbit consume - second trace', {
|
|
378
|
-
trace,
|
|
379
|
-
outbreakTrace,
|
|
380
|
-
user: trace?.context?.get(consts_1.USER_OBJECT),
|
|
381
|
-
traceId: trace?.context?.get(consts_1.TRACING_HEADER),
|
|
382
|
-
traceId2: outbreakTrace?.context?.get(consts_1.TRACING_HEADER),
|
|
383
|
-
});
|
|
384
365
|
}
|
|
385
|
-
logger_1.default.info('rabbit consume - third trace', {
|
|
386
|
-
trace: zehut_1.getCurrentPayload(),
|
|
387
|
-
});
|
|
388
366
|
if (auditContext) {
|
|
389
367
|
await auditContext(queue);
|
|
390
368
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/rabbit",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
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.
|
|
19
|
+
"@autofleet/zehut": "^3.0.2",
|
|
20
20
|
"@types/amqplib": "0.8.2",
|
|
21
21
|
"@types/uuid": "^8.3.3",
|
|
22
22
|
"amqp-connection-manager": "4.1.9",
|
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
"redis-lock": "^0.1.4",
|
|
28
28
|
"uuid": "^8.3.2"
|
|
29
29
|
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@autofleet/outbreak": "^0.2.1"
|
|
32
|
+
},
|
|
30
33
|
"devDependencies": {
|
|
31
34
|
"@types/jest": "^26.0.23",
|
|
32
35
|
"@typescript-eslint/eslint-plugin": "^4.8.1",
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
ConfirmChannel, ConsumeMessage, Options, Replies,
|
|
10
10
|
} from 'amqplib';
|
|
11
11
|
import {
|
|
12
|
-
getCurrentPayload, newTrace, traceTypes, createOrSetRabbitTrace,
|
|
12
|
+
getCurrentPayload, newTrace, traceTypes, createOrSetRabbitTrace, outbreak,
|
|
13
13
|
} from '@autofleet/zehut';
|
|
14
14
|
import logger from './logger';
|
|
15
15
|
import RabbitError from './lib/rabbitError';
|
|
@@ -115,16 +115,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
115
115
|
const trace = getCurrentPayload();
|
|
116
116
|
const user = trace?.context?.get(USER_OBJECT);
|
|
117
117
|
const traceId = trace?.context?.get(TRACING_HEADER);
|
|
118
|
-
const outbreakTrace =
|
|
119
|
-
const obj = Object.fromEntries(trace?.context);
|
|
120
|
-
const jsonString = JSON.stringify(obj);
|
|
121
|
-
logger.info('getPublishOptions', {
|
|
122
|
-
traceId,
|
|
123
|
-
user,
|
|
124
|
-
traceId2: outbreakTrace?.context?.get(TRACING_HEADER),
|
|
125
|
-
traceContextSize: trace?.context?.size,
|
|
126
|
-
jsonString,
|
|
127
|
-
});
|
|
118
|
+
const outbreakTrace = outbreak.getCurrentContext();
|
|
128
119
|
return {
|
|
129
120
|
timestamp: moment().unix(),
|
|
130
121
|
headers: {
|
|
@@ -493,11 +484,13 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
493
484
|
|
|
494
485
|
const traceId = msg.properties.headers[TRACING_HEADER];
|
|
495
486
|
const userId = msg.properties.headers[USER_TRACING_HEADER];
|
|
496
|
-
logger.info('rabbit: consume', { traceId, userId, enableRabbitTrace });
|
|
497
487
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
498
488
|
const releaseLock = await this.lockRedisIfNeeded(parsedMessage, optionsWithDefaults);
|
|
499
489
|
const trace = newTrace(traceTypes.RABBIT);
|
|
500
|
-
|
|
490
|
+
// setting also outbreak trace as part of legacy code
|
|
491
|
+
const outbreakTrace = outbreak.newTrace(traceTypes.RABBIT);
|
|
492
|
+
// enableRabbitTrace is a flag to protect from different flows that doesn't work with permission
|
|
493
|
+
// and we don't want to fail the flow because of it
|
|
501
494
|
if (userId && enableRabbitTrace) {
|
|
502
495
|
try {
|
|
503
496
|
await Promise.all([
|
|
@@ -510,27 +503,11 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
510
503
|
}
|
|
511
504
|
}
|
|
512
505
|
|
|
513
|
-
logger.info('rabbit consume - first trace', {
|
|
514
|
-
trace,
|
|
515
|
-
outbreakTrace,
|
|
516
|
-
user: trace?.context?.get(USER_OBJECT),
|
|
517
|
-
});
|
|
518
|
-
|
|
519
506
|
if (traceId) {
|
|
520
507
|
(trace as any)?.context?.set(TRACING_HEADER, traceId);
|
|
521
508
|
(outbreakTrace as any)?.context.set(TRACING_HEADER, traceId);
|
|
522
|
-
logger.info('rabbit consume - second trace', {
|
|
523
|
-
trace,
|
|
524
|
-
outbreakTrace,
|
|
525
|
-
user: trace?.context?.get(USER_OBJECT),
|
|
526
|
-
traceId: trace?.context?.get(TRACING_HEADER),
|
|
527
|
-
traceId2: outbreakTrace?.context?.get(TRACING_HEADER),
|
|
528
|
-
});
|
|
529
509
|
}
|
|
530
510
|
|
|
531
|
-
logger.info('rabbit consume - third trace', {
|
|
532
|
-
trace: getCurrentPayload(),
|
|
533
|
-
});
|
|
534
511
|
if (auditContext) {
|
|
535
512
|
await auditContext(queue);
|
|
536
513
|
}
|