{"id":13716537,"url":"https://github.com/tafarij/micro-correlation-id","last_synced_at":"2025-05-07T05:33:23.563Z","repository":{"id":30002936,"uuid":"123468551","full_name":"tafarij/micro-correlation-id","owner":"tafarij","description":"Correlate http requests across microservices built with zeit/micro","archived":false,"fork":false,"pushed_at":"2023-10-17T22:07:37.000Z","size":640,"stargazers_count":10,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-14T04:34:50.994Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tafarij.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-03-01T17:27:50.000Z","updated_at":"2023-08-23T11:26:15.000Z","dependencies_parsed_at":"2024-01-05T23:53:58.647Z","dependency_job_id":"6dccb12b-08c4-459a-a0b5-012e8875673e","html_url":"https://github.com/tafarij/micro-correlation-id","commit_stats":{"total_commits":33,"total_committers":3,"mean_commits":11.0,"dds":"0.33333333333333337","last_synced_commit":"6affe9a0e0b61a0839f721ad53d63b0e9b692f90"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tafarij%2Fmicro-correlation-id","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tafarij%2Fmicro-correlation-id/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tafarij%2Fmicro-correlation-id/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tafarij%2Fmicro-correlation-id/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tafarij","download_url":"https://codeload.github.com/tafarij/micro-correlation-id/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252823562,"owners_count":21809705,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T00:01:11.534Z","updated_at":"2025-05-07T05:33:23.095Z","avatar_url":"https://github.com/tafarij.png","language":"JavaScript","readme":"# micro-correlation-id\n\n\u003e Correlate http requests across microservices built with [micro](https://github.com/zeit/micro).\n\nThis a [micro](https://github.com/zeit/micro) module for setting a [correlation id](https://blog.rapid7.com/2016/12/23/the-value-of-correlation-ids/) per HTTP request. The correlation id associated with a request remains consistent across async calls made within the scope of the request handler.\n\nThis module is inspired by [express-correlation-id](https://github.com/toboid/express-correlation-id) and makes use of [AsyncLocalStorage](https://nodejs.org/api/async_context.html#class-asynclocalstorage).\n\n## Installation\n\n```bash\n# npm\nnpm i -S micro-correlation-id\n\n# or yarn\nyarn add micro-correlation-id\n```\n\n## Usage\n\n```javascript\nconst { correlator, getId } = require('micro-correlation-id');\nconst assert = require('assert');\n\nmodule.exports = correlator()(async (req, res) =\u003e {\n  // These values will always be the same within this scope\n  assert.equal(req.correlationId(), getId());\n  res.end();\n});\n```\n\n## API\n\n### `correlator(idHeader='x-correlation-id')`\n\nThis creates and/or sets the correlation id on each incomming request. If the incoming request has a correlation id then that id is preserved, a new uuid is assigned otherwise. The correlation id may be accessed using `req.correlationId()` or `getId()`.\n\n`correlator` takes and optional argument `idHeader` which defaults to `x-correlation-id`. This is HTTP header key used for passing a correlation id. You may change this to your liking.\n\n### `getId()`\n\nUse this to get the current correlation id from any where within a request handler. It will always be equivalent to `req.correlationId()`.\n\n## License\n\n[MIT](LICENCE)\n","funding_links":[],"categories":["Modules"],"sub_categories":["HTTP Requests"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftafarij%2Fmicro-correlation-id","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftafarij%2Fmicro-correlation-id","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftafarij%2Fmicro-correlation-id/lists"}