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

How to inject into another module? #94

Open
schw4rzlicht opened this issue Jul 26, 2022 · 4 comments
Open

How to inject into another module? #94

schw4rzlicht opened this issue Jul 26, 2022 · 4 comments

Comments

@schw4rzlicht
Copy link

schw4rzlicht commented Jul 26, 2022

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!

@booi
Copy link

booi commented Oct 16, 2022

@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

@booi
Copy link

booi commented Oct 16, 2022

It seems like @xiifain might know what's going on?

@xiifain
Copy link
Contributor

xiifain commented Oct 16, 2022

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);
  });
}

@booi
Copy link

booi commented Oct 18, 2022

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants