Search in sources :

Example 1 with SamplingStrategy

use of io.fabric8.apmagent.strategy.sampling.SamplingStrategy in project fabric8 by fabric8io.

the class ApmAgent method initialize.

/**
 * @return false if already initialized, else true if is actually initialized
 */
public boolean initialize(final Instrumentation instrumentation, String args) throws Exception {
    boolean result;
    if ((result = initialized.compareAndSet(false, true))) {
        this.instrumentation = instrumentation;
        PropertyUtils.setProperties(configuration, args);
        configuration.addChangeListener(this);
        apmAgentContext.initialize();
        ApmConfiguration.STRATEGY theStrategy = configuration.getStrategyImpl();
        switch(theStrategy) {
            case TRACE:
                this.strategy = new TraceStrategy(apmAgentContext, instrumentation);
                LOG.debug("Using Trace strategy");
                break;
            default:
                this.strategy = new SamplingStrategy(apmAgentContext);
                LOG.debug("Using Sampling strategy");
        }
        this.strategy.initialize();
        // add shutdown hook
        Thread cleanup = new Thread() {

            @Override
            public void run() {
                try {
                    ApmAgent apmAgent = ApmAgent.INSTANCE;
                    apmAgent.shutDown();
                } catch (Exception e) {
                    LOG.warn("Failed to run shutdown hook due " + e.getMessage(), e);
                }
            }
        };
        Runtime.getRuntime().addShutdownHook(cleanup);
    }
    return result;
}
Also used : TraceStrategy(io.fabric8.apmagent.strategy.trace.TraceStrategy) SamplingStrategy(io.fabric8.apmagent.strategy.sampling.SamplingStrategy)

Example 2 with SamplingStrategy

use of io.fabric8.apmagent.strategy.sampling.SamplingStrategy in project fabric8 by jboss-fuse.

the class ApmAgent method initialize.

/**
 * @param instrumentation
 * @param args
 * @return false if already initialized, else true if is actually initialized
 */
public boolean initialize(final Instrumentation instrumentation, String args) throws Exception {
    boolean result;
    if ((result = initialized.compareAndSet(false, true))) {
        this.instrumentation = instrumentation;
        PropertyUtils.setProperties(configuration, args);
        configuration.addChangeListener(this);
        apmAgentContext.initialize();
        ApmConfiguration.STRATEGY theStrategy = configuration.getStrategyImpl();
        switch(theStrategy) {
            case TRACE:
                this.strategy = new TraceStrategy(apmAgentContext, instrumentation);
                LOG.info("Using Trace strategy");
                break;
            default:
                this.strategy = new SamplingStrategy(apmAgentContext);
                LOG.info("Using Sampling strategy");
        }
        this.strategy.initialize();
        // add shutdown hook
        Thread cleanup = new Thread() {

            @Override
            public void run() {
                try {
                    ApmAgent apmAgent = ApmAgent.INSTANCE;
                    apmAgent.shutDown();
                } catch (Exception e) {
                    LOG.error("Failed to run shutdown hook", e);
                }
            }
        };
        Runtime.getRuntime().addShutdownHook(cleanup);
    }
    return result;
}
Also used : TraceStrategy(io.fabric8.apmagent.strategy.trace.TraceStrategy) SamplingStrategy(io.fabric8.apmagent.strategy.sampling.SamplingStrategy)

Aggregations

SamplingStrategy (io.fabric8.apmagent.strategy.sampling.SamplingStrategy)2 TraceStrategy (io.fabric8.apmagent.strategy.trace.TraceStrategy)2