A fast in-process tracer and profiler for .NET. Scopes, flows and counters on an allocation-free hot path. Reports, Perfetto traces and a flight recorder come after the fact, without touching the code that runs.
English · Русский
Tracer.Start();
using (Tracer.Scope(Ids.Checkout))
{
Checkout(order);
}
var session = Tracer.Stop();
Console.WriteLine(TraceText.Write(session.Process(), Tracer.CreateMetadata()));A profiler is useful when you can leave it on and trust its numbers. EmberTrace keeps recording cheap and moves the work to after the session.
- Cheap to record.
Scope,Instant,Counterand flow events do not allocate and take no locks: writers use thread-local buffers, and shared state is touched only when a chunk rotates or a limit is set. - Async-aware.
ScopeAsyncfollows a continuation across threads and keeps its parent throughawait. Flows link work that never shares a call stack. - Instrumentation by attribute.
[Trace]on apartialmethod generates the scope, the id and the metadata. On a class it generates a DI decorator for the whole service. - Always on. The flight recorder keeps the last seconds in memory.
Tracer.Snapshot()dumps them without stopping the session, and ASP.NET Core hosting can do it on demand or for every slow request. - Analysis after the fact. Aggregates, percentiles with distribution shape, text reports, flame graphs and statistically sound comparison of two sets of runs.
- Opens anywhere. Chrome Trace and Perfetto, speedscope, OpenTelemetry spans and a compact binary
.emberformat. - Guards in CI.
EmberTrace.Testingturns a trace into assertions and regression gates. - Correct usage by construction. Roslyn analyzers catch a scope that is never disposed or a flow that is never closed.
ScopeAsync allocates about 224 bytes per scope to carry its parent through await; a generated [Trace] async method pays about half of that.
dotnet add package EmberTrace.AllRequires .NET 10. The metapackage brings the runtime, the generator, analysis, export and text reports. To pick the parts yourself:
| Package | Contents |
|---|---|
EmberTrace |
Runtime API: Tracer.*. |
EmberTrace.Abstractions |
Attributes: [assembly: TraceId(...)], [Trace]. |
EmberTrace.Generator |
Source generator that registers metadata and emits [Trace] wrappers. |
EmberTrace.Analysis |
Session processing: session.Process(). |
EmberTrace.ReportText |
Text reports: TraceText.Write(...). |
EmberTrace.Export |
Chrome Trace export: TraceExport.*. |
EmberTrace.Format |
Binary session files: TraceFormat.Write and Read. |
EmberTrace.OpenTelemetry |
Export to Activity spans. |
EmberTrace.Extensions.Hosting |
ASP.NET Core: AddEmberTrace(), request scopes, /embertrace/dump. |
EmberTrace.Testing |
Performance assertions and baseline diffing: stats.Scope(...), TraceBudget. |
EmberTrace.RoslynAnalyzers |
Analyzers and code fixes. |
Describe ids and metadata once, at the assembly level:
using EmberTrace.Abstractions.Attributes;
[assembly: TraceId(1000, "App", "App")]
[assembly: TraceId(2000, "Worker", "Workers")]Wrap the code you want to see in scopes:
using EmberTrace;
Tracer.Start();
using (Tracer.Scope(1000))
{
DoWork();
}
var session = Tracer.Stop();Print a report and write a trace file:
var processed = session.Process();
var meta = Tracer.CreateMetadata();
Console.WriteLine(TraceText.Write(processed, meta: meta, topHotspots: 20, maxDepth: 8));
using var file = File.Create("out/trace.json");
TraceExport.WriteChromeComplete(session, file, meta: meta);Open out/trace.json in Perfetto or chrome://tracing.
| Area | Highlights |
|---|---|
| Recording | Scopes, async scopes, instants, counters, flows, runtime counters for GC, memory, thread pool and exceptions. |
| Instrumentation | [Trace] on methods and classes, TraceId metadata, analyzers with code fixes. |
| Live capture | Flight recorder, Tracer.Snapshot(), ASP.NET Core dump endpoint, slow request capture. |
| Analysis | Hotspots, call trees, percentiles, bimodality detection, run set comparison, collapsed stacks. |
| Output | Chrome Trace, Perfetto, speedscope, OpenTelemetry, .ember files, CSV. |
| Testing | Latency budgets and regression gates that work with MSTest, xUnit and NUnit. |
A scope costs about 157 ns here (ScopeBenchmarks, Scope_BeginEnd_SingleThread; two Stopwatch.GetTimestamp() calls cost about 61 ns), so a scope around an operation of a microsecond measures mostly itself. Wrap a batch in one scope instead and check the cost on your machine with OverheadCalibration.Measure(). See Usage and API.
| Quick start | Installation, ids, the first trace |
| Usage and API | Sessions, scopes, options |
| Auto-instrumentation | [Trace] and the DI decorator |
| Flows | Links across threads and await |
| Export | Chrome Trace and Perfetto |
| Analysis and reports | Percentiles, reports, comparison |
| Flight recorder | Snapshots of a live session |
| ASP.NET Core hosting | Request scopes, dump endpoint |
| Performance testing | Budgets and regression gates |
| Generator and metadata | TraceId, diagnostics |
| Troubleshooting | Symptoms, causes, fixes |
The full list is in the documentation index.
| Sample | Shows |
|---|---|
BasicTracing |
Scopes, a text report with percentiles, Chrome Trace, collapsed stacks, an .ember round trip. |
ParallelWorkers |
Worker threads, flows with AnalyzeFlows, runtime counters. |
AutoInstrumentation |
[Trace] on partial methods. |
FlightRecorder |
Tracer.Snapshot() over a bounded DropOldest buffer. |
WebApi |
ASP.NET Core hosting, /embertrace/dump, slow request capture. |
NativeAot |
NativeAOT publish. |
DocScreenshots |
Every scenario behind the images in docs/assets. |
dotnet run --project samples/EmberTrace.BasicTracing -c Release -p:UseLocalEmberTrace=trueThe files appear in ./out. -p:UseLocalEmberTrace=true builds a sample against the sources in this repository instead of the published packages.
Requires the SDK pinned in global.json.
dotnet build -c Release
dotnet test -c ReleaseBenchmarks and NativeAOT:
dotnet run --project benchmarks/EmberTrace.Benchmarks -c Release -- --filter *ScopeBenchmarks*
dotnet publish samples/EmberTrace.NativeAot -c Release -p:PublishAot=trueThe images in docs/assets are regenerated with python3 samples/EmberTrace.DocScreenshots/capture.py, which needs Playwright with Chromium and Pygments.


