Java Code Examples for io.opentracing.util.GlobalTracer#isRegistered()
The following examples show how to use
io.opentracing.util.GlobalTracer#isRegistered() .
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: JaegerDeploymentRecorder.java From quarkus with Apache License 2.0 | 6 votes |
private void registerTracer(JaegerConfig jaeger, ApplicationConfig appConfig, MetricsFactory metricsFactory) { if (!jaeger.serviceName.isPresent()) { if (appConfig.name.isPresent()) { jaeger.serviceName = appConfig.name; } else { jaeger.serviceName = UNKNOWN_SERVICE_NAME; } } initTracerConfig(jaeger); quarkusTracer.setMetricsFactory(metricsFactory); quarkusTracer.reset(); // register Quarkus tracer to GlobalTracer. // Usually the tracer will be registered only here, although consumers // could register a different tracer in the code which runs before this class. // This is also used in tests. if (!GlobalTracer.isRegistered()) { log.debugf("Registering tracer to GlobalTracer %s", quarkusTracer); GlobalTracer.register(quarkusTracer); } }
Example 2
Source File: TracerResolverListener.java From thorntail with Apache License 2.0 | 6 votes |
@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: XioTracing.java From xio with Apache License 2.0 | 6 votes |
public XioTracing(TracingConfig config) { name = config.getApplicationName(); TracingConfig.TracingType type = config.getType(); switch (type) { case ZIPKIN: String zipkinUrl = config.getZipkinUrl(); float samplingRate = config.getZipkinSamplingRate(); Tracing tracing = buildZipkinTracing(this.name, zipkinUrl, samplingRate); if (tracing != null) { tracer = BraveTracer.create(tracing); } break; case DATADOG: if (GlobalTracer.isRegistered()) { tracer = GlobalTracer.get(); } else { tracer = new DDTracer(); GlobalTracer.register(tracer); } break; } log.info("Configured tracer type: {}", type.toString()); }
Example 4
Source File: Main.java From batfish with Apache License 2.0 | 6 votes |
private static void mainRun(BindPortFutures portFutures) { try { initAuthorizer(); initPoolManager(portFutures); if (_settings.getTracingEnable() && !GlobalTracer.isRegistered()) { initTracer(); } initWorkManager(portFutures); } catch (Exception e) { System.err.println( "org.batfish.coordinator: Initialization of a helper failed: " + Throwables.getStackTraceAsString(e)); System.exit(1); } // sleep indefinitely, in 10 minute chunks try { while (true) { Thread.sleep(10 * 60 * 1000); // 10 minutes _logger.info("Still alive .... waiting for work to show up\n"); } } catch (Exception ex) { String stackTrace = Throwables.getStackTraceAsString(ex); System.err.println(stackTrace); } }
Example 5
Source File: TracingUtil.java From hadoop-ozone with Apache License 2.0 | 5 votes |
/** * Initialize the tracing with the given service name. */ public static void initTracing( String serviceName, ConfigurationSource conf) { if (!GlobalTracer.isRegistered() && isTracingEnabled(conf)) { Configuration config = Configuration.fromEnv(serviceName); JaegerTracer tracer = config.getTracerBuilder() .registerExtractor(StringCodec.FORMAT, new StringCodec()) .registerInjector(StringCodec.FORMAT, new StringCodec()) .build(); GlobalTracer.register(tracer); } }
Example 6
Source File: TracingUtil.java From hadoop-ozone with Apache License 2.0 | 5 votes |
private static SpanContext extractParent(String parent, Tracer tracer) { if (!GlobalTracer.isRegistered()) { return null; } if (parent == null || parent.isEmpty()) { return null; } return tracer.extract(StringCodec.FORMAT, new StringBuilder(parent)); }
Example 7
Source File: TracedService.java From java-grpc with Apache License 2.0 | 5 votes |
@Override public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) { // verify that there is an active span in case of using GlobalTracer: if (GlobalTracer.isRegistered() && GlobalTracer.get().activeSpan() == null) { throw new RuntimeException("no active span"); } HelloReply reply = HelloReply.newBuilder().setMessage("Hello " + req.getName()).build(); responseObserver.onNext(reply); responseObserver.onCompleted(); }
Example 8
Source File: OpenTracingHelper.java From java-agent with Apache License 2.0 | 5 votes |
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 9
Source File: ShardingTracer.java From shardingsphere with Apache License 2.0 | 4 votes |
/** * Initialize sharding tracer. * * @param tracer opentracing tracer */ public static void init(final Tracer tracer) { if (!GlobalTracer.isRegistered()) { GlobalTracer.register(tracer); } }
Example 10
Source File: Client.java From batfish with Apache License 2.0 | 4 votes |
public void run(List<String> initialCommands) { if (_settings.getTracingEnable() && !GlobalTracer.isRegistered()) { initTracer(); } loadPlugins(); initHelpers(); _logger.debugf( "Will use coordinator at %s://%s\n", (_settings.getSslDisable()) ? "http" : "https", _settings.getCoordinatorHost()); if (!processCommands(initialCommands)) { return; } // set container if specified if (_settings.getContainerId() != null && !processCommand(Command.SET_NETWORK.commandName() + " " + _settings.getContainerId())) { return; } // set testrig if dir or id is specified if (_settings.getSnapshotDir() != null) { if (_settings.getSnapshotId() != null) { System.err.println("org.batfish.client: Cannot supply both snapshotDir and snapshotId."); System.exit(1); } if (!processCommand(Command.INIT_SNAPSHOT.commandName() + " " + _settings.getSnapshotDir())) { return; } } if (_settings.getSnapshotId() != null && !processCommand(Command.SET_SNAPSHOT.commandName() + " " + _settings.getSnapshotId())) { return; } switch (_settings.getRunMode()) { case batch: { runBatchFile(); break; } case interactive: { runInteractive(); break; } default: System.err.println("org.batfish.client: Unknown run mode."); System.exit(1); } }
Example 11
Source File: Driver.java From batfish with Apache License 2.0 | 4 votes |
private static void mainRunWorkService() { if (_mainSettings.getTracingEnable() && !GlobalTracer.isRegistered()) { initTracer(); } String protocol = _mainSettings.getSslDisable() ? "http" : "https"; String baseUrl = String.format("%s://%s", protocol, _mainSettings.getServiceBindHost()); URI baseUri = UriBuilder.fromUri(baseUrl).port(_mainSettings.getServicePort()).build(); _mainLogger.debug(String.format("Starting server at %s\n", baseUri)); ResourceConfig rc = new ResourceConfig(Service.class).register(new JettisonFeature()); if (_mainSettings.getTracingEnable()) { rc.register(ServerTracingDynamicFeature.class); } try { HttpServer server; if (_mainSettings.getSslDisable()) { server = GrizzlyHttpServerFactory.createHttpServer(baseUri, rc); } else { server = CommonUtil.startSslServer( rc, baseUri, _mainSettings.getSslKeystoreFile(), _mainSettings.getSslKeystorePassword(), _mainSettings.getSslTrustAllCerts(), _mainSettings.getSslTruststoreFile(), _mainSettings.getSslTruststorePassword(), ConfigurationLocator.class, Driver.class); } int selectedListenPort = server.getListeners().iterator().next().getPort(); if (_mainSettings.getCoordinatorRegister()) { // this function does not return until registration succeeds registerWithCoordinatorPersistent(selectedListenPort); } // sleep indefinitely, check for coordinator each time while (true) { Thread.sleep(COORDINATOR_CHECK_INTERVAL_MS); /* * every time we wake up, we check if the coordinator has polled us recently * if not, re-register the service. the coordinator might have died and come back. */ if (_mainSettings.getCoordinatorRegister() && new Date().getTime() - _lastPollFromCoordinator.getTime() > COORDINATOR_POLL_TIMEOUT_MS) { // this function does not return until registration succeeds registerWithCoordinatorPersistent(selectedListenPort); } } } catch (ProcessingException e) { String msg = "FATAL ERROR: " + e.getMessage() + "\n"; _mainLogger.error(msg); System.exit(1); } catch (Exception ex) { String stackTrace = Throwables.getStackTraceAsString(ex); _mainLogger.error(stackTrace); System.exit(1); } }