Anarchy.Toolkit.Infrastructure.CorrelationId 3.1.0

dotnet add package Anarchy.Toolkit.Infrastructure.CorrelationId --version 3.1.0
                    
NuGet\Install-Package Anarchy.Toolkit.Infrastructure.CorrelationId -Version 3.1.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="Anarchy.Toolkit.Infrastructure.CorrelationId" Version="3.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Anarchy.Toolkit.Infrastructure.CorrelationId" Version="3.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Anarchy.Toolkit.Infrastructure.CorrelationId" />
                    
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 Anarchy.Toolkit.Infrastructure.CorrelationId --version 3.1.0
                    
#r "nuget: Anarchy.Toolkit.Infrastructure.CorrelationId, 3.1.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 Anarchy.Toolkit.Infrastructure.CorrelationId@3.1.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=Anarchy.Toolkit.Infrastructure.CorrelationId&version=3.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Anarchy.Toolkit.Infrastructure.CorrelationId&version=3.1.0
                    
Install as a Cake Tool

Anarchy.Toolkit.Infrastructure.CorrelationId

Part of Anarchy I/O Toolkit, a .NET developer platform · Pillar: Infrastructure · Layer: Infrastructure · Package catalog

Provider-neutral correlation and attempt ID propagation for ASP.NET Core services, workers and message consumers.

dotnet add package Anarchy.Toolkit.Infrastructure.CorrelationId
  • Access IDs through the async-flowing CorrelationContext.
  • Add UseCorrelationId() to the ASP.NET Core pipeline; headers default to X-Correlation-Id and X-Attempt-Id and are configurable.
  • Correlation and attempt IDs are added to standard ILogger scopes and the current Activity as tags, so logging and tracing providers can consume them without a Serilog dependency.
  • Use CorrelationContext.BeginScope() in workers and message consumers to set IDs and open the same provider-neutral scope for an operation.

When to use it

Use correlation and attempt IDs to connect log events and traces from the same request or retry across service boundaries. The package provides inbound HTTP middleware and a helper for non-HTTP entry points; it does not automatically configure every outgoing HTTP client or message publisher to forward IDs.

How to use it

  1. Register ModuleCorrelationId with the application's configuration and environment. Pass a CorrelationIdOptions factory to customize header names, log property names or missing-header behavior.
  2. Add UseCorrelationId() early enough in the ASP.NET Core pipeline for later middleware and endpoints to see the context.
  3. Use CorrelationContext.BeginScope(logger, correlationId, attemptId) around worker or message-consumer work. It sets the async-flowing context, opens a standard logging scope and adds tags to the current activity.

To forward the ids on outgoing HTTP calls, add the handler to the client: services.AddHttpClient("orders").AddCorrelationId(). CorrelationIdHandler writes the ambient ids with the configured header names, skips empty values and headers the request already carries, and removes what it added when the call completes. OutgoingAttemptId is Forward (the ambient attempt id, the default) or NewPerCall (a new attempt id on every send, even without an ambient context): add the handler after a retry handler for a new attempt id per retry, before it to share one.

The options, by name: CorrelationIdHeaderName and AttemptIdHeaderName (headers, default X-Correlation-Id and X-Attempt-Id), CorrelationIdPropertyName and AttemptIdPropertyName (log scope properties and activity tags, default CorrelationId and AttemptId), the message attribute names below, Behavior (missing incoming header) and OutgoingAttemptId. Every part of this package reads these names; the Serilog Enrich.WithCorrelationId(correlationIdPropertyName, attemptIdPropertyName) enricher takes the property names as arguments, so pass the same ones. No custom enricher is needed.

For messages, use CorrelationContext.BeginScopeFromAttributes(logger, attributes, options). Message attribute names are a third contract, separate from header and log property names: CorrelationIdAttributeName and AttemptIdAttributeName (default CorrelationId and AttemptId), plus CorrelationIdAttributeAliases and AttemptIdAttributeAliases (default empty). The name is read first, then each alias; the first non-empty value wins. A missing value falls back to the current context, then to a new GUID, and never throws.

The middleware and helper use both logging scopes and activity tags: scopes make the values available to any ILogger provider; tags make them available to tracing and OpenTelemetry pipelines. They do not use baggage, which would implicitly propagate values to downstream services. Use the optional Anarchy.Toolkit.Infrastructure.Telemetry.Serilog integration only when Serilog-specific event enrichment is needed.

The default behavior generates missing values. IgnoreIfMissing and ThrowIfMissing are available when the application instead wants to accept missing headers or reject them. Coordinate header names with upstream and downstream services.

ModuleCorrelationId without a factory and parameterless AddCorrelationId() keep existing options; they register defaults only when none are present. A factory returning options or AddCorrelationId(options) replaces earlier options. The AddCorrelationId(Action<IServiceCollection>) overload delegates registration entirely to the caller. This lets a module configure names before a default ModuleTelemetry is applied without losing them.

See the observability guide and toolkit overview.

Releases

See the release notes for the complete release history.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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 (6)

Showing the top 5 NuGet packages that depend on Anarchy.Toolkit.Infrastructure.CorrelationId:

Package Downloads
Anarchy.Toolkit.Configuration

Application configuration: settings contracts, environment and secret handling, and the provider-neutral telemetry bootstrap (ModuleTelemetry) that applications extend through dependency injection.

Anarchy.Toolkit.Infrastructure.Messaging.Aws

AWS SNS and SQS implementations of the message-broker publisher abstraction, with the shared publisher base, request-builder base, inbound mapping, and compression.

Anarchy.Toolkit.Hosting.Workers

Worker pipeline: monitored/resilient background workers, heartbeat, and a self-hosted health API (service health reports, build metadata) for workers.

Anarchy.Toolkit.Infrastructure.Telemetry.Serilog

Optional Serilog integration for Anarchy telemetry: logging provider registration, console defaults for composition roots, a structured-exception enricher and opt-in log-based metrics.

Anarchy.Toolkit.Bootstrap

Application configuration: settings contracts, environment and secret handling, and the provider-neutral telemetry bootstrap (ModuleTelemetry) that applications extend through dependency injection.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.0 0 12/1/2026
3.0.0 155 11/27/2026
2.0.1 403 11/21/2026
2.0.0 267 11/20/2026
1.1.1 321 11/17/2026
1.1.0 272 11/17/2026
1.0.6 232 11/16/2026
1.0.5 272 11/14/2026
1.0.4 325 11/9/2026
1.0.3 198 11/9/2026
1.0.1 267 11/6/2026
1.0.0 223 11/5/2026

## Releases

### 3.1.0

- Add opt-in outgoing HTTP propagation, message attribute names and aliases, and scoped inbound correlation.
- feat(Infrastructure): Add configurable provider and messaging seams

### 3.0.0

- **Breaking:** extension classes take the `Extensions` suffix under `Extensions/<extended namespace>/`, helpers live in `Helpers/<Subject>/`, and their namespaces follow those folders: update `using` directives.
- **Breaking:** depends on the new major versions of `Core`.

### 2.0.1

- chore(build): Format package release notes property

### 2.0.0

- feat(automation): establish onboarding and layering conventions
- feat(telemetry)!: introduce provider-neutral application telemetry
- refactor(packages)!: restructure persistence and automation packages
- refactor(infrastructure.correlationid)!: decouple correlation scopes from Serilog
- refactor(core)!: reshape telemetry, event and health contracts
- refactor(telemetry)!: remove legacy APIs and simplify namespaces

### 1.1.1

- docs(packages): identify each package's pillar and layer
- build(packages): attribute the copyright to Leandro Melão Medeiros
- build: relicense under Apache-2.0 and update the package metadata

### 1.1.0

- build(deps): upgrade Swashbuckle.AspNetCore to 11.0.1 and Microsoft.OpenApi to 3.11.1

### 1.0.6

- docs: expand XML docblocks across all projects for the DocFX API reference

### 1.0.5

- refactor(src): clean up code style across library packages

### 1.0.3

- build: migrate local automation to build tooling

### 1.0.2

- docs: expand package guides and release histories

### 1.0.1

- Added a package-specific NuGet README.

### 1.0.0

- Introduced correlation ID context and options, HTTP header propagation middleware, Serilog enrichment and dependency-injection wiring.