TraceStax Docs
.NET
The TraceStax .NET SDK supports Hangfire, MassTransit, and the generic IHostedService / BackgroundService pattern. It targets .NET 6+ and works with both ASP.NET Core and worker services.
Requirements
Section titled “Requirements”- .NET 6.0+
- One of: Hangfire 1.8+, MassTransit 8.x, or any
BackgroundServiceimplementation
Installation
Section titled “Installation”dotnet add package TraceStaxOr via the NuGet Package Manager:
Install-Package TraceStaxbuilder.Services.AddHangfire(config => config .UseRecommendedSerializerSettings() .UseSqlServerStorage(connectionString));
builder.Services.AddHangfireServer();
// Add TraceStax — registers a job filter automaticallybuilder.Services.AddTraceStax(options => { options.ApiKey = builder.Configuration["TraceStax:ApiKey"];});The TraceStax job filter wraps all Hangfire job executions — no per-job changes needed.
builder.Services.AddMassTransit(x => { x.AddConsumer<OrderProcessedConsumer>();
x.UsingRabbitMq((ctx, cfg) => { cfg.UseTraceStax(ctx); // add before other middleware cfg.ConfigureEndpoints(ctx); });});
builder.Services.AddTraceStax(options => { options.ApiKey = builder.Configuration["TraceStax:ApiKey"];});Wrap your hosted service with the TraceStax client:
public class OrderProcessingService : BackgroundService{ private readonly ITraceStaxClient _tracestax;
public OrderProcessingService(ITraceStaxClient tracestax) { _tracestax = tracestax; }
protected override async Task ExecuteAsync(CancellationToken ct) { await foreach (var job in _queue.ReadAllAsync(ct)) { using var evt = _tracestax.StartJob(job.Name, job.Queue); try { await ProcessAsync(job, ct); evt.Succeed(); } catch (Exception ex) { evt.Fail(ex); throw; } } }}Register in DI:
builder.Services.AddTraceStax(o => o.ApiKey = "ts_live_xxxxxxxxxxxx");builder.Services.AddHostedService<OrderProcessingService>();Configuration
Section titled “Configuration”builder.Services.AddTraceStax(options => { options.ApiKey = "ts_live_xxxxxxxxxxxx"; // or from config options.WorkerId = "worker-01"; // default: hostname + PID options.Enabled = !builder.Environment.IsDevelopment(); options.TimeoutMs = 3000;});Or via appsettings.json:
{ "TraceStax": { "ApiKey": "ts_live_xxxxxxxxxxxx", "WorkerId": "worker-01", "Enabled": true }}Testing
Section titled “Testing”// Register the no-op client in test projectsservices.AddTraceStaxNoop();Or set Enabled = false in your test appsettings.json.