#injecting service into decorator
1 messages · Page 1 of 1 (latest)
I think you are looking for Interceptors : https://docs.nestjs.com/interceptors
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).
I don't think so - I want to trace just a single method not a whole request
you could set a metadata key for the decorated method and on startup wrap all methods that have this metadata with a trace function
While it's not possible to inject a service into a decorator, you can take a method decorator and modify the descriptor.value to reference the class's injected values. I have an example of this with my ogma package where I provide a @Log() method that printed a log at the beginning and end of the method for tracing purposes
@gleaming flume Could you share a link for that please ?
@cosmic sierra If you need to generate traces, just go with OTEL. There's no point in inventing a custom solution. https://www.npmjs.com/package/nestjs-otel
Thank you very much 🙏
ok, I agree with traces, but there's probably no "standardized" way of measuring time of execution of some method for metrics purposes, correct? so the only way is to write some custom decorator
I think otel can do metrics this way too, let me check
@OtelHistorgram might do that