@diia-inhouse/diia-queue 14.0.10 → 14.0.11
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.
|
@@ -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 {
|
|
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:
|
|
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 };
|