# @greguintow/nestjs-sentry 中文文档

规范地址：https://npmcn.com/package/%40greguintow/nestjs-sentry/

版本：4\.1\.9
npm 元数据更新时间：2026-02-05T14:01:42.042Z
中文译文更新时间：2026-11-17T00:19:53.471Z
软件包许可：ISC

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40greguintow/nestjs-sentry
原文对照：https://npmcn.com/package/%40greguintow/nestjs-sentry/?lang=original
项目主页：https://github.com/greguintow/nestjs-sentry#readme
源码仓库：https://github.com/greguintow/nestjs-sentry

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：66.1 kB，42 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- peer 依赖：@nestjs/common \>=8\.0\.2，@nestjs/core \>=8\.0\.2，@sentry/node \>=6\.9\.0，reflect-metadata \>=0\.1\.13，rimraf \>=3\.0\.2，rxjs ^7\.2\.0，@nestjs/graphql \>=8\.0\.2
- 首次发布：2022-01-05T23:28:23.345Z
- 最新版本发布：2026-02-05T14:01:41.905Z
- 近 30 天下载量：17123（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：14（近 12 个月 1 个）

## 中文简介

提供可注射的哨兵。 io 客户端, 提供企业日志嵌入模块

## 安装

```sh
npm install @greguintow/nestjs-sentry
```

也可以使用：`pnpm add @greguintow/nestjs-sentry`、`yarn add @greguintow/nestjs-sentry`、`bun add @greguintow/nestjs-sentry`

## README

[![npm version](http://img.shields.io/npm/v/@ntegral/nestjs-sentry.svg?style=flat)](https://npmjs.org/package/@ntegral/nestjs-sentry "View this project on npm") [![Codecov Coverage](https://img.shields.io/codecov/c/github/ntegral/nestjs-sentry/master.svg?style=flat-square)](https://codecov.io/gh/ntegral/nestjs-sentry) [![ISC license](http://img.shields.io/badge/license-ISC-brightgreen.svg)](http://opensource.org/licenses/ISC) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PM2PTQ6Z2XATQ&source=url)

### @ntegral/nestjs-sentry (英语)

提供可注射的哨兵。 io 客户端, 提供企业日志嵌入模块

## 目录

-   [雀巢JS 8 支助](https://npmcn.com/package/%40greguintow/nestjs-sentry/#readme-nestjs-8-support)
-   [关于](https://npmcn.com/package/%40greguintow/nestjs-sentry/#readme-about)
-   [安装](https://npmcn.com/package/%40greguintow/nestjs-sentry/#readme-installation)
-   [开始](https://npmcn.com/package/%40greguintow/nestjs-sentry/#readme-getting-started)
-   [捐款](https://npmcn.com/package/%40greguintow/nestjs-sentry/#readme-contributing)
-   [许可证](https://npmcn.com/package/%40greguintow/nestjs-sentry/#readme-license)
-   [鸣谢](https://npmcn.com/package/%40greguintow/nestjs-sentry/#readme-acknowledgements)

## 雀巢JS 8 支助

3.x.x版本将支持NestJS 8+. 如果您需要 NestJS 7 的支持,请继续使用版本 2.x.x. 谢谢你的支持!

## 关于

`@ntegral/nestjs-sentry` 执行模块, `SentryModule`,在输入时 您的 sentry.io 工程为任何注射该软件的类提供 Sentry.io 客户端。 这个 让哨兵.io进入依赖性注射工作流程,而不必 完成初始设置之外的任何额外工作.

## 安装

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

## 使用@ntegral/nestjs-sentry的 Github 样本项目

以下项目是作为样板启动项目创建的,以让你去...(如果需要的话).

-   [@ntegral/nestjs-哨兵样本](https://github.com/ntegral/nestjs-sentry-example)

## 开始

最简单的使用方式 `@ntegral/nestjs-sentry` 将使用 `SentryModule.forRoot`

```typescript
import { Module } from '@nestjs-common';
import { SentryModule } from '@ntegral/nestjs-sentry';
import { LogLevel } from '@sentry/types';

@Module({
  imports: [
    SentryModule.forRoot({
      dsn: 'sentry_io_dsn',
      debug: true | false,
      environment: 'dev' | 'production' | 'some_environment',
      release: 'some_release', | null, // must create a release in sentry.io dashboard
      logLevel: LogLevel.Debug //based on sentry.io loglevel //
    }),
  ],
})
export class AppModule {}
```

同步方式 `@ntegral/nestjs-sentry` 将使用 `SentryModule.forRootAsync`

```typescript
import { Module } from '@nestjs-common';
import { SentryModule } from '@ntegral/nestjs-sentry';
import { ConfigModule } from '@ntegral/nestjs-config';
import { ConfigService } from '@ntegral/nestjs-config';

@Module({
  imports: [
    SentryModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (cfg:ConfigService) => ({
        dsn: cfg.get('SENTRY_DSN'),
        debug: true | false,
        environment: 'dev' | 'production' | 'some_environment',
        release: 'some_release', | null, // must create a release in sentry.io dashboard
        logLevel: LogLevel.Debug //based on sentry.io loglevel //
      }),
      inject: [ConfigService],
    })
  ]
})

export class AppModule {}
```

然后,你可以使用一个 自定义装饰器

```typescript
import { Injectable } from '@nestjs/common';
import { InjectSentry, SentryService } from '@ntegral/nestjs-sentry';

@Injectable()
export class AppService {
  public constructor(@InjectSentry() private readonly client: SentryService) {
      client.instance().captureMessage(message, Sentry.Severity.Log);
      client.instance().captureException(exception);
      ... and more
  }
}
```

您可以指示 Nest 使用 Sentry Service 作为默认的日志 :

```typescript
async function bootstrap() {
  const app = await NestFactory.create(AppModule, { logger: false });

  app.useLogger(SentryService.SentryServiceInstance());
  await app.listen(3000);
}
bootstrap();
```

您可以使用 SentryService 登录非错误消息作为面包屑或使用本地的 Sentry.addBreadcrumb 方法.

```typescript
import { Injectable } from '@nestjs/common';
import { InjectSentry, SentryService } from '@ntegral/nestjs-sentry';
import {  Severity } from '@sentry/types';

@Injectable()
export class AppService {
  constructor(@InjectSentry() private readonly client: SentryService) {
    client.log('AppSevice Loaded','test', true); // creates log asBreadcrumb //
    client.instance().addBreadcrumb({level: Severity.Debug, message: 'How to use native breadcrumb', data: { context: 'WhatEver'}})
    client.debug('AppService Debug', 'context');
  }
  getHello(): string {
    return 'Hello World!';
  }
}
```

## 截取器

哨兵干扰器可以用于不需要GraphQL的项目. 如果您需要 GraphQL 支持, 请使用 Graphql Interceptor 。 使用 Graphql Interceptor 会为 @nestjs/graphql 软件包创建依赖性 .

```bash
npm install --save @nestjs/graphql
```

全球使用图克l截取器

```typescript
import { Module } from '@nestjs/common';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { GraphqlInterceptor } from '@ntegral/nestjs-sentry';

@Module({
  ....
  providers: [
    {
      provide: APP_INTERCEPTOR,
      useFactory: () => new GraphqlInterceptor(),
    },
  ],
})
export class AppModule {}
```

## 闪闪发光哨

哨兵不会自己冲出所有的出错,而是在背景中进行,以免阻挡主线程. 若为 你用强力手段杀死巢鼠 某些例外 不必被冲去和记录.

如果您想强迫这种行为,请在选项中使用近旗. 如果用"巢"作为控制台,那就方便了 运行。 记住,你需要 `app.enableShutdownHooks();` 启用顺序 关闭(流出)工作.

```typescript
import { Module } from '@nestjs-common';
import { SentryModule } from '@ntegral/nestjs-sentry';
import { LogLevel } from '@sentry/types';

@Module({
  imports: [
    SentryModule.forRoot({
      dsn: 'sentry_io_dsn',
      debug: true | false,
      environment: 'dev' | 'production' | 'some_environment',
      release: 'some_release', | null, // must create a release in sentry.io dashboard
      logLevel: LogLevel.Debug //based on sentry.io loglevel //
      close: {
        enabled: true,
        // Time in milliseconds to forcefully quit the application  
        timeout?: number,  
      }
    }),
  ],
})
export class AppModule {}
```

## 捐款

我将非常感谢为改进这一项目而提供的任何捐助。 请 在弄脏你的手之前,确保遵循以下准则.

1.  叉子存储器
2.  创建您的分支( C)`git checkout -b my-branch`(中文(简体) )
3.  向您的分支提交任何更改
4.  推动您的更改到您的远程分支
5.  打开拉动请求

## 许可证

根据ISC许可证分发。 见 `LICENSE` 更多信息.

## 鸣谢

-   [鸟巢](https://nestjs.com/)
-   [@ sentry/ 节点](https://github.com/getsentry/sentry-javascript)

版权:"2019 Ntegral Inc.

## 常见问题

### @greguintow/nestjs-sentry 是什么？

提供可注射的哨兵。 io 客户端, 提供企业日志嵌入模块

### 如何安装 @greguintow/nestjs-sentry？

在项目目录运行 npm install @greguintow/nestjs-sentry，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@nestjs/common（\>=8\.0\.2）、@nestjs/core（\>=8\.0\.2）、@sentry/node（\>=6\.9\.0）、reflect-metadata（\>=0\.1\.13）、rimraf（\>=3\.0\.2）、rxjs（^7\.2\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @greguintow/nestjs-sentry 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @greguintow/nestjs-sentry 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @greguintow/nestjs-sentry 可以商用吗？

@greguintow/nestjs-sentry 使用 ISC 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @greguintow/nestjs-sentry 的下载量有多少？

根据 npm 官方下载统计，@greguintow/nestjs-sentry 在 2026/10/17 – 2026/11/15 这 30 天内被下载 17,123 次，日均约 571 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @greguintow/nestjs-sentry 还在维护吗？

最新版本 4\.1\.9 发布于 2026/02/05（9 个月前）；至今共发布 14 个版本，其中过去 12 个月发布了 1 个；首次发布于 2022/01/06。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

