Metrics, traces and health
Traces and metrics
Section titled “Traces and metrics”MassiveJobs records on an ActivitySource and a Meter, both named MassiveJobs. Collect them with OpenTelemetry:
builder.Services.AddOpenTelemetry() .WithTracing(t => t.AddSource(MassiveJobsTelemetry.ActivitySourceName)) .WithMetrics(m => m.AddMeter(MassiveJobsTelemetry.MeterName));Nothing is recorded while nothing listens.
Traces
Section titled “Traces”Each run of a job is an activity (a span of kind consumer), named by the job’s tag. It’s linked to the trace that
published the job: the publisher puts the current W3C traceparent in the message, so the run of a job published while
handling a request points back to that request. The job’s own activities (HttpClient’s, EF Core’s) are inside the run’s.
A retry published by a run links to that run.
On .NET Framework without OpenTelemetry’s SDK, activity ids aren’t W3C by default; set
Activity.DefaultIdFormat = ActivityIdFormat.W3C and Activity.ForceDefaultIdFormat = true at startup to get the links.
Metrics
Section titled “Metrics”| Metric | Type | |
|---|---|---|
massivejobs.job.attempts |
counter | Runs, by massivejobs.outcome: completed, retried, failed (to the failed queue), interrupted (by a shutdown). |
massivejobs.job.duration |
histogram (s) | Run time, by outcome. |
massivejobs.job.running |
up-down counter | Jobs running now, per queue. |
massivejobs.job.published |
counter | Jobs published. |
massivejobs.message.unknown_tag |
counter | Messages with a tag the app doesn’t register. |
massivejobs.message.unreadable |
counter | Messages that couldn’t be read as a job. |
massivejobs.periodic.runs |
counter | Runs of periodic jobs, by what happened to them. |
massivejobs.continuation.skipped |
counter | Continuations not published: the job’s outcome didn’t meet their condition. |
The tags are massivejobs.queue, massivejobs.job.tag and massivejobs.outcome. The job tag is always a registered one (except on
massivejobs.message.unknown_tag, which is rare), so stray messages can’t blow up the cardinality.
Health check
Section titled “Health check”MassiveJobsHealthCheck reports whether this app’s workers are consuming:
builder.Services.AddHealthChecks().AddCheck<MassiveJobsHealthCheck>("massivejobs");app.MapHealthChecks("/health");- Healthy: every worker is connected and consuming, or the app runs no workers.
- Degraded: a worker is connecting, or waiting to reconnect after it lost its channel.
- Unhealthy (the registration’s failure status): a worker has been without a connection for a minute, e.g. the broker is down.
The result’s data has each queue’s state. Publishing isn’t checked: it connects on demand, and a failed publish throws.
MassiveJobs logs through Microsoft.Extensions.Logging, under its classes’ names (MassiveJobs.Core.*,
MassiveJobs.RabbitMqBroker.*). Each message has a stable event id: 1–38 in Core, 1001–1012 in the RabbitMQ broker.
Failed jobs are logged as errors, with the exception; a lost connection as a warning; connections, worker restarts,
starts and stops as information.