docs/sources/configure-client/trace-span-profiles/dotnet-span-profiles.md
Span Profiles represent a shift in profiling methodology. Traditional continuous profiling provides an application-wide view over fixed intervals. In contrast, Span Profiles delivers focused, dynamic analysis on specific execution scopes within applications, such as individual requests or specific trace spans.
To learn more about Span Profiles, refer to Combining tracing and profiling for enhanced observability: Introducing Span Profiles.
Pyroscope integrates with distributed tracing systems supporting the OpenTelemetry standard. This integration lets you link traces with the profiling data and find resource usage for specific lines of code for your trace spans.
{{< admonition type="note" >}}
For a more detailed list of supported profile types, refer to Profile types.
To use Span Profiles, you need to:
Your applications must be instrumented for profiling and tracing before you can use span profiles.
{{< admonition type="note" >}} Span profiles in .NET are only supported using OpenTelemetry manual instrumentation because Pyroscope's .NET profiler and OpenTelemetry's auto instrumentation are based on separate .NET CLR profilers. {{< /admonition >}}
Pyroscope.OpenTelemetry packageTo start collecting Span Profiles for your .NET application, you need to include Pyroscope.OpenTelemetry in your code.
This package provides a SpanProcessor implementation, which connects the two telemetry signals (traces and profiles) together.
dotnet add package Pyroscope.OpenTelemetry
Next, create and register the PyroscopeSpanProcessor:
builder.Services.AddOpenTelemetry()
.WithTracing(b =>
{
b
.AddAspNetCoreInstrumentation()
.AddConsoleExporter()
.AddOtlpExporter()
.AddProcessor(new Pyroscope.OpenTelemetry.PyroscopeSpanProcessor());
});
With the span processor registered, spans created automatically (for example, HTTP handlers) and manually (ActivitySource.StartActivity()) have profiling data associated with them.
To view the span profiles in Grafana Explore or Grafana Traces Drilldown, you need to have a Grafana instance running and a Tempo data source configured to link traces and profiles.
Refer to the Tempo data source configuration documentation to see how to configure the visualization to link traces with profiles.
Check out these demo applications for span profiles: