nestjs-sentry
nestjs-sentry copied to clipboard
How to inject into another module?
Hey there!
I am currently importing the module in my AppModule and configure it there. When I try to DI the SentryService into another module's service using @InjectSentry(), I only get this error
Error: Nest can't resolve dependencies of the SomeService ([...], ?). Please make sure that the argument Symbol(SentryToken) at index [11] is available in the SomeModule context.
despite SomeModule imports the SentryModule from this package.
Is it even possible to import the Sentry module without reconfiguring Sentry for the current module which would make it a little bit verbose imho?
Thanks for your help!
@schw4rzlicht I'm having a similar issue and I was wondering if you (or anyone else) has found a solution? I'm having trouble primarily with testing modules that contain the sentry client
It seems like @xiifain might know what's going on?
do you have a minimal reproducible repo for it @schw4rzlicht.
Regarding the testing context, you can import the SentryModule like this example service.spec.ts. @booi
describe('Service', () => {
let service: TestService;
const config: SentryModuleOptions = {
dsn: '',
debug: true,
environment: 'development',
logLevels: ['debug'],
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [SentryModule.forRoot({ ...config })],
providers: [
<your providers>
]
}).compile();
service = module.get<TestService>(TestService);
});
}
@xiifain Thanks for the clarification! I didn't realize I needed to import the sentry module with configuration but it makes sense. I pulled the actual call into it's own file so I could import it in multiple places. Thanks!