Hrithik.Security.Correlation
1.0.0
dotnet add package Hrithik.Security.Correlation --version 1.0.0
NuGet\Install-Package Hrithik.Security.Correlation -Version 1.0.0
<PackageReference Include="Hrithik.Security.Correlation" Version="1.0.0" />
<PackageVersion Include="Hrithik.Security.Correlation" Version="1.0.0" />
<PackageReference Include="Hrithik.Security.Correlation" />
paket add Hrithik.Security.Correlation --version 1.0.0
#r "nuget: Hrithik.Security.Correlation, 1.0.0"
#:package Hrithik.Security.Correlation@1.0.0
#addin nuget:?package=Hrithik.Security.Correlation&version=1.0.0
#tool nuget:?package=Hrithik.Security.Correlation&version=1.0.0
Hrithik.Security.Correlation
A lightweight, secure, and enterprise-ready Correlation ID library for .NET applications.
Hrithik.Security.Correlation provides automatic correlation ID generation, validation, propagation, and logging enrichment for distributed systemsβwithout the overhead of full tracing frameworks.
β¨ Features
π Automatic Correlation ID management
π ASP.NET Core middleware
π€ Outgoing HTTP propagation (HttpClient)
π§΅ Async-safe context (AsyncLocal)
π Logging enrichment (ILogger scopes)
π Optional strict validation
βοΈ Fully configurable
π§© Minimal dependencies
π¦ Installation dotnet add package Hrithik.Security.Correlation
Optional integrations:
dotnet add package Hrithik.Security.Correlation.AspNetCore dotnet add package Hrithik.Security.Correlation.Http dotnet add package Hrithik.Security.Correlation.Logging
π§ Why Correlation IDs?
In distributed systems:
One user request β many services
Logs become impossible to trace
Debugging production issues is painful
A Correlation ID solves this by attaching a single identifier to a request across:
APIs
Downstream services
Logs
Exceptions
π Quick Start 1οΈβ£ Register Services builder.Services.AddCorrelation(options β { options.HeaderName = "X-Correlation-Id"; options.GenerateIfMissing = true; options.StrictValidation = true; });
2οΈβ£ Enable Middleware app.UseCorrelation();
This will:
Read correlation ID from request headers
Generate one if missing
Validate format
Attach it to the response headers
3οΈβ£ Access Correlation ID Anywhere public class OrderService { private readonly ICorrelationContext _correlation;
public OrderService(ICorrelationContext correlation)
{
_correlation = correlation;
}
public void Process()
{
Console.WriteLine(_correlation.CorrelationId);
}
}
π HTTP Client Propagation
Automatically propagate the same correlation ID to downstream services.
builder.Services.AddHttpClient("DownstreamApi") .AddHttpMessageHandler<CorrelationDelegatingHandler>();
Outgoing requests will include:
X-Correlation-Id: <same-id>
π Logging Integration
Enrich logs with correlation ID using logging scopes.
using (_logger.BeginCorrelationScope(_correlationContext)) { _logger.LogInformation("Processing request"); }
Example log output:
{ "Message": "Processing request", "CorrelationId": "a9b12c1e5f9a4b5b9a9d0e1f8b3d2a1c" }
βοΈ Configuration Options Option Default Description HeaderName X-Correlation-Id Header used for correlation GenerateIfMissing true Generate ID if missing StrictValidation false Enforce validation MaxLength 64 Maximum allowed length π Security Considerations
Prevents header spoofing (optional)
Limits correlation ID length
Rejects invalid incoming requests
Designed for zero-trust environments
π§© Package Structure Hrithik.Security.Correlation βββ Abstractions βββ Core βββ AspNetCore βββ Http βββ Logging
Each module can be used independently.
π Alternatives Solution Drawbacks Custom middleware Reinvented in every project OpenTelemetry Heavy & complex DIY logging No propagation
Hrithik.Security.Correlation focuses on one thing and does it well.
π£ Roadmap
gRPC interceptor
Serilog enricher
Azure Functions support
W3C traceparent compatibility
OpenTelemetry bridge
π€ Contributing
Contributions, issues, and feature requests are welcome.
π License
MIT License
π€ Author
Hrithik Kalra
.NET | API Security | Fintech Systems
π§ Email: hrithikkalra11@gmail.com
GitHub: https://github.com/hrithikalra
LinkedIn: https://www.linkedin.com/in/hrithik-kalra-b6836a246/
If you find this package useful, consider supporting its development:
- β Buy Me a Coffee: https://www.buymeacoffee.com/alkylhalid9
- β€οΈ GitHub Sponsors: https://github.com/sponsors/hrithikalra
Support is entirely optional and helps sustain ongoing development and maintenance.
π Related Packages
This package is part of the Hrithik.Security ecosystem:
Hrithik.Security.ApiKeyManagement
API key generation, storage, and scope-based authorizationHrithik.Security.RequestSigning
HMAC-based request signing for tamper-proof APIsHrithik.Security.ReplayProtection
Short-window replay attack preventionHrithik.Security.RateLimiting
Flexible, API-keyβaware rate limiting for ASP.NET Core APIsHrithik.Security.Idempotency Idempotency-keyβbased protection for safe retries in financial APIs
Hrithik.Security.Jose JWT and JWS utilities for secure token handling and message signing
Hrithik.Security.AuditLogging Compliance-grade, tamper-evident audit logging for .NET APIs
Hrithik.Security.Headers Strongly-typed and validated security HTTP headers for ASP.NET Core.
Together, they form a complete API security framework.
These packages are independent and can be used together or individually.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.9)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.2)
- Microsoft.Extensions.Logging (>= 10.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 131 | 2/9/2026 |