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

# Grape

export const VersionRequirements = ({versions = []}) => {
  if (!Array.isArray(versions) || versions.length === 0) {
    return null;
  }
  const boundaries = {
    upper: " or lower",
    exact: "",
    lower: " or higher"
  };
  const containerStyle = {
    marginTop: "0.5rem",
    marginBottom: "1.5rem"
  };
  const lineStyle = {
    display: "block",
    margin: "0 0 0.35rem 0",
    fontSize: "0.875rem",
    lineHeight: "1.4"
  };
  const pillBaseStyle = {
    display: "inline-block",
    padding: "0.1em 0.4em",
    borderRadius: "0.25rem",
    border: "1px solid",
    fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
    fontSize: "0.85em",
    fontWeight: 500
  };
  const pillColors = {
    "AppSignal for Elixir": {
      background: "#f3e8ff",
      borderColor: "#e9d5ff",
      color: "#9333ea"
    },
    "AppSignal for Front-end": {
      background: "#fef9c3",
      borderColor: "#fde68a",
      color: "#ca8a04"
    },
    "AppSignal for Go": {
      background: "#ccfbf1",
      borderColor: "#99f6e4",
      color: "#0d9488"
    },
    "AppSignal for JavaScript": {
      background: "#fef9c3",
      borderColor: "#fde68a",
      color: "#ca8a04"
    },
    "AppSignal for Node.js": {
      background: "#dcfce7",
      borderColor: "#bbf7d0",
      color: "#16a34a"
    },
    "AppSignal for Python": {
      background: "#dbeafe",
      borderColor: "#bfdbfe",
      color: "#2563eb"
    },
    "AppSignal for Ruby": {
      background: "#fee2e2",
      borderColor: "#fecaca",
      color: "#dc2626"
    },
    "AppSignal for Rust": {
      background: "#ffedd5",
      borderColor: "#fed7aa",
      color: "#ea580c"
    }
  };
  const defaultPillColor = {
    background: "#f4f4f5",
    borderColor: "#e4e4e7",
    color: "#52525b"
  };
  const getPillStyle = name => ({
    ...pillBaseStyle,
    ...pillColors[name] || defaultPillColor
  });
  const getBoundText = bound => {
    return boundaries[bound] || boundaries.lower;
  };
  return <div style={containerStyle}>
      {versions.map((v, i) => <p key={`${v.name}-${v.version}-${v.bound || "lower"}-${i}`} style={lineStyle}>
          This feature requires{" "}
          <code style={getPillStyle(v.name)}>{v.name}</code> version {v.version}
          {getBoundText(v.bound)}.
        </p>)}
    </div>;
};

export const Compatibility = ({versions = [], label = "Available in"}) => {
  if (!Array.isArray(versions) || versions.length === 0) {
    return null;
  }
  const defaultPillStyle = {
    borderColor: "#d4d4d8",
    background: "#f4f4f5",
    color: "#3f3f46"
  };
  const pillStyles = {
    "AppSignal for Elixir": {
      background: "#f3e8ff",
      borderColor: "#d8b4fe",
      color: "#6b21a8"
    },
    "AppSignal for Front-end": {
      background: "#fef9c3",
      borderColor: "#fde047",
      color: "#854d0e"
    },
    "AppSignal for Go": {
      background: "#ccfbf1",
      borderColor: "#5eead4",
      color: "#115e59"
    },
    "AppSignal for JavaScript": {
      background: "#fef9c3",
      borderColor: "#fde047",
      color: "#854d0e"
    },
    "AppSignal for Node.js": {
      background: "#dcfce7",
      borderColor: "#86efac",
      color: "#166534"
    },
    "AppSignal for Python": {
      background: "#dbeafe",
      borderColor: "#93c5fd",
      color: "#1e40af"
    },
    "AppSignal for Ruby": {
      background: "#fee2e2",
      borderColor: "#fca5a5",
      color: "#991b1b"
    },
    "AppSignal for Rust": {
      background: "#ffedd5",
      borderColor: "#fdba74",
      color: "#9a3412"
    }
  };
  const getPillStyle = name => ({
    ...defaultPillStyle,
    ...pillStyles[name] || ({})
  });
  return <div className="not-prose my-4 rounded-lg border border-zinc-200 bg-zinc-50 px-4 py-3 text-sm dark:border-white/10 dark:bg-white/5">
      <div className="flex flex-wrap items-center gap-x-2 gap-y-1">
        <span className="font-semibold text-zinc-700 dark:text-zinc-200">
          {label}:
        </span>
        {versions.map((v, i) => <span key={`${v.name}-${v.version}-${i}`} className="inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-xs font-medium" style={getPillStyle(v.name)}>
            <span>{v.name}</span>
            <span className="opacity-70">
              {v.version}
              {v.exact ? "" : "+"}
            </span>
          </span>)}
      </div>
    </div>;
};

<VersionRequirements
  versions={[
{ name: "AppSignal for Ruby", version: "1.1" },
{ name: "Grape", version: "1.0" }
]}
/>

[Grape](https://www.ruby-grape.org/)-applicaties worden officieel ondersteund. Het instrumenteren van Grape-applicaties vereist enige handmatige configuratie. Volg de installatiestappen in AppSignal, te beginnen met het klikken op 'Add app' op het [accountsscherm](https://appsignal.com/accounts).

<Note>
  Gebruikt uw applicatie een combinatie van Rails, Grape, Hanami, Padrino of Sinatra? Volg dan onze handleiding voor het [instrumenteren van meerdere Rack-applicaties](/ruby/integrations/rack-libraries).
</Note>

## Installatie

<Tip>
  Deze installatiehandleiding is voor Ruby-gem 3.12 en nieuwer. Voor applicaties
  die een oudere AppSignal voor Ruby-gem gebruiken, volgt u onze [legacy
  installatiehandleiding](#legacy-installation).
</Tip>

Voeg na het [installeren en configureren van de AppSignal-gem](/ruby/installation) de AppSignal-integratie toe nadat de Grape-app is geladen.

De Grape-integratie wordt vereist vanuit de AppSignal Ruby-gem en de event- en instrumentatie-middlewares worden toegevoegd in de volgende codevoorbeelden.

<CodeGroup>
  ```ruby Ruby theme={null}
  # config.ru
  require "appsignal" # Add this require

  # Load the Grape integration
  Appsignal.load(:grape)

  # Add the AppSignal Rack event middleware
  # AppSignal for Ruby gem 4.7+ required
  use Appsignal::Rack::EventMiddleware

  # Require the app
  require_relative "api"

  # Start AppSignal
  Appsignal.start

  # Start the app
  run Acme::API
  ```
</CodeGroup>

De volgende stap is het toevoegen van de AppSignal-middleware aan de basis-API-klasse van de applicatie. Deze rapporteert eventuele niet-afgehandelde excepties uit de applicatie.

<CodeGroup>
  ```ruby Ruby theme={null}
  # api.rb

  module Acme
    class API < Grape::API
      # Add this line
      insert_before Grape::Middleware::Error, Appsignal::Rack::GrapeMiddleware # Include this middleware

      # ...
    end
  end
  ```
</CodeGroup>

### Legacy installatie

Voor applicaties die AppSignal voor Ruby-gem 3.11 of ouder gebruiken, volgt u deze stappen om AppSignal te installeren in Grape-applicaties.

De Grape-integratie wordt vereist vanuit de AppSignal Ruby-gem en de event handler- en instrumentatie-middlewares worden toegevoegd in de volgende codevoorbeelden.

<CodeGroup>
  ```ruby Ruby theme={null}
  # config.ru
  require "appsignal/integrations/grape" # Add this require

  # Configure AppSignal
  Appsignal.config = Appsignal::Config.new(
    Dir.pwd,        # The root of your app
    ENV["RACK_ENV"] # The environment of your app (development/production)
  )
  # Start AppSignal
  Appsignal.start_logger # Not required in Ruby gem 3.9.3+
  Appsignal.start

  # Add the AppSignal Rack EventHandler
  # AppSignal for Ruby gem 3.8+ required
  use ::Rack::Events, [Appsignal::Rack::EventHandler.new]

  # Require the app
  require_relative "api"

  # Start the app
  run Acme::API
  ```
</CodeGroup>

De volgende stap is het toevoegen van de AppSignal-middleware aan de basis-API-klasse van de applicatie. Deze rapporteert eventuele niet-afgehandelde excepties uit de applicatie.

<CodeGroup>
  ```ruby Ruby theme={null}
  # api.rb

  module Acme
    class API < Grape::API
      # Add this line
      insert_before Grape::Middleware::Error, Appsignal::Grape::Middleware # Include this middleware

      # ...
    end
  end
  ```
</CodeGroup>

## Gemounte Grape-apps

<Compatibility versions={[{ name: "AppSignal for Ruby", version: "3.9.3" }]} />

Het mounten van Grape-applicaties op Ruby on Rails-applicaties wordt ondersteund. De Ruby-gem moet een recente versie zijn om requests voor gemounte Grape-apps correct te instrumenteren.

## Fouten negeren

<Compatibility versions={[{ name: "AppSignal for Ruby", version: "2.10.5" }]} />

Om een specifieke Grape-fout te negeren, stelt u de `grape.skip_appsignal_error`-vlag in de request-environment in. Door deze vlag op `true` te zetten, instrueert u AppSignal om geen fouten tijdens de request te rapporteren.

Gebruik deze vlag alleen als u dynamisch fouten van een Grape-applicatie moet negeren. Specificeer foutklassen in de [`ignore_errors`-optie](/guides/filter-data/ignore-errors) om ze voor de hele applicatie te negeren. Zie onze [documentatie over notificatie-instellingen](/application/notification-settings) voor meer informatie over het dempen van notificaties voor specifieke fouten.

<CodeGroup>
  ```ruby Ruby theme={null}
  get "/" do
    env["grape.skip_appsignal_error"] = true # Add this line to an endpoint or callback
    raise "uh oh" # Example error, don't copy this
  end
  ```
</CodeGroup>

## Fouten rapporteren vanuit `rescue_from`

Als een fout in de app wordt afgehandeld met `rescue_from`, ontvangt en registreert AppSignal deze niet. Om de fout toch te rapporteren, roept u `Appsignal.report_error` aan in het `rescue_from`-blok. (Gebruik de `Appsignal.set_error`-helper bij gebruik van Ruby-gem versie 3 of ouder.)

<CodeGroup>
  ```ruby Ruby theme={null}
  class Api < ::Grape::API
    insert_before Grape::Middleware::Error, Appsignal::Grape::Middleware

    format :json

    rescue_from :all do |error|
      Appsignal.report_error(error)
      error!({ :error => "error message" }.to_json, 500)
    end
  end
  ```
</CodeGroup>
