Skip to content

Comments

Fix SentryUserFilter in spring and spring-jakarta samples#4316

Closed
lcian wants to merge 4 commits intomainfrom
lcian/fix/user-filter-spring-samples
Closed

Fix SentryUserFilter in spring and spring-jakarta samples#4316
lcian wants to merge 4 commits intomainfrom
lcian/fix/user-filter-spring-samples

Conversation

@lcian
Copy link
Member

@lcian lcian commented Apr 4, 2025

📜 Description

Previously this was

  @Bean
  SentryUserFilter sentryUserFilter(
      final IScopes scopes, final List<SentryUserProvider> sentryUserProviders) {
    return new SentryUserFilter(scopes, sentryUserProviders);
  }

This didn't register the bean because "Could not autowire. No beans of 'IScopes' type found. ".

This seems to work, not sure if it's the correct approach.

#skip-changelog

@github-actions
Copy link
Contributor

github-actions bot commented Apr 4, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 452.73 ms 455.34 ms 2.61 ms
Size 1.58 MiB 2.08 MiB 505.40 KiB

Previous results on branch: lcian/fix/user-filter-spring-samples

Startup times

Revision Plain With Sentry Diff
e315f51 426.61 ms 443.64 ms 17.03 ms

App size

Revision Plain With Sentry Diff
e315f51 1.58 MiB 2.08 MiB 505.35 KiB

@lcian lcian marked this pull request as draft April 4, 2025 09:47
Copy link
Member

@adinauer adinauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this should work, it sounds like a bug if the bean can't be found. We should investigate that.

@lcian lcian marked this pull request as ready for review April 4, 2025 11:29
@lcian
Copy link
Member Author

lcian commented Apr 4, 2025

While this should work, it sounds like a bug if the bean can't be found. We should investigate that.

I've changed this to use applicationContext.getBean(IScopes.class) to retrieve the bean.
As far as I understand this is the correct way to do it because we register the bean dynamically in SentryHubRegistrar:

  private void registerSentryHubBean(final @NotNull BeanDefinitionRegistry registry) {
    final BeanDefinitionBuilder builder =
        BeanDefinitionBuilder.genericBeanDefinition(ScopesAdapter.class);
    builder.setInitMethodName("getInstance");

    registry.registerBeanDefinition("sentryHub", builder.getBeanDefinition());
  }

So using something like @Autowired private IScopes scopes; would not work.
If I try to retrieve it like that, I get the same error "Could not autowire..." as per the PR description.

@lcian
Copy link
Member Author

lcian commented Apr 17, 2025

This actually works fine, my IDE produces an error because it doesn't know that the bean will be there at runtime, obviously.

@lcian lcian closed this Apr 17, 2025
@lcian lcian deleted the lcian/fix/user-filter-spring-samples branch April 17, 2025 14:06
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

Successfully merging this pull request may close these issues.

2 participants