{"id":27273553,"url":"https://github.com/nmakhmutov/elwark.correlationid","last_synced_at":"2026-04-10T06:01:46.084Z","repository":{"id":65509331,"uuid":"284504822","full_name":"nmakhmutov/Elwark.CorrelationId","owner":"nmakhmutov","description":"This specific library offers a lightweight approach to implementing Correlation Ids for ASP.NET","archived":false,"fork":false,"pushed_at":"2024-03-01T04:37:02.000Z","size":60,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T15:55:29.567Z","etag":null,"topics":["correlation","csharp","dotnet","dotnet-core","grpc","grpc-client","grpc-server","http","http-client","http-server"],"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/nmakhmutov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-02T17:02:43.000Z","updated_at":"2024-06-17T03:12:45.000Z","dependencies_parsed_at":"2023-02-18T03:16:03.246Z","dependency_job_id":null,"html_url":"https://github.com/nmakhmutov/Elwark.CorrelationId","commit_stats":null,"previous_names":["nmakhmutov/elwark.people.abstractions"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmakhmutov%2FElwark.CorrelationId","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmakhmutov%2FElwark.CorrelationId/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmakhmutov%2FElwark.CorrelationId/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmakhmutov%2FElwark.CorrelationId/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nmakhmutov","download_url":"https://codeload.github.com/nmakhmutov/Elwark.CorrelationId/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248427780,"owners_count":21101771,"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":["correlation","csharp","dotnet","dotnet-core","grpc","grpc-client","grpc-server","http","http-client","http-server"],"created_at":"2025-04-11T14:58:19.209Z","updated_at":"2026-03-06T09:06:30.906Z","avatar_url":"https://github.com/nmakhmutov.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Elwark Correlation Id\n\nA Correlation Id is a tool used in distributed systems to trace requests across multiple services. This specific library\noffers a lightweight approach to implementing Correlation Ids. When enabled, it checks for the presence of a Correlation\nId in request headers and attaches it to the Correlation Context, which can then be used for logging and other purposes.\nAdditionally, this Correlation Id can also be attached to downstream HTTP calls made through an `IHttpClientFactory`.\nHowever, it should be noted that this library may not be fully comprehensive and that built-in tracing options for .NET\napps\nmay be more suitable for more extensive tracing needs.\n\n## Installation\n\nYou should install [Elwark.CorrelationId](https://www.nuget.org/packages/Elwark.CorrelationId) from NuGet:\n\n```ps\nInstall-Package Elwark.CorrelationId\n```\n\n[![NuGet](https://img.shields.io/nuget/v/Elwark.CorrelationId.svg)](https://www.nuget.org/packages/Elwark.CorrelationId)\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.AddCorrelationId()\n```\n\nor you can define with options\n\n```csharp\nservices.AddCorrelationId(options =\u003e\n{ \n    options.AddToLoggingScope = true;\n    options.EnforceHeader = true;\n    options.IgnoreRequestHeader = false;\n    options.IncludeInResponse = true;\n    options.RequestHeader = \"X-Correlation-Id\";\n    options.ResponseHeader = \"X-Correlation-Id\";\n    options.UpdateTraceIdentifier = false;\n});\n```\n\nThis registers a correlation id provider which generates new ids based on a random GUID.\n\n## Minimal API / MVC\n\nYou should install [Elwark.CorrelationId.Http](https://www.nuget.org/packages/Elwark.CorrelationId.Http) from NuGet:\n\n```ps\nInstall-Package Elwark.CorrelationId.Http\n```\n\n[![NuGet](https://img.shields.io/nuget/v/Elwark.CorrelationId.Http.svg)](https://www.nuget.org/packages/Elwark.CorrelationId.Http)\n\n### Add the middleware\n\nRegister the middleware into the pipeline. This should occur before any downstream middleware which requires the\ncorrelation ID. Normally this will be registered very early in the middleware pipeline.\n\n```csharp\napp.UseCorrelationId();\n```\n\nAlso Elwark.CorrelationId.Http contains TraceIdentifier Correlation id provider. You can replace GUID provider by\nTraceId just following code:\n\n```csharp\nservices.AddCorrelationId()\n   .WithTraceIdentifierProvider();\n```\n\nAfter your correlation id will be trace identifier from HttpContext.\n\n### Add HttpClient forwarding\n\nForwarding your correlation id to another service by http call available by adding:\n\n```csharp\nbuilder.Services\n    .AddHttpClient\u003cITestClient, TestClient\u003e()\n    .AddHttpCorrelationIdForwarding();\n```\n\n## gRPC\n\nYou should install [Elwark.CorrelationId.Grpc](https://www.nuget.org/packages/Elwark.CorrelationId.Grpc) from NuGet:\n\n```ps\nInstall-Package Elwark.CorrelationId.Grpc\n```\n\n[![NuGet](https://img.shields.io/nuget/v/Elwark.CorrelationId.Grpc.svg)](https://www.nuget.org/packages/Elwark.CorrelationId.Grpc)\n\n### Add the interceptor\n\nRegister the interceptor into the pipeline.\n\n```csharp\nbuilder.Services\n    .AddGrpc(options =\u003e options.UseCorrelationId());\n```\n\n### Add GrpcClient forwarding\n\nForwarding your correlation id to another service by gRPC call available by adding:\n\n```csharp\nbuilder.Services\n    .AddGrpcClient\u003cGreeter.GreeterClient\u003e()\n    .AddGrpcCorrelationIdForwarding();\n```\n\nor\n\n```csharp\nbuilder.Services\n    .AddGrpcClient\u003cGreeter.GreeterClient\u003e(options =\u003e\n    {\n        options.AddCorrelationIdForwarding();\n    });\n```\n\nWhere you need to access the correlation Id, you may request the `ICorrelationContextAccessor` from DI.\n\n```csharp\npublic class MyClass\n{\n   private readonly ICorrelationContextAccessor _accessor;\n\n   public MyClass(ICorrelationContextAccessor accessor)\n   {\n\t  _accessor = accessor;\n   }\n\n   ...\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnmakhmutov%2Felwark.correlationid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnmakhmutov%2Felwark.correlationid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnmakhmutov%2Felwark.correlationid/lists"}