@diia-inhouse/diia-queue 14.0.13 → 14.0.14

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.
@@ -32,6 +32,11 @@ type QueueConfigByQueueName = { [k in QueueName]: {
32
32
  topics: ExchangeName[];
33
33
  } };
34
34
  type QueueConfig = Record<QueueConfigType.Internal, QueueConfigByQueueName>;
35
+ /**
36
+ * Under QueueConfigType.External, each key is auto-prefixed
37
+ * with 'TopicExternal' to form the broker exchange name (e.g.
38
+ * 'Auth' → 'TopicExternalAuth'). See ExternalEventBus.
39
+ */
35
40
  type TopicConfigByConfigType = { [k in ExchangeName]: {
36
41
  events: EventName[];
37
42
  } };
@@ -21,7 +21,7 @@ declare class EventMessageHandler {
21
21
  private getServiceCode;
22
22
  private prepareQueueMessageError;
23
23
  private resolveTraceId;
24
- private extractTraceparentTraceId;
24
+ private toPropagationCarrier;
25
25
  }
26
26
  //#endregion
27
27
  export { EventMessageHandler };
@@ -2,7 +2,7 @@ import { NackOptions } from "../interfaces/providers/rabbitmq/index.js";
2
2
  import "../interfaces/index.js";
3
3
  import { ApiError, ValidationError } from "@diia-inhouse/errors";
4
4
  import { randomBytes } from "node:crypto";
5
- import { isValidTraceId, trace } from "@opentelemetry/api";
5
+ import { context, isValidTraceId, propagation, trace } from "@opentelemetry/api";
6
6
  import { utils } from "@diia-inhouse/utils";
7
7
  //#region src/services/eventMessageHandler.ts
8
8
  var EventMessageHandler = class {
@@ -107,17 +107,20 @@ var EventMessageHandler = class {
107
107
  };
108
108
  }
109
109
  resolveTraceId(properties) {
110
- const extractedTraceId = this.extractTraceparentTraceId(properties.headers?.traceparent);
110
+ const carrier = this.toPropagationCarrier(properties.headers);
111
+ const extractedTraceId = trace.getSpan(propagation.extract(context.active(), carrier))?.spanContext().traceId ?? "";
111
112
  if (isValidTraceId(extractedTraceId)) return extractedTraceId;
112
113
  const activeSpanTraceId = trace.getActiveSpan()?.spanContext().traceId ?? "";
113
114
  if (isValidTraceId(activeSpanTraceId)) return activeSpanTraceId;
114
115
  return properties.headers?.traceId || randomBytes(16).toString("hex");
115
116
  }
116
- extractTraceparentTraceId(raw) {
117
- if (raw === void 0 || raw === null) return "";
118
- const [version, traceId] = (Buffer.isBuffer(raw) ? raw.toString("utf8") : raw).split("-");
119
- if (version !== "00" || !traceId) return "";
120
- return isValidTraceId(traceId) ? traceId : "";
117
+ toPropagationCarrier(headers) {
118
+ const carrier = {};
119
+ for (const [key, value] of Object.entries(headers ?? {})) {
120
+ if (value === void 0 || value === null) continue;
121
+ carrier[key] = Buffer.isBuffer(value) ? value.toString("utf8") : String(value);
122
+ }
123
+ return carrier;
121
124
  }
122
125
  };
123
126
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diia-inhouse/diia-queue",
3
- "version": "14.0.13",
3
+ "version": "14.0.14",
4
4
  "type": "module",
5
5
  "description": "Package provide queue functionality",
6
6
  "main": "dist/index.js",