@greguintow/nestjs-sentry

中文文档
4.1.9发布于 2026/02/05ISCTypeScriptCommonJS零依赖近 30 天下载 1.7万

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

中文使用文档
文档目录12 节
  1. @ntegral/nestjs-sentry (英语)
  2. 目录
  3. 雀巢JS 8 支助
  4. 关于
  5. 安装
  6. 使用@ntegral/nestjs-sentry的 Github 样本项目
  7. 开始
  8. 截取器
  9. 闪闪发光哨
  10. 捐款
  11. 许可证
  12. 鸣谢

npm version Codecov Coverage ISC license Donate

@ntegral/nestjs-sentry (英语)

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

目录

雀巢JS 8 支助

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

关于

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

安装

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

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

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

开始

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

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

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 {}

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

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 作为默认的日志 :

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

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

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

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 软件包创建依赖性 .

npm install --save @nestjs/graphql

全球使用图克l截取器

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(); 启用顺序 关闭(流出)工作.

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 更多信息.

鸣谢

版权:"2019 Ntegral Inc.

版本与发布记录

@greguintow/nestjs-sentry 共发布 14 个版本,首次发布于 2022/01/06;过去 12 个月发布了 1 个版本。

版本发布日期距今
4.1.9latest2026/02/059 个月前
4.1.82023/12/192 年前
4.1.72023/01/263 年前
4.1.62023/01/263 年前
4.1.52022/02/244 年前
4.1.42022/02/244 年前

关于 @greguintow/nestjs-sentry 的常见问题

@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 和提交记录判断。