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

@Scheduled doesn't work out of the box #125

Closed
innokenty opened this issue Jun 12, 2018 · 6 comments
Closed

@Scheduled doesn't work out of the box #125

innokenty opened this issue Jun 12, 2018 · 6 comments

Comments

@innokenty
Copy link
Contributor

innokenty commented Jun 12, 2018

I have a spring-boot project with tracer added (more details below). Configuration is just the default one, just the trace name is configured. I'm trying to get my trace value in a @Scheduled method, but I get IllegalStateException: X-Flow-ID has not been started.

Question: how is it supposed to work? I think the documentation on this is missing.

Description

  • I'm running on spring-boot:1.4.6.
  • I have only tracer-spring-boot-starter:0.16.0 in dependencies.
  • I have configured only this single property for tracer: tracer.traces.X-Flow-ID=flow-id
  • I have a @Scheduled method inside of which I'm calling tracer.get("X-Flow-ID").getValue() on an @Autowired Tracer tracer field.
  • Autowiring works, but I get the following exception:
java.lang.IllegalStateException: X-Flow-ID has not been started
	at org.zalando.tracer.DefaultTracer.getAndCheckValue(DefaultTracer.java:102) ~[tracer-core-0.16.0.jar:na]
	at org.zalando.tracer.DefaultTracer.access$000(DefaultTracer.java:15) ~[tracer-core-0.16.0.jar:na]
	at org.zalando.tracer.DefaultTracer$1.getValue(DefaultTracer.java:68) ~[tracer-core-0.16.0.jar:na]

Question

I didn't really find any docs of what a "support for scheduling" means. I'm sure I'm doing something wrong, but can you point out what's missing? I was expecting that the trace will be already initialized and I can just get it's value (and send in an outgoing request).

@innokenty innokenty changed the title How does tracer work with @Schdeuled? How does tracer work with @Scheduled? Jun 12, 2018
@whiskeysierra
Copy link
Contributor

That sounds like the correct setup to me. Can you compare your setup to this test? Maybe there is an obvious difference somewhere? Do you register a custom TaskScheduler or something? Maybe you can put some breakpoints in the SchedulingAutoConfiguration to see whether it's executed correctly.

@innokenty
Copy link
Contributor Author

It works on an empty project indeed. I think the scheduler configuration doesn't work properly in this case. Not sure why, but I think the conditional taskScheduler bean is simply not created. In my log I see only:

org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler - Initializing ExecutorService  'taskScheduler'

ANd no more relevant mentions of taskScheduler.

How is this supposed to work, if a bean with this name and type is already present?

@innokenty
Copy link
Contributor Author

innokenty commented Jun 18, 2018

Turned out the problem was that my project already had a TaskScheduler bean configured (see below). And that's why tracer's autoconfiguration was not running, since it's conditional.

@Configuration
public class TaskSchedulerConfig {
    @Bean
    public ThreadPoolTaskScheduler taskScheduler() {
        return new ThreadPoolTaskScheduler();
    }
}

Maybe it would a great idea to somehow make this configuration not conditional, but make it extend whatever schedulers there are already in the context?

And if someone stumbles upon that thread some day: check if you already have a taskScheduler bean defined, guys! It ain't gonna work!!

@innokenty innokenty changed the title How does tracer work with @Scheduled? @Scheduled doesn't work out of the box Jun 20, 2018
@Sam-Kruglov
Copy link

Just got the same error. Had to copy paste bean definition from org.zalando.tracer.spring.TracerAutoConfiguration.AsyncAutoConfiguration#taskExecutor without condition. Worked, thanks

@Sam-Kruglov
Copy link

@whiskeysierra it doesn't make sense to have both @Primary and @ConditionalOnMissingBean

@whiskeysierra
Copy link
Contributor

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