nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.73k stars 7.63k forks source link

Execution time decorator #14119

Closed 40oleg closed 1 day ago

40oleg commented 5 days ago

Is there an existing issue that is already proposing this?

Is your feature request related to a problem? Please describe it

Trying to determine bottleneck of app.

Describe the solution you'd like

It would be great to add some decorators that could handle the execution time of some endpoint and log logs if something runs longer than some threshold. @MaxExecutionTime(N), where N is the waiting time in milliseconds

If the endpoint execution time is less than N, then nothing happens, but otherwise the message "the SOME_METHOD method performed much more than expected" appears.

Teachability, documentation, adoption, migration strategy

It does not need any migration. It just a decorator that have some logging execution time logic

What is the motivation / use case for changing the behavior?

I'm building a distributed system on nest, and one of the connected systems is returning responses too slowly. I could have handled this situation by just looking at the logs, but I needed to check the client settings and the code.

micalevisk commented 4 days ago

you can write an interceptor for that and then:

const MaxExecutionTime = (n) => UseInterceptors(TimeoutInterceptor(n))

So I'd say that this is too specific to leave under @nestjs/* scope.