{"id":20129128,"url":"https://github.com/stevejgordon/correlationid","last_synced_at":"2025-05-14T21:07:54.488Z","repository":{"id":20557578,"uuid":"90254475","full_name":"stevejgordon/CorrelationId","owner":"stevejgordon","description":"An ASP.NET Core middleware component which synchronises a correlation ID for cross API request logging.","archived":false,"fork":false,"pushed_at":"2024-04-26T16:14:00.000Z","size":137,"stargazers_count":565,"open_issues_count":33,"forks_count":105,"subscribers_count":17,"default_branch":"main","last_synced_at":"2025-04-03T03:12:07.529Z","etag":null,"topics":["asp-net-core","correlation","microservices"],"latest_commit_sha":null,"homepage":"","language":"C#","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/stevejgordon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["stevejgordon"],"custom":["https://www.buymeacoffee.com/stevejgordon"]}},"created_at":"2017-05-04T11:17:38.000Z","updated_at":"2025-03-15T18:20:07.000Z","dependencies_parsed_at":"2023-02-14T02:31:21.707Z","dependency_job_id":"b56c3f2f-f1fe-4d30-a4c5-c3eb0334e73d","html_url":"https://github.com/stevejgordon/CorrelationId","commit_stats":{"total_commits":76,"total_committers":13,"mean_commits":5.846153846153846,"dds":0.2763157894736842,"last_synced_commit":"7b647e57cf5e069290ff5b835c82b1157bbea1b3"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevejgordon%2FCorrelationId","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevejgordon%2FCorrelationId/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevejgordon%2FCorrelationId/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevejgordon%2FCorrelationId/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevejgordon","download_url":"https://codeload.github.com/stevejgordon/CorrelationId/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248166925,"owners_count":21058481,"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":["asp-net-core","correlation","microservices"],"created_at":"2024-11-13T20:32:11.534Z","updated_at":"2025-04-10T06:13:20.223Z","avatar_url":"https://github.com/stevejgordon.png","language":"C#","readme":"# Correlation ID\n\nCorrelations IDs are used in distributed applications to trace requests across multiple services. This library and package provides a lightweight correlation ID approach. When enabled, request headers are checked for a correlation ID from the consumer. If found, this correlation ID is attached to the Correlation Context which can be used to access the current correlation ID where it is required for logging etc.\n\nOptionally, this correlation ID can be attached to downstream HTTP calls made via a `HttpClient` instance created by the `IHttpClientFactory`.\n\n**NOTE: While I plan to add a few more features to this library, I believe it is close to feature complete for the scenario it was designed for. I recommend looking at [built-in tracing for .NET apps](https://devblogs.microsoft.com/aspnet/observability-asp-net-core-apps/#adding-tracing-to-a-net-core-application) for more complete and automated application tracing.**\n\n## Release Notes\n\n[Change history and release notes](https://stevejgordon.github.io/CorrelationId/releasenotes).\n\n## Supported Runtimes\n- .NET Standard 2.0+\n\n| Package | NuGet Stable | NuGet Pre-release | Downloads | Travis CI | Azure Pipelines |\n| ------- | ------------ | ----------------- | --------- | --------- | ----------------|\n| [CorrelationId](https://www.nuget.org/packages/CorrelationId/) | [![NuGet](https://img.shields.io/nuget/v/CorrelationId.svg)](https://www.nuget.org/packages/CorrelationId) | [![NuGet](https://img.shields.io/nuget/vpre/CorrelationId.svg)](https://www.nuget.org/packages/CorrelationId) | [![Nuget](https://img.shields.io/nuget/dt/CorrelationId.svg)](https://www.nuget.org/packages/CorrelationId) | [![Build Status](https://travis-ci.org/stevejgordon/CorrelationId.svg?branch=master)](https://travis-ci.org/stevejgordon/CorrelationId) | [![Build Status](https://dev.azure.com/stevejgordon/CorrelationId/_apis/build/status/stevejgordon.CorrelationId?branchName=master)](https://dev.azure.com/stevejgordon/CorrelationId/_build/latest?definitionId=1\u0026branchName=master) |\n\n## Installation\n\nYou should install [CorrelationId from NuGet](https://www.nuget.org/packages/CorrelationId/):\n\n```ps\nInstall-Package CorrelationId\n```\n\nThis command from Package Manager Console will download and install CorrelationId and all required dependencies.\n\nAll stable and some pre-release packages are available on NuGet. \n\n## Quick Start\n\n### Register with DI\n\nInside `ConfigureServices` add the required correlation ID services, with common defaults.\n\n```csharp\nservices.AddDefaultCorrelationId\n```\n\nThis registers a correlation ID provider which generates new IDs based on a random GUID.\n\n### Add the middleware\n\nRegister the middleware into the pipeline. This should occur before any downstream middleware which requires the correlation ID. Normally this will be registered very early in the middleware pipeline.\n\n```csharp\napp.UseCorrelationId();\n```\n\nWhere you need to access the correlation ID, you may request the `ICorrelationContextAccessor` from DI.\n\n```csharp\npublic class TransientClass\n{\n   private readonly ICorrelationContextAccessor _correlationContext;\n\n   public TransientClass(ICorrelationContextAccessor correlationContext)\n   {\n\t  _correlationContext = correlationContext;\n   }\n\n   ...\n}\n```\n\nSee the [sample app](https://github.com/stevejgordon/CorrelationId/tree/master/samples/3.1/MvcSample) for example usage.\n\nFull documentation can be found in the [wiki](https://github.com/stevejgordon/CorrelationId/wiki).\n\n## Known Issue with ASP.NET Core 2.2.0\n\nIt appears that a [regression in the code for ASP.NET Core 2.2.0](https://github.com/aspnet/AspNetCore/issues/5144) means that setting the TraceIdentifier on the context via middleware results in the context becoming null when accessed further down in the pipeline. A fix is was released in 2.2.2.\n\nA workaround at this time is to disable the behaviour of updating the TraceIdentifier using the options when adding the middleware.\n\n## Support\n\nIf this library has helped you, feel free to [buy me a coffee](https://www.buymeacoffee.com/stevejgordon) or see the \"Sponsor\" link [at the top of the GitHub page](https://github.com/stevejgordon/CorrelationId).\n","funding_links":["https://github.com/sponsors/stevejgordon","https://www.buymeacoffee.com/stevejgordon"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevejgordon%2Fcorrelationid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevejgordon%2Fcorrelationid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevejgordon%2Fcorrelationid/lists"}