Comments (3)
I was able to get performance monitoring, including tracing, working on Sentry v7.31.1 using the below module configuration (thanks to @mahendradambe and their own Sentry/NestJS integration for pointing me in the right direction on how to inject the Express application object into the tracing integration).
Root Module (ex. AppModule)
SentryModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService, HttpAdapterHost],
useFactory: async (
config: ConfigService,
adapterHost: HttpAdapterHost,
) => ({
dsn: "...",
// ...
integrations: [
// ...,
new Sentry.Integrations.Http({ tracing: true }),
new Tracing.Integrations.Express({
app: adapterHost.httpAdapter.getInstance(),
}),
] as Integration[],
tracesSampleRate: 1.0,
}),
})
App Init
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.use(Sentry.Handlers.tracingHandler());
await app.listen(8080);
from nestjs-sentry.
here is some code, maybe help you
import { Plugin } from '@nestjs/apollo'
import { ApolloServerPlugin, GraphQLRequestListener } from 'apollo-server-plugin-base'
import { InjectSentry, SentryService } from '@ntegral/nestjs-sentry'
import { GraphQLRequestContext } from 'apollo-server-types'
import '@sentry/tracing'
/**
* @document: https://develop.sentry.dev/sdk/event-payloads/request/
* @document: https://github.com/ntegral/nestjs-sentry/issues/63
* @document: https://www.apollographql.com/docs/apollo-server/integrations/plugins/
* @document: https://blog.sentry.io/2021/08/31/guest-post-performance-monitoring-in-graphql
* @document: https://github.com/getsentry/sentry-javascript/issues/4731
*/
@Plugin()
export class SentryPlugin implements ApolloServerPlugin {
constructor(@InjectSentry() private readonly sentry: SentryService) {}
async requestDidStart({ request, context }: GraphQLRequestContext): Promise<GraphQLRequestListener> {
const transaction = this.sentry.instance().startTransaction({
op: 'gql',
name: request.operationName ? `graphql: ${request.operationName}` : 'GraphQLTransaction'
})
this.sentry
.instance()
.getCurrentHub()
.configureScope(scope => {
const { headers, body: data, method, baseUrl: url } = context.req
scope.addEventProcessor(event => {
event.request = { method, url, headers, data }
return event
})
})
this.sentry.instance().configureScope(scope => {
scope.setSpan(transaction)
})
return {
// hook for transaction finished
async willSendResponse() {
transaction.finish()
},
async executionDidStart() {
return {
// hook for each new resolver
willResolveField({ info }) {
const span = transaction.startChild({
op: 'resolver',
description: `${info.parentType.name}.${info.fieldName}`
})
// this will execute once the resolver is finished
return () => {
span.finish()
}
}
}
}
}
}
}
I update code to below to solve some problems of tracing overflow
@Plugin()
export class SentryPlugin implements ApolloServerPlugin {
constructor(@InjectSentry() private readonly sentry: SentryService) {}
async requestDidStart({ request, context }: GraphQLRequestContext): Promise<GraphQLRequestListener> {
context.transaction = this.sentry.instance().startTransaction({
op: 'gql',
name: request.operationName ? `graphql: ${request.operationName}` : 'graphql: withoutOperationName'
})
this.sentry
.instance()
.getCurrentHub()
.configureScope(scope => {
scope.addEventProcessor(event => {
const { headers, body: data, method, baseUrl: url } = context.req
// eslint-disable-next-line no-param-reassign
event.request = { method, url, headers, data }
return event
})
})
this.sentry.instance().configureScope(scope => {
scope.setSpan(context.transaction)
})
return {
// hook for transaction finished
async willSendResponse({ context }) {
context.transaction.finish()
},
async executionDidStart() {
return {
// hook for each new resolver
willResolveField({ context, info }) {
const span = context.transaction.startChild({
op: 'resolver',
description: `${info.parentType.name}.${info.fieldName}`
})
// this will execute once the resolver is finished
return () => {
span.finish()
}
}
}
}
}
}
}
from nestjs-sentry.
@CalMlynarczyk it seems your example has become outdated. Tracing.Integrations.Express
is deprecated in @sentry/tracing
. But even without that, it seems that only my first request to the server works after adding app.use(Sentry.Handlers.tracingHandler());
. After that, the server stops responding to requests (but is still running). This is with @sentry/node running on ^6.13.3.
Are you using this sample still?
Update:
I got it working on @sentry/node 7.69.0 without using Tracing.Integrations.Express
:
SentryModule.forRoot({
dsn: process.env.SENTRY_DSN,
// ...
integrations: [
new Sentry.Integrations.Http({ tracing: true })
] as unknown as Integration[],
}),
from nestjs-sentry.
Related Issues (20)
- Custom exception does not work in SentryInterceptor HOT 4
- Sentry Profiling Integration doesn't work HOT 8
- Exception objectError does not work
- unmet peer rimraf@^3.0.2: found 4.1.2
- Make app name in sentryService customizable HOT 1
- Argument of type 'undefined' is not assignable to parameter of type 'string | symbol'
- Is this project still maintained? HOT 7
- nestjs 10 support HOT 5
- Getting error in the latest version of nestjs (v10) HOT 6
- Remove 'rimraf' unused dependency HOT 1
- Request for Updating 'reflect-metadata' Package Version in Project HOT 2
- Can not install in NestJS 9
- Official Sentry Nest.js support in `8.x` of the Sentry SDK HOT 4
- Cannot read properties of undefined (reading 'OnUncaughtException') HOT 3
- NestJs 9 Support HOT 7
- How to inject into another module? HOT 4
- Why does my Sentry errors look like this? HOT 1
- Integrate Sentry Prisma ORM HOT 2
- Update imports of `@sentry/hub` to use `@sentry/core`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nestjs-sentry.