@diia-inhouse/diia-queue 14.0.10 → 14.0.12

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.
@@ -20,6 +20,8 @@ declare class EventMessageHandler {
20
20
  private directReplyDone;
21
21
  private getServiceCode;
22
22
  private prepareQueueMessageError;
23
+ private resolveTraceId;
24
+ private extractTraceparentTraceId;
23
25
  }
24
26
  //#endregion
25
27
  export { EventMessageHandler };
@@ -1,7 +1,7 @@
1
1
  import { NackOptions } from "../interfaces/providers/rabbitmq/index.js";
2
2
  import "../interfaces/index.js";
3
3
  import { ApiError, ValidationError } from "@diia-inhouse/errors";
4
- import { randomUUID } from "node:crypto";
4
+ import { randomBytes } from "node:crypto";
5
5
  import { isValidTraceId, trace } from "@opentelemetry/api";
6
6
  import { utils } from "@diia-inhouse/utils";
7
7
  //#region src/services/eventMessageHandler.ts
@@ -34,9 +34,8 @@ var EventMessageHandler = class {
34
34
  });
35
35
  }
36
36
  prepareAsyncContext(properties, serviceCode) {
37
- const activeSpanTraceId = trace.getActiveSpan()?.spanContext().traceId ?? "";
38
37
  return { logData: {
39
- traceId: isValidTraceId(activeSpanTraceId) ? activeSpanTraceId : properties.headers?.traceId || randomUUID(),
38
+ traceId: this.resolveTraceId(properties),
40
39
  serviceCode
41
40
  } };
42
41
  }
@@ -107,6 +106,19 @@ var EventMessageHandler = class {
107
106
  http_code: err.getCode()
108
107
  };
109
108
  }
109
+ resolveTraceId(properties) {
110
+ const extractedTraceId = this.extractTraceparentTraceId(properties.headers?.traceparent);
111
+ if (isValidTraceId(extractedTraceId)) return extractedTraceId;
112
+ const activeSpanTraceId = trace.getActiveSpan()?.spanContext().traceId ?? "";
113
+ if (isValidTraceId(activeSpanTraceId)) return activeSpanTraceId;
114
+ return properties.headers?.traceId || randomBytes(16).toString("hex");
115
+ }
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 : "";
121
+ }
110
122
  };
111
123
  //#endregion
112
124
  export { EventMessageHandler };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diia-inhouse/diia-queue",
3
- "version": "14.0.10",
3
+ "version": "14.0.12",
4
4
  "type": "module",
5
5
  "description": "Package provide queue functionality",
6
6
  "main": "dist/index.js",