A lightweight interceptor plugin for the Temporal .NET SDK that provides visibility into:
- Workflow execution cost drivers
- Activity-level execution patterns
- Retry amplification
- Signal and query traffic
- Workflow load hotspots
- Client-side tracking for workflow starts, signals, and queries
- Replay-safe workflow execution tracking
- Activity attempt, retry, failure, and duration tracking
- Scheduled activity and local activity counts from workflow outbound interceptors
- Child workflow scheduling counts
- Configurable estimated cost units
- Snapshot and hotspot helpers on the metrics store
- Lightweight in-process metrics store
Built using Temporal .NET interceptors:
IClientInterceptorrecords workflow starts, queries, and signals from clientsIWorkerInterceptorrecords workflow execution and activity execution from workers- Workflow outbound interception records scheduled activities and child workflows
- Workflow-side metrics skip replay paths with
Workflow.Unsafe.IsReplaying
using Temporalio.Client;
using Temporalio.Worker;
using TemporalCostInsights.Core;
var plugin = new CostInsightsPlugin();
var client = await TemporalClient.ConnectAsync(new("localhost:7233")
{
Interceptors = new[] { plugin },
});
using var worker = new TemporalWorker(
client,
new TemporalWorkerOptions("cost-insights-taskqueue")
.AddActivity(new SampleActivities().ProcessData)
.AddWorkflow<SampleWorkflow>());
await worker.ExecuteAsync(cancellationToken);TemporalWorker automatically receives client interceptors that also implement IWorkerInterceptor, so registering the plugin on the client is enough for the sample path.
var topWorkflows = plugin.MetricsStore.GetTopWorkflowsByEstimatedCost(count: 5);
foreach (var workflow in topWorkflows)
{
Console.WriteLine(workflow);
}For stable reads, use SnapshotWorkflows() or GetMetrics(workflowId). Both return detached copies.
The built-in score is a heuristic, not a billing calculator. Tune it per deployment:
var plugin = new CostInsightsPlugin(new CostInsightsOptions
{
ActivityExecutionUnits = 3.0,
RetryUnits = 2.0,
FailureUnits = 5.0,
});Run the sample against a local Temporal server:
dotnet run --project TemporalCostInsights.SampleThe sample registers the plugin, runs a worker, and prints a compact top-cost workflow snapshot every 10 seconds when metrics are present.