github.com/grafana/pyroscope@v1.18.0/docs/sources/configure-client/trace-span-profiles/ruby-span-profiles.md (about) 1 --- 2 title: Span profiles with Traces to profiles for Ruby 3 menuTitle: Span profiles with Traces to profiles (Ruby) 4 description: Learn about and configure Span profiles with Traces to profiles in Grafana for the Ruby language. 5 weight: 102 6 --- 7 8 # Span profiles with Traces to profiles for Ruby 9 10 Span Profiles represent a major shift in profiling methodology, enabling deeper analysis of both tracing and profiling data. 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 This shift enables a more granular view of performance, enhancing the utility of profiles by linking them directly with traces for a comprehensive understanding of application behavior. As a result, engineering teams can more efficiently identify and address performance bottlenecks. 15 16 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/). 17 18  19 20 Pyroscope integrates with distributed tracing systems supporting the [**OpenTelemetry**](https://opentelemetry.io/docs/instrumentation/ruby/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 To use Span Profiles, you need to: 29 30 * [Configure Pyroscope to send profiling data](../../) 31 * Configure a client-side package to link traces and profiles: [Ruby](https://github.com/grafana/otel-profiling-ruby) 32 * [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/) 33 34 ## Before you begin 35 36 Your applications must be instrumented for profiling and tracing before you can use span profiles. 37 38 * Profiling: Your application must be instrumented with Pyroscope's Ruby SDK. Refer to the [Ruby](../../language-sdks/ruby/) guide for instructions. 39 * Tracing: Your application must be instrumented with OpenTelemetry traces. Refer to the [OpenTelemetry](https://opentelemetry.io/docs/languages/ruby/getting-started/) guide for instructions. 40 41 ## Configure the otel-profiling-ruby package 42 43 To start collecting Span Profiles for your Ruby application, you need to include [otel-profiling-ruby](https://github.com/pyroscope-io/otel-profiling-ruby) in your code. 44 45 This package is a `TracerProvider` implementation, that labels profiling data with span IDs which makes it possible to query for span-specific profiling data in Grafana Tempo UI. 46 47 ```shell 48 # Add to your Gemfile 49 gem install pyroscope-otel 50 ``` 51 52 Next, you need to create and configure the tracer provider: 53 ```ruby 54 Pyroscope.configure do |config| 55 # Configure pyroscope as described https://pyroscope.io/docs/ruby/ 56 end 57 58 OpenTelemetry::SDK.configure do |config| 59 config.add_span_processor Pyroscope::Otel::SpanProcessor.new( 60 "#{app_name}.cpu", # your app name with ".cpu" suffix, for example rideshare-ruby.cpu 61 pyroscope_endpoint # link to your pyroscope server, for example "http://localhost:4040" 62 ) 63 # Configure the rest of opentelemetry as described https://github.com/open-telemetry/opentelemetry-ruby 64 end 65 ``` 66 67 ## View the span profiles in Grafana Tempo 68 69 To view the span profiles in Grafana Tempo, you need to have a Grafana instance running and a data source configured to link trace spans and profiles. 70 71 Refer to the [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 trace spans with profiles. 72 73 To use a simple configuration, follow these steps: 74 75 1. Select a Pyroscope data source from the Data source drop-down. 76 77 2. Optional: Choose any tags to use in the query. If left blank, the default values of `service.name` and `service.namespace` are used. 78 79 The tags you configure must be present in the spans attributes or resources for a trace to profiles span link to appear. You can optionally configure a new name for the tag. This is useful for example if the tag has dots in the name and the target data source doesn't allow using dots in labels. In that case you can for example remap service.name to service_name. 80 81 3. Select one or more profile types to use in the query. Select the drop-down and choose options from the menu. 82 83 The profile type or app must be selected for the query to be valid. Grafana doesn't show any data if the profile type or app isn’t selected when a query runs. 84 85  86 87 ## Examples 88 89 Check out the [examples](https://github.com/grafana/pyroscope/tree/main/examples/tracing/tempo) directory for a complete demo application that shows tracing integration features. 90 91 ## Examples 92 93 Check out these demo applications for span profiles: 94 - [Ruby example](https://github.com/grafana/pyroscope/tree/main/examples/tracing/ruby) 95 - [Other examples](https://github.com/grafana/pyroscope/tree/main/examples/tracing/tempo) in multiple languages