# Hapi Error Tracking and Performance Monitoring

> Error tracking that helps developers monitor and fix crashes in real time. Iterate continuously. Boost workflow efficiency. Improve user experience.

**URL:** https://sentry.io/for/hapi/

---

**Documentation:** [https://docs.sentry.io/platforms/javascript/guides/hapi/](https://docs.sentry.io/platforms/javascript/guides/hapi/)

## Install

Add `@sentry/node` as a dependency:

```bash
npm install --save @sentry/node
```

Create an `instrument.js` file that initializes Sentry:

```javascript
const Sentry = require("@sentry/node");

// Ensure to call this before requiring any other modules!
Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",

  // Set tracesSampleRate to 1.0 to capture 100%
  // of transactions for tracing.
  // We recommend adjusting this value in production
  tracesSampleRate: 1.0,
});
```

Require `instrument.js` before any other modules. The Hapi integration registers an error handler when your server starts, so errors are captured automatically:

```javascript
// Require this first!
require("./instrument");

// Now require other modules
const Hapi = require("@hapi/hapi");

const init = async () => {
  const server = Hapi.server({
    port: 3030,
    host: "localhost",
  });

  // All your routes etc.

  await server.start();
};

init();
```

See the [Hapi docs](https://docs.sentry.io/platforms/javascript/guides/hapi/) for full setup options.

## Features

### Works With OpenTelemetry

Sentry traces your app out of the box, with rich distributed tracing context across the libraries and frameworks you use. Already running OpenTelemetry? Sentry runs alongside your existing setup without taking it over, and can capture spans from `@opentelemetry/api` when you turn it on.

### Hapi Performance Monitoring

Quickly identify Hapi [performance](https://sentry.io/product/tracing/) issues and view the full end-to-end distributed trace to see the exact, poor-performing API call and surface any related errors.

### Hapi Error Monitoring with Complete Stack Traces

See the Hapi source code at each frame instead of settling for just line and column numbers. Get proper asynchronous context tracking — like thread-local store — in a way that fits Node's concurrency model.

### Fill In The Blanks About Hapi Errors

See what the app was doing when the Hapi error occurred: HTTP requests, database queries, console log statements, etc.

### Hapi Application Profiling

Profiling lets you see what parts of your code are consuming the most resources, like CPU or memory, in your application— so you can optimize them before end user experience is impacted. Test your application performance in any environment, including in production, without writing manual tests or extensive troubleshooting.

---

*Source: [sentry.io/for/hapi/](https://sentry.io/for/hapi/)*
