github.com/grafana/pyroscope@v1.18.0/docs/sources/configure-client/trace-span-profiles/dotnet-span-profiles.md (about) 1 --- 2 title: Span profiles with Traces to profiles for .NET 3 menuTitle: Span profiles with Traces to profiles (.NET) 4 description: Learn about and configure Span profiles with Traces to profiles in Grafana for .NET applications. 5 weight: 103 6 --- 7 8 # Span profiles with Traces to profiles for .NET 9 10 Span Profiles represent a shift in profiling methodology. 11 Traditional continuous profiling provides an application-wide view over fixed intervals. 12 In contrast, Span Profiles delivers focused, dynamic analysis on specific execution scopes within applications, such as individual requests or specific trace spans. 13 14 To learn more about Span Profiles, refer to [Combining tracing and profiling for enhanced observability: Introducing Span Profiles](/blog/2024/02/06/combining-tracing-and-profiling-for-enhanced-observability-introducing-span-profiles/). 15 16  17 18 ## Supported profile types 19 20 Pyroscope integrates with distributed tracing systems supporting the [**OpenTelemetry**](https://opentelemetry.io/docs/languages/net/getting-started/) standard. 21 This integration lets you link traces with the profiling data and find resource usage for specific lines of code for your trace spans. 22 23 {{< admonition type="note" >}} 24 * Only CPU profiling is supported at the moment. 25 * Because of how sampling profilers work, spans shorter than the sample interval may not be captured. 26 {{< /admonition >}} 27 28 For a more detailed list of supported profile types, refer to [Profile types](https://grafana.com/docs/pyroscope/<PYROSCOPE_VERSION/configure-client/profile-types/>). 29 30 ## Before you begin 31 32 To use Span Profiles, you need to: 33 34 * [Configure Pyroscope to send profiling data](https://grafana.com/docs/pyroscope/<PYROSCOPE_VERSION>/configure-client/) 35 * Configure a client-side package to link traces and profiles: [.NET](https://github.com/grafana/pyroscope-dotnet/tree/main/Pyroscope/Pyroscope.OpenTelemetry) 36 * [Configure the Tempo data source in Grafana or Grafana Cloud to discover linked traces and profiles](/docs/grafana-cloud/connect-externally-hosted/data-sources/tempo/configure-tempo-data-source/) 37 38 ### Instrument your application for profiles 39 40 Your applications must be instrumented for profiling and tracing before you can use span profiles. 41 42 * Profiling: Your application must be instrumented with Pyroscope's .NET instrumentation library. Refer to the [.NET](../../language-sdks/dotnet/) guide for instructions. 43 * Tracing: Your application must be instrumented with OpenTelemetry traces. Refer to the [OpenTelemetry](https://opentelemetry.io/docs/languages/net/getting-started/) guide for instructions. 44 45 {{< admonition type="note" >}} 46 Span profiles in .NET are only supported using [OpenTelemetry manual instrumentation](https://opentelemetry.io/docs/languages/net/instrumentation/) 47 because Pyroscope's .NET profiler and OpenTelemetry's auto instrumentation are based on separate .NET CLR profilers. 48 {{< /admonition >}} 49 50 ## Configure the `Pyroscope.OpenTelemetry` package 51 52 To start collecting Span Profiles for your .NET application, you need to include [Pyroscope.OpenTelemetry](https://github.com/grafana/pyroscope-dotnet/tree/main/Pyroscope/Pyroscope.OpenTelemetry) in your code. 53 54 This package provides a [`SpanProcessor`](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry/BaseProcessor.cs) implementation, which connects the two telemetry signals (traces and profiles) together. 55 56 ```shell 57 dotnet add package Pyroscope.OpenTelemetry 58 ``` 59 60 Next, create and register the `PyroscopeSpanProcessor`: 61 ```csharp 62 builder.Services.AddOpenTelemetry() 63 .WithTracing(b => 64 { 65 b 66 .AddAspNetCoreInstrumentation() 67 .AddConsoleExporter() 68 .AddOtlpExporter() 69 .AddProcessor(new Pyroscope.OpenTelemetry.PyroscopeSpanProcessor()); 70 }); 71 ``` 72 73 With the span processor registered, spans created automatically (for example, HTTP handlers) and manually (`ActivitySource.StartActivity()`) have profiling data associated with them. 74 75 ## View the span profiles in Grafana 76 77 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. 78 79 Refer to the [Tempo data source configuration documentation](https://grafana.com/docs/grafana/<GRAFANA_VERSION>/datasources/tempo/configure-tempo-data-source) to see how to configure the visualization to link traces with profiles. 80 81 ## Examples 82 83 Check out these demo applications for span profiles: 84 - [.NET example](https://github.com/grafana/pyroscope/tree/main/examples/tracing/dotnet) 85 - [Other examples](https://github.com/grafana/pyroscope/tree/main/examples/tracing/tempo) in multiple languages