Skip to content

Metrics and tracing

Surefire emits metrics via System.Diagnostics.Metrics and traces via System.Diagnostics.ActivitySource. Both use the name "Surefire".

InstrumentTypeUnitDescription
surefire.runs.claimedCounterRuns claimed by workers
surefire.runs.completedCounterRuns completed successfully
surefire.runs.failedCounterRuns that reached dead letter
surefire.runs.cancelledCounterRuns cancelled
surefire.runs.duration.msHistogrammsRun execution duration

Current counters and histograms are emitted without additional metric tags.

The "Surefire" activity source creates surefire.run.execute spans with these tags:

TagDescription
surefire.run.idThe run ID
surefire.run.jobThe job name
surefire.run.attemptAttempt number
surefire.run.parentParent run ID (if any)

Failed jobs set the span status to Error with the exception message.

Install the OpenTelemetry packages:

Terminal window
dotnet add package OpenTelemetry.Extensions.Hosting
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
dotnet add package OpenTelemetry.Exporter.Console # optional, for local dev

Wire up the meter and activity source in your host builder:

using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddMeter("Surefire");
metrics.AddOtlpExporter();
// metrics.AddConsoleExporter(); // uncomment for local dev
})
.WithTracing(tracing =>
{
tracing.AddSource("Surefire");
tracing.AddOtlpExporter();
// tracing.AddConsoleExporter(); // uncomment for local dev
});
builder.Services.AddSurefire();

The OTLP exporter sends data to any OpenTelemetry-compatible backend (Jaeger, Grafana, Aspire Dashboard, etc.). By default it connects to http://localhost:4317. Configure via environment variables:

Terminal window
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
OTEL_SERVICE_NAME=my-app

If you’re using .NET Aspire, metrics and traces are collected automatically — just add the meter and source:

builder.Services.AddOpenTelemetry()
.WithMetrics(m => m.AddMeter("Surefire"))
.WithTracing(t => t.AddSource("Surefire"));