Pacote NuGet para gerenciamento de correlation-id em aplicações .NET com suporte para .NET 8 e .NET Framework 4.8
$ dotnet add package WhiteBeard.Traceability
If you find this project useful, consider supporting its development:
Have questions about the API, implementation, or documentation? Ask DeepWiki, an AI agent that can help you understand and use Traceability.
NuGet package for automatic correlation-id management in .NET applications, with support for .NET Standard 2.0+ (core), .NET 8 (ASP.NET Core), and .NET Framework 4.8+ (ASP.NET Framework).
📖 Quick Start | User Manual | Complete Documentation | Examples
Indexed Documentation (Devin DeepWiki): DeepWiki for
whitebeardit/traceability
In distributed architectures and microservices, tracking a request across multiple services is essential for debugging, monitoring, and performance analysis. The correlation-id is a unique identifier that allows you to track a request from its origin to all subsequent calls.
Use Traceability when you need:
AsyncLocal<string>Activity.Current (when OpenTelemetry is configured externally)traceparent header) when trace context is available (best-effort)PreApplicationStartMethoddocs/migration.mddotnet add package WhiteBeard.Traceability
1. Install the package:
dotnet add package WhiteBeard.Traceability
2. Configure in Program.cs (just one line!):
using Traceability.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Zero configuration - everything is automatic!
// Source comes from TRACEABILITY_SERVICENAME or assembly name
// Middleware is registered automatically
// HttpClient is configured automatically
builder.Services.AddTraceability();
builder.Services.AddControllers();
var app = builder.Build();
app.MapControllers();
app.Run();
With explicit Source (optional):
builder.Services.AddTraceability("MyService");
3. Use in a Controller:
using Microsoft.AspNetCore.Mvc;
using Traceability;
[ApiController]
[Route("api/[controller]")]
public class ValuesController : ControllerBase
{
[HttpGet]
public IActionResult Get()
{
// Correlation-id is automatically available
var correlationId = CorrelationContext.Current;
return Ok(new { CorrelationId = correlationId });
}
}
Result:
X-Correlation-Id)traceparent) when OpenTelemetry is configured externallyX-Correlation-Id response header1. Install the package:
Install-Package WhiteBeard.Traceability
2. That's it! No code needed!
The library automatically:
CorrelationIdHttpModule via PreApplicationStartMethodOptional: Configure Serilog
// Global.asax.cs
using Traceability.Extensions;
using Serilog;
protected void Application_Start()
{
Log.Logger = new LoggerConfiguration()
.WithTraceability("MyService")
.WriteTo.Console(
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Source} {CorrelationId} {Message:lj}{NewLine}{Exception}")
.CreateLogger();
GlobalConfiguration.Configure(config =>
{
config.MapHttpAttributeRoutes();
});
}
3. Use in a Controller:
using System.Web.Http;
using Traceability;
public class ValuesController : ApiController
{
[HttpGet]
[Route("api/values")]
public IHttpActionResult Get()
{
// Correlation-id is automatically available
var correlationId = CorrelationContext.Current;
return Ok(new { CorrelationId = correlationId });
}
}
Result:
traceparent) when OpenTelemetry is configured externallyX-Correlation-Id response headerTo reduce verbosity, you can use environment variables:
Linux/Mac:
export TRACEABILITY_SERVICENAME="UserService"
export LOG_LEVEL="Information"
Windows PowerShell:
$env:TRACEABILITY_SERVICENAME="UserService"
$env:LOG_LEVEL="Information"
With the environment variable defined, you can use:
// Source comes automatically from TRACEABILITY_SERVICENAME
builder.Services.AddTraceability();
// Program.cs
builder.Services.AddTraceability("MyService");
builder.Logging.AddConsole(options => options.IncludeScopes = true);
// In Controller
_logger.LogInformation("Processing request");
// Output: => CorrelationId: a1b2c3d4e5f6789012345678901234ab
// Program.cs
builder.Services.AddTraceability("MyService");
builder.Services.AddHttpClient("ExternalApi", client =>
{
client.BaseAddress = new Uri("https://api.example.com/");
});
// In Controller
var client = _httpClientFactory.CreateClient("ExternalApi");
// Correlation-id is automatically added to the header
The package uses multi-targeting to provide the best experience for each platform:
PreApplicationStartMethodNote: The package automatically selects the appropriate implementation based on your target framework. Core functionality (correlation-id management, HttpClient propagation, logging) is available on all platforms via the .NET Standard 2.0 target.
Contributions are welcome! Please open an issue or pull request.
For developers who want to contribute:
MIT