You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Interceptors are a bit harder than the other constructs we have instrumented so far. All interceptors get a CallHandler implementing a handle() method, which can be used to invoke the route execution. So interceptors basically wrap the execution of the route and therefore allow you to add logic before and after the route execution. Ideally, we would like to collect a span before the route and one span after the route execution for each interceptor.
Solution: According to the docs interceptors are annotated with the @Injectable decorator and implement a intercept method. We can use that to hook into the framework.
Before Route: This worked without any issues. We can start a span shortly before calling intercept() and then proxy CallHandler.next() to end the span before the route is actually executed.
After Route: This is much harder. After the route execution is done an rxjs Observable is returned, which users can chain arbitrary operations to, which in turn might lead to new Observable objects being created etc. We ran into various issues trying to make these spans work for individual interceptors. In the end we simplified the approach and now we just create one span that traces anything that happens after the route execution. Specifically this means that if there are multiple interceptors with logic after the rout execution, we only send exactly one span to Sentry encapsulating the logic for all these interceptors.
Limitation: Although the nest docs say that interceptors should always have an @Injectable decorator, interceptors work just fine without it unless it has dependencies on other services.
The text was updated successfully, but these errors were encountered:
Hey @rubiin, thanks for the suggestion. However, I think this is different to what we are trying to achieve here. The goal of this ticket is not to capture exceptions but to get performance tracing for operations that happen within user-defined interceptors. The error reporting is currently implemented with global error filters.
https://docs.nestjs.com/interceptors
Interceptors are a bit harder than the other constructs we have instrumented so far. All interceptors get a
CallHandler
implementing ahandle()
method, which can be used to invoke the route execution. So interceptors basically wrap the execution of the route and therefore allow you to add logic before and after the route execution. Ideally, we would like to collect a span before the route and one span after the route execution for each interceptor.Solution: According to the docs interceptors are annotated with the
@Injectable
decorator and implement aintercept
method. We can use that to hook into the framework.Before Route: This worked without any issues. We can start a span shortly before calling
intercept()
and then proxyCallHandler.next()
to end the span before the route is actually executed.After Route: This is much harder. After the route execution is done an rxjs
Observable
is returned, which users can chain arbitrary operations to, which in turn might lead to newObservable
objects being created etc. We ran into various issues trying to make these spans work for individual interceptors. In the end we simplified the approach and now we just create one span that traces anything that happens after the route execution. Specifically this means that if there are multiple interceptors with logic after the rout execution, we only send exactly one span to Sentry encapsulating the logic for all these interceptors.Limitation: Although the nest docs say that interceptors should always have an @Injectable decorator, interceptors work just fine without it unless it has dependencies on other services.
The text was updated successfully, but these errors were encountered: