Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instrument @nestjs/cache-manager in @sentry/nestjs #12824

Open
Tracked by #12504
nicohrubec opened this issue Jul 9, 2024 · 0 comments
Open
Tracked by #12504

Instrument @nestjs/cache-manager in @sentry/nestjs #12824

nicohrubec opened this issue Jul 9, 2024 · 0 comments
Labels
Package: nestjs Issues related to the Sentry Nestjs SDK

Comments

@nicohrubec
Copy link
Contributor

nicohrubec commented Jul 9, 2024

https://docs.nestjs.com/techniques/caching

Potential solutions:

  • Root Module: Add a module that provides a caching service with updated cache methods that users can use instead of the native nest cache mdoule. This takes away some of the hassle of manual instrumentation, but is still a lot of extra effort for users.
  • Simple utility functions: We can write simple functions that wrap the native nest caching methods.This is already much better than manual instrumentation but still not too nice because users need to wrap everything.
  • Fully automatic: Write a otel instrumentation that does automatic instrumentation of cache operations. This is definitely the ideal solution from a user perspective.

Notes from initial experimentation with fully automatic approach:
The CacheManager instances usually get injected in the constructor with the @Inject decorator. So my initial idea was to patch that decorator. I have experimented with this but not yet make it work. I initially expected that we would directly be able to access and patch the injected instance directly but instead we get the whole class as service and it is non-trivial to get the actual cache instance from that. There is a WIP PR open for this. Potentially we can try to monkey-patch the constructor and then check if there is a property of the CacheManager type on the service after the constructor was executed.

Another approach I tried was to "exploit" the DI system of nestjs. I was hoping that there is a singleton cache instance in the DI container that is being used wherever the user injects a cache instance. So I added a service to the root module that injected the cache manager and proxied it. The hope was that this would carry to other service instances injecting the cache in the same application but did not work out.

@nicohrubec nicohrubec mentioned this issue Jul 9, 2024
@nicohrubec nicohrubec self-assigned this Jul 9, 2024
@nicohrubec nicohrubec added the Package: nestjs Issues related to the Sentry Nestjs SDK label Jul 9, 2024
@nicohrubec nicohrubec changed the title Implement Cache module in @sentry/nestjs for built-in cache similar to how Django cache module works Instrument @nestjs/cache-manager in @sentry/nestjs Jul 23, 2024
@nicohrubec nicohrubec removed their assignment Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nestjs Issues related to the Sentry Nestjs SDK
Projects
None yet
Development

No branches or pull requests

1 participant