generateTraceId function in Motia codebase.
In this article, we review generateTraceId function in Motia codebase. We will look at:
-
generateTraceId fn definition.
-
Usage in Motia codebase.
Press enter or click to view image in full size
generateTraceId fn definition
In motia/packages/core/generate-trace-id.ts, you will find the following code:
export const generateTraceId = () => {
const datePart = String(Date.now()).slice(6)
const randomPart = generateCode(5)
return `${randomPart}-${datePart}`
}
There’s datePart and randomPart. You will find the generateCode defined in the same file:
export const generateCode = (length = 6) => {
const chars = 'ABCDEFGHJKMNPQRSTUVWXYZ123456789'
return Array.from({ length }, () => chars[Math.floor(Math.random() * chars.length)]).join('')
}
TraceID is a combination of random part and date part.
Usage in Motia codebase
You will find 4 references in the Motia codebase (There could be more).
Press enter or click to view image in full size
About me:
Hey, my name is Ramu Narasinga. I study codebase architecture in large open-source projects.
Email: ramu.narasinga@gmail.com
Want to learn from open-source? Solve challenges inspired by open-source projects.
References:
-
https://github.com/MotiaDev/motia/blob/main/packages/core/src/generate-trace-id.ts
-
https://github.com/MotiaDev/motia/blob/main/packages/core/src/cron-handler.ts#L3
-
https://github.com/MotiaDev/motia/blob/main/packages/core/src/server.ts#L12