@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 {}
捐款
我将非常感谢为改进这一项目而提供的任何捐助。 请 在弄脏你的手之前,确保遵循以下准则.
- 叉子存储器
- 创建您的分支( C)
git checkout -b my-branch(中文(简体) ) - 向您的分支提交任何更改
- 推动您的更改到您的远程分支
- 打开拉动请求
许可证
根据ISC许可证分发。 见 LICENSE 更多信息.
鸣谢
版权:"2019 Ntegral Inc.