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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hrithik.Security.Correlation" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hrithik.Security.Correlation" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Hrithik.Security.Correlation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Hrithik.Security.Correlation --version 1.0.0
                    
#r "nuget: Hrithik.Security.Correlation, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Hrithik.Security.Correlation@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Hrithik.Security.Correlation&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Hrithik.Security.Correlation&version=1.0.0
                    
Install as a Cake Tool

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:

Support is entirely optional and helps sustain ongoing development and maintenance.


This package is part of the Hrithik.Security ecosystem:

  • Hrithik.Security.ApiKeyManagement
    API key generation, storage, and scope-based authorization

  • Hrithik.Security.RequestSigning
    HMAC-based request signing for tamper-proof APIs

  • Hrithik.Security.ReplayProtection
    Short-window replay attack prevention

  • Hrithik.Security.RateLimiting
    Flexible, API-key–aware rate limiting for ASP.NET Core APIs

  • Hrithik.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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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