Search in sources :

Example 1 with InvocationInstrumenter

use of io.micronaut.scheduling.instrument.InvocationInstrumenter in project micronaut-core by micronaut-projects.

the class ReactorInstrumentation method init.

/**
 * Initialize instrumentation for reactor with the tracer and factory.
 *
 * @param instrumenterFactory The instrumenter factory
 */
@SuppressWarnings("unchecked")
@PostConstruct
void init(ReactorInstrumenterFactory instrumenterFactory) {
    if (instrumenterFactory.hasInstrumenters()) {
        Schedulers.onScheduleHook(Environment.MICRONAUT, runnable -> {
            InvocationInstrumenter instrumenter = instrumenterFactory.create();
            if (instrumenter != null) {
                return () -> {
                    try (Instrumentation ignored = instrumenter.newInstrumentation()) {
                        runnable.run();
                    }
                };
            }
            return runnable;
        });
        Hooks.onEachOperator(Environment.MICRONAUT, Operators.lift((scannable, coreSubscriber) -> {
            if (coreSubscriber instanceof ReactorSubscriber) {
                return coreSubscriber;
            }
            InvocationInstrumenter instrumenter = instrumenterFactory.create();
            if (instrumenter != null) {
                return new ReactorSubscriber<>(instrumenter, coreSubscriber);
            }
            return coreSubscriber;
        }));
    }
}
Also used : Environment(io.micronaut.context.env.Environment) Context(io.micronaut.context.annotation.Context) Operators(reactor.core.publisher.Operators) Hooks(reactor.core.publisher.Hooks) InvocationInstrumenter(io.micronaut.scheduling.instrument.InvocationInstrumenter) Internal(io.micronaut.core.annotation.Internal) ArrayList(java.util.ArrayList) Flux(reactor.core.publisher.Flux) PreDestroy(javax.annotation.PreDestroy) List(java.util.List) ReactiveInvocationInstrumenterFactory(io.micronaut.scheduling.instrument.ReactiveInvocationInstrumenterFactory) Nullable(io.micronaut.core.annotation.Nullable) CollectionUtils(io.micronaut.core.util.CollectionUtils) PostConstruct(javax.annotation.PostConstruct) Requires(io.micronaut.context.annotation.Requires) Schedulers(reactor.core.scheduler.Schedulers) Instrumentation(io.micronaut.scheduling.instrument.Instrumentation) Instrumentation(io.micronaut.scheduling.instrument.Instrumentation) InvocationInstrumenter(io.micronaut.scheduling.instrument.InvocationInstrumenter) PostConstruct(javax.annotation.PostConstruct)

Aggregations

Context (io.micronaut.context.annotation.Context)1 Requires (io.micronaut.context.annotation.Requires)1 Environment (io.micronaut.context.env.Environment)1 Internal (io.micronaut.core.annotation.Internal)1 Nullable (io.micronaut.core.annotation.Nullable)1 CollectionUtils (io.micronaut.core.util.CollectionUtils)1 Instrumentation (io.micronaut.scheduling.instrument.Instrumentation)1 InvocationInstrumenter (io.micronaut.scheduling.instrument.InvocationInstrumenter)1 ReactiveInvocationInstrumenterFactory (io.micronaut.scheduling.instrument.ReactiveInvocationInstrumenterFactory)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PostConstruct (javax.annotation.PostConstruct)1 PreDestroy (javax.annotation.PreDestroy)1 Flux (reactor.core.publisher.Flux)1 Hooks (reactor.core.publisher.Hooks)1 Operators (reactor.core.publisher.Operators)1 Schedulers (reactor.core.scheduler.Schedulers)1