io.opentracing.contrib.tracerresolver.TracerResolver Java Examples

The following examples show how to use io.opentracing.contrib.tracerresolver.TracerResolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SkipPatternTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Deployment
public static Archive createDeployment() throws Exception {
    WARArchive deployment = ShrinkWrap.create(WARArchive.class);

    // on real world deployments, these parts would come from a dependency of the target application
    deployment.addClass(MockTracerResolver.class);
    deployment.addPackage(MockTracer.class.getPackage());
    deployment.addAsServiceProvider(TracerResolver.class, MockTracerResolver.class);

    // this is a simple servlet, that we can hit with our tests
    deployment.addClass(SimpleServlet.class);
    deployment.addClass(HealthServlet.class);
    deployment.addAsResource("project-skip-pattern.yml", "/project-defaults.yml");

    return deployment;
}
 
Example #2
Source File: TracerResolverListener.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public void contextInitialized(ServletContextEvent sce) {
  ServletContext servletContext = sce.getServletContext();

  String skipParameter = servletContext.getInitParameter("skipOpenTracingResolver");
  if (skipParameter != null && Boolean.parseBoolean(skipParameter)) {
    logger.info("Skipping the OpenTracing TracerResolver. "
        + "Your application is expected to set a tracer to GlobalTracer explicitly.");
    return;
  }
  if (GlobalTracer.isRegistered()) {
    logger.info("A Tracer is already registered at the GlobalTracer. Skipping resolution via TraceResolver.");
  }

  Tracer tracer = TracerResolver.resolveTracer();
  if (tracer != null) {
    logger.info(String.format("Registering resolved tracer %s to GlobalTracer.",
        tracer.getClass().getCanonicalName()));
    GlobalTracer.register(tracer);
  } else {
    logger.info("No Tracerresolver found on classpath!");
  }
}
 
Example #3
Source File: OpenTracingHelper.java    From java-agent with Apache License 2.0 5 votes vote down vote up
protected void initTracer() {
    synchronized (SYNC) {
        if (tracer == null) {
            if (!GlobalTracer.isRegistered()) {
                boolean triggeringState = Rule.isTriggeringEnabled();
                if (!allowInstrumentedTracer() && triggeringState) {
                    // Temporarily disable triggering of rules unless we have explicitly allowed
                    // the tracer to be instrumented.
                    setTriggering(false);
                }
                try {
                    // Try to obtain a tracer using the TracerResolver
                    Tracer resolved = TracerResolver.resolveTracer();
                    if (resolved != null) {
                        try {
                            GlobalTracer.register(resolved);
                        } catch (RuntimeException re) {
                            log.log(Level.WARNING,
                                    "Failed to register tracer '" + resolved + "'", re);
                        }
                    }
                } finally {
                    setTriggering(triggeringState);
                }
            }
            // Initialize the tracer even if one has not been registered
            // (i.e. it will use a NoopTracer under the covers)
            tracer = new AgentTracer(GlobalTracer.get());
        }
    }
}
 
Example #4
Source File: TraceResolverOnDeploymentTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive createDeployment() throws Exception {
    WARArchive deployment = ShrinkWrap.create(WARArchive.class);

    // on real world deployments, these parts would come from a dependency of the target application
    deployment.addClass(MockTracerResolver.class);
    deployment.addPackage(MockTracer.class.getPackage());
    deployment.addAsServiceProvider(TracerResolver.class, MockTracerResolver.class);

    // this is a simple servlet, that we can hit with our tests
    deployment.addClass(SimpleServlet.class);
    deployment.addClass(AsyncServlet.class);

    return deployment;
}
 
Example #5
Source File: DeploymentProcessor.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public void process(Archive<?> archive, TestClass testClass) {
  JavaArchive extensionsJar = ShrinkWrap.create(JavaArchive.class,"mp-ot-mocktracer-resolver.jar")
               .addAsServiceProvider(TracerResolver.class, MockTracerResolver.class);
  extensionsJar.addAsServiceProvider(Providers.class, ExceptionMapper.class);
  extensionsJar.addClass(MockTracerResolver.class);
  extensionsJar.addClass(ExceptionMapper.class);
  extensionsJar.addPackages(true, "io.opentracing.tracerresolver", "io.opentracing.mock");

  WebArchive war = WebArchive.class.cast(archive);
  war.addAsLibraries(extensionsJar);
  war.setWebXML("web.xml");
}
 
Example #6
Source File: TracerProducer.java    From thorntail with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves tracer instance to be used. It is using {@link TracerResolver} service loader to find
 * the tracer. It tracer is not resolved it will use {@link io.opentracing.noop.NoopTracer}.
 *
 * @return tracer instance
 */
@Default
@Produces
@Singleton
public Tracer produceTracer() {
  // TCK casts to MockTracer so we cannot use GlobalTracer as a bean!
  Tracer tracer = TracerResolver.resolveTracer();
  if (tracer == null) {
    tracer = GlobalTracer.get();
  }
  logger.info(String.format("Registering %s to GlobalTracer and providing it as CDI bean.", tracer));
  GlobalTracer.register(tracer);
  return tracer;
}
 
Example #7
Source File: OpenTracingHelperTest.java    From java-agent with Apache License 2.0 4 votes vote down vote up
@Before
public void reloadResolverProviderCaches() {
    TracerResolver.reload();
}
 
Example #8
Source File: TracerProvider.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
public TracerProvider() {
  this(TracerResolver.resolveTracer());
}
 
Example #9
Source File: ApplicationConfig.java    From hono with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Exposes an OpenTracing {@code Tracer} as a Spring Bean.
 * <p>
 * The Tracer will be resolved by means of a Java service lookup.
 * If no tracer can be resolved this way, the {@code NoopTracer} is
 * returned.
 *
 * @return The tracer.
 */
@Bean
public Tracer getTracer() {

    return Optional.ofNullable(TracerResolver.resolveTracer())
            .orElse(NoopTracerFactory.create());
}
 
Example #10
Source File: ApplicationConfig.java    From hono with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Exposes an OpenTracing {@code Tracer} as a Spring Bean.
 * <p>
 * The Tracer will be resolved by means of a Java service lookup.
 * If no tracer can be resolved this way, the {@code NoopTracer} is
 * returned.
 *
 * @return The tracer.
 */
@Bean
public Tracer getTracer() {

    return Optional.ofNullable(TracerResolver.resolveTracer())
            .orElse(NoopTracerFactory.create());
}
 
Example #11
Source File: ApplicationConfig.java    From hono with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Exposes an OpenTracing {@code Tracer} as a Spring Bean.
 * <p>
 * The Tracer will be resolved by means of a Java service lookup.
 * If no tracer can be resolved this way, the {@code NoopTracer} is
 * returned.
 *
 * @return The tracer.
 */
@Bean
public Tracer getTracer() {

    return Optional.ofNullable(TracerResolver.resolveTracer())
            .orElse(NoopTracerFactory.create());
}
 
Example #12
Source File: AbstractAdapterConfig.java    From hono with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Exposes an OpenTracing {@code Tracer} as a Spring Bean.
 * <p>
 * The Tracer will be resolved by means of a Java service lookup.
 * If no tracer can be resolved this way, the {@code NoopTracer} is
 * returned.
 *
 * @return The tracer.
 */
@Bean
public Tracer getTracer() {

    return Optional.ofNullable(TracerResolver.resolveTracer())
            .orElse(NoopTracerFactory.create());
}
 
Example #13
Source File: TracerConfiguration.java    From enmasse with Apache License 2.0 3 votes vote down vote up
/**
 * Exposes an OpenTracing {@code Tracer} as a Spring Bean.
 * <p>
 * The Tracer will be resolved by means of a Java service lookup.
 * If no tracer can be resolved this way, the {@code NoopTracer} is
 * returned.
 *
 * @return The tracer.
 */
@Bean
public Tracer getTracer() {

    return Optional
            .ofNullable(TracerResolver.resolveTracer())
            .orElse(NoopTracerFactory.create());
}
 
Example #14
Source File: TracerConfiguration.java    From enmasse with Apache License 2.0 3 votes vote down vote up
/**
 * Exposes an OpenTracing {@code Tracer} as a Spring Bean.
 * <p>
 * The Tracer will be resolved by means of a Java service lookup.
 * If no tracer can be resolved this way, the {@code NoopTracer} is
 * returned.
 *
 * @return The tracer.
 */
@Bean
public Tracer getTracer() {

    return Optional
            .ofNullable(TracerResolver.resolveTracer())
            .orElse(NoopTracerFactory.create());
}
 
Example #15
Source File: TracerConfiguration.java    From enmasse with Apache License 2.0 3 votes vote down vote up
/**
 * Exposes an OpenTracing {@code Tracer} as a Spring Bean.
 * <p>
 * The Tracer will be resolved by means of a Java service lookup.
 * If no tracer can be resolved this way, the {@code NoopTracer} is
 * returned.
 *
 * @return The tracer.
 */
@Bean
public Tracer getTracer() {

    return Optional
            .ofNullable(TracerResolver.resolveTracer())
            .orElse(NoopTracerFactory.create());
}