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

Spring plugin misses classes injected with @Bean method instead of @Component #955

Open
MFAshby opened this issue Oct 4, 2022 · 1 comment

Comments

@MFAshby
Copy link

MFAshby commented Oct 4, 2022

There are 2 ways of doing dependency injection in Spring, either annotations on the classes to be inject with @Component and friends, or via @Configuration classes with @Bean methods.

It seems like some of the spring glowroot config explicitly looks for @Component annotation, which means that beans injected with @Bean methods aren't traced. Example code:

public class FooService {
  @Scheduled(fixedDelay = 100)
  public void fooSchedule() {
    System.out.println("Hi");
  }
}
...
@Configuration
public class FooConfig {
  @Bean fooService() {
    return new FooService();
  }
}
...
@Component
public class BarService {
  @Scheduled(fixedDelay = 100)
  public void barSchedule() {
    System.out.println("good morning");
  }
}

Only scheduled tasks from BarService would appear in glowroot under 'Background' transactions. The scheduled method in FooService is ignored.

@MFAshby
Copy link
Author

MFAshby commented Oct 4, 2022

I tried an alternative instrumentation approach like this;

{
  "className": "ScheduledMethodRunnable",
  "methodName": "run",
  "methodParameterTypes": [],
  "captureKind": "transaction",
  "transactionType": "Background",
  "transactionNameTemplate": "Spring scheduled: {{this.method}}",
  "traceEntryMessageTemplate": "Spring scheduled: {{this.method}}",
  "timerName": "spring scheduled"
}

but it didn't capture anything. For now I'm going to change my code to use @Component based injection instead; but this has the downside it is less flexible than @Bean based injection; since that can be used to inject any class without modifying the source.

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

1 participant