> ## Documentation Index
> Fetch the complete documentation index at: https://mw-docs.middleware.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Ruby

> Ruby APM - Setup & Installation Docs | Middleware

<span
  style={{
background: "url(https://img.shields.io/github/v/release/middleware-labs/ruby-gem) no-repeat",
width: "125px",
height: "20px",
display: "inline-block",
}}
/>

| Traces | Metrics | App Logs | Custom Logs | Profiling |
| :----: | :-----: | :------: | :---------: | :-------: |
|    ✅   |    ✖️   |    ✖️    |      ✖️     |     ✅     |

This guide walks you through setting up Application Performance Monitoring (APM) on a Ruby application. These instructions can also be found on the Installation page in your Middleware Account. View example code [here](https://github.com/middleware-labs/demo-apm/tree/master/ruby).

# Prerequisites

<Steps>
  <Step title="Infra Agent">
    Infrastructure Agent (Infra Agent). To install the Infra Agent, see our [Installation Guide](https://docs.middleware.io/docs/agent-installation/overview).
  </Step>

  <Step title="Ruby Version">
    `Ruby version 3.0.0`. Check your Ruby version with the following command:

    ```bash Shell theme={null}
    ruby --version
    ```
  </Step>
</Steps>

# Install

### Step 1: Add Gems to Your Gemfile

<Tabs>
  <Tab title="Linux Gemfile">
    ```ruby Ruby theme={null}
       gem 'opentelemetry-sdk'
       gem 'opentelemetry-exporter-otlp'
       gem 'opentelemetry-instrumentation-all'
       gem 'pyroscope'
       gem 'middleware_apm_linux', '~> 2.1.0'
    ```
  </Tab>

  <Tab title="Windows Gemfile">
    ```ruby Ruby theme={null}
      gem 'opentelemetry-sdk'
      gem 'opentelemetry-exporter-otlp'
      gem 'opentelemetry-instrumentation-all'
      gem 'pyroscope'
      gem 'middleware_apm_windows', '~> 2.1.0'
    ```
  </Tab>
</Tabs>

### Step 2: Import Tracker

<Tabs>
  <Tab title="Linux Environment">
    ```ruby Ruby theme={null}
        require 'middleware/ruby_gem_linux'
        Middleware::RubyGem.init
    ```
  </Tab>

  <Tab title="Windows Environment">
    ```ruby Ruby theme={null}
        require 'middleware/ruby_gem_windows'
        Middleware::RubyGem.init
    ```
  </Tab>
</Tabs>

### Step 3: Capture Application Data

#### Traces

```bash Shell theme={null}
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:9320 \ 
OTEL_SERVICE_NAME="<Your Service Name>" \ 
OTEL_RESOURCE_ATTRIBUTES=project.name="<Your Project Name>" \ 
MW_API_KEY=<Your API Key> \ 
<YOUR COMMAND> 
```

#### Profiling

Application Profiling is auto-configured upon completion of Step 2.

# Continuous Profiling

Continuous profiling captures real-time performance insights from your application to enable rapid identification of resource allocation, bottlenecks, and more. Navigate to the [Continuous Profiling](https://docs.middleware.io/workflow/profiling#continuous-profiling) section to learn more about using Continuous Profiling with the Ruby APM.

<Note> Need assistance or want to learn more about Middleware? Contact us at support\[at]middleware.io. </Note>
