diff --git a/.npmignore b/.npmignore index 2b768264..5651d133 100644 --- a/.npmignore +++ b/.npmignore @@ -1,3 +1,4 @@ .vscode node_modules -tmp \ No newline at end of file +tmp +test \ No newline at end of file diff --git a/README.md b/README.md index c57595f7..f3eadd4b 100644 --- a/README.md +++ b/README.md @@ -219,7 +219,7 @@ interface ClsMiddlewareOptions { # Request ID -Because of a shared storage, CLS is an ideal tool for tracking request (correlation) ids for the purpose of logging. This package provides an option to automatically generate request ids in the middleware and also provides a way to provide a custom ID generator function. +Because of a shared storage, CLS is an ideal tool for tracking request (correlation) ids for the purpose of logging. This package provides an option to automatically generate request ids in the middleware, if you pass `{ generateId: true }` to the middleware options. By default, the generated is a string based on `Math.random()`, but you can provide a custom function in the `idGenerator` option. This function receives the `Request` as the first parameter, which can be used in the generation process. diff --git a/src/lib/cls.interfaces.ts b/src/lib/cls.interfaces.ts index 3a724eca..ff4daf82 100644 --- a/src/lib/cls.interfaces.ts +++ b/src/lib/cls.interfaces.ts @@ -34,7 +34,8 @@ export class ClsMiddlewareOptions { /** * the function to generate request ids inside the middleware */ - idGenerator?: (req: Request) => string | Promise; + idGenerator?: (req: Request) => string | Promise = () => + Math.random().toString(36).slice(-10); /** * Whether to store the Request object to the cls