# @item-enonic-types/lib-sentry

> Type definitions for lib-sentry

Latest version **0.4.0** (published 2025-05-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install @item-enonic-types/lib-sentry
pnpm add @item-enonic-types/lib-sentry
yarn add @item-enonic-types/lib-sentry
bun add @item-enonic-types/lib-sentry
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2025-05-31 |
| First published | 2023-04-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | tajakobsen |

## Links

- npm: https://www.npmjs.com/package/@item-enonic-types/lib-sentry
- npm.io page: https://npm.io/package/@item-enonic-types/lib-sentry

## Recent versions

- 0.4.0 (latest) — 2025-05-31
- 0.3.0 — 2025-05-31
- 0.2.0 — 2025-03-07
- 0.1.0 — 2025-01-03
- 0.0.3 — 2024-12-20
- 0.0.2 — 2023-04-20

## README

# Sentry Integration Library for Enonic XP

Enonic XP Library for enhancing data sent to Sentry.

[![](https://repo.itemtest.no/api/badge/latest/releases/no/item/lib-xp-sentry)](https://repo.itemtest.no/#/releases/no/item/lib-xp-sentry)

<img src="https://github.com/ItemConsulting/lib-xp-sentry/raw/main/docs/icon.svg?sanitize=true" width="150">

## Installation

To install this library you need to add a new dependency to your app's build.gradle file.

### Gradle

```groovy
repositories {
  maven { url "https://repo.itemtest.no/releases" }
}

dependencies {
  include "com.enonic.xp:lib-admin:${xpVersion}"
  include "no.item:lib-xp-sentry:0.3.0"
}
```

## Usage

You can use the `Sentry.init` method to configure the DSN for the Sentry client in your `main.ts` file.

```typescript
import { Sentry } from "/lib/sentry";

Sentry.init((opts): void => {
  opts.setDsn("https://public@sentry.example.com/1");
  opts.setRelease(app.version);
  opts.setEnvironment(getInstallation());
});
```

You can use your _/error/error.ts_ to get access to the `Exception` thrown, and send it to Sentry using 
`Sentry.captureException`.

```typescript
import { Sentry, ScopeCallbackBuilder } from "/lib/sentry";
import type { ErrorRequest, Request, Response } from "@enonic-types/core";

export function handleError(err: ErrorRequest): Response {
  if (err.status !== 404) {
    reportToSentry(err);
  }

  return {
    status: err.status,
    body: `<h1>${err.status} error</h1>`
  }
}

function reportToSentry(err: ErrorRequest): void {
  try {
    const callback = new ScopeCallbackBuilder()
      .setRequest(err.request)
      .setTag("branch", err.request.branch)
      .build();

    Sentry.captureException(err.exception, callback);
  } catch (e) {
    log.error("Failed to configure Sentry scope", e);
  }
}
```


## Deploying

### Building

To build he project run the following code

```bash
./gradlew build
```

### Deploy locally

Deploy locally for testing purposes:

```bash
./gradlew publishToMavenLocal
```

## Deploy to Maven

```bash
./gradlew publish -P com.enonic.xp.app.production=true
```

---
_Source: https://npm.io/package/@item-enonic-types/lib-sentry · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
