當前位置: 首頁>>代碼示例>>Java>>正文


Java Tracer類代碼示例

本文整理匯總了Java中io.opentracing.Tracer的典型用法代碼示例。如果您正苦於以下問題:Java Tracer類的具體用法?Java Tracer怎麽用?Java Tracer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Tracer類屬於io.opentracing包,在下文中一共展示了Tracer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testWithStartTimestamp

import io.opentracing.Tracer; //導入依賴的package包/類
@Test
public void testWithStartTimestamp() throws InterruptedException {
    MetricsReporter reporter = Mockito.mock(MetricsReporter.class);
    MockTracer tracer = new MockTracer(new ThreadLocalActiveSpanSource());
    Tracer metricsTracer = Metrics.decorate(tracer, reporter);

    long start = System.currentTimeMillis() * 687;
    Thread.sleep(100);
    ActiveSpan parent = metricsTracer.buildSpan("parent")
            .withStartTimestamp(start)
            .startActive();

    parent.deactivate();

    List<MockSpan> spans = tracer.finishedSpans();
    assertEquals(1, spans.size());
    MockSpan span = spans.get(0);
    long started = span.startMicros();
    assertEquals(start, started);
}
 
開發者ID:opentracing-contrib,項目名稱:java-metrics,代碼行數:21,代碼來源:MetricsTest.java

示例2: buildSpan

import io.opentracing.Tracer; //導入依賴的package包/類
private Scope buildSpan(Tracer tracer, String operationName, StatementInformation statementInformation) {
  try {
    final Scope activeScope = tracer.scopeManager().active();
    final String dbUrl =
        statementInformation.getConnectionInformation().getConnection().getMetaData().getURL();
    if (withActiveSpanOnly(dbUrl) && activeScope == null) {
      return NoopScopeManager.NoopScope.INSTANCE;
    }

    final Tracer.SpanBuilder spanBuilder = tracer
        .buildSpan(operationName)
        .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
    if (activeScope != null) {
      spanBuilder.asChildOf(activeScope.span());
    }
    final Scope scope = spanBuilder.startActive(true);
    decorate(scope.span(), statementInformation);
    return scope;
  } catch (SQLException e) {
    return NoopScopeManager.NoopScope.INSTANCE;
  }
}
 
開發者ID:opentracing-contrib,項目名稱:java-p6spy,代碼行數:23,代碼來源:TracingP6SpyListener.java

示例3: buildAndInjectSpan

import io.opentracing.Tracer; //導入依賴的package包/類
/**
 * Build span and inject. Should be used by producers.
 *
 * @param message JMS message
 * @return span
 */
public static Span buildAndInjectSpan(Destination destination, final Message message,
    Tracer tracer)
    throws JMSException {
  Tracer.SpanBuilder spanBuilder = tracer.buildSpan(TracingMessageUtils.OPERATION_NAME_SEND)
      .ignoreActiveSpan()
      .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_PRODUCER);

  SpanContext parent = TracingMessageUtils.extract(message, tracer);

  if (parent != null) {
    spanBuilder.asChildOf(parent);
  }

  Span span = spanBuilder.startManual();

  SpanJmsDecorator.onRequest(destination, span);

  TracingMessageUtils.inject(span, message, tracer);
  return span;
}
 
開發者ID:Estafet-LTD,項目名稱:estafet-microservices-scrum-api-project-burndown,代碼行數:27,代碼來源:PropagatingTracingMessageUtils.java

示例4: withStartTimestamp

import io.opentracing.Tracer; //導入依賴的package包/類
/**
 * @param timestamp - ms since unix epoch
 * @return SpanBuilder instance
 */
@Override
public Tracer.SpanBuilder withStartTimestamp(long timestamp) {
    startSpanOptions.setTimestamp(new com.google.cloud.trace.core.Timestamp() {
        @Override
        public long getSeconds() {
            return timestamp / 1000;
        }

        @Override
        public int getNanos() {
            return java.lang.Math.toIntExact(timestamp % 1000) * 1000000;
        }
    });

    return this;
}
 
開發者ID:connctd,項目名稱:stackdriver-opentracing,代碼行數:21,代碼來源:StackDriverOTSpanBuilder.java

示例5: TracingActionSubscriber

import io.opentracing.Tracer; //導入依賴的package包/類
public TracingActionSubscriber(Action1<? super T> onNext, Action1<Throwable> onError,
    Action0 onCompleted, String operationName, Tracer tracer) {
  super(operationName, tracer);

  if (onNext == null) {
    throw new IllegalArgumentException("onNext can not be null");
  }
  if (onError == null) {
    throw new IllegalArgumentException("onError can not be null");
  }
  if (onCompleted == null) {
    throw new IllegalArgumentException("onComplete can not be null");
  }

  this.onNext = onNext;
  this.onError = onError;
  this.onCompleted = onCompleted;
}
 
開發者ID:opentracing-contrib,項目名稱:java-rxjava,代碼行數:19,代碼來源:TracingActionSubscriber.java

示例6: apiClient

import io.opentracing.Tracer; //導入依賴的package包/類
@Produces
@Singleton
private ApiClient apiClient(Tracer tracer) {

    String host = config.getValue(APIGATEWAY_URL, String.class);
    String port = config.getValue(APIGATEWAY_PORT, String.class);

    log.infof("API gateway expected at %s:%s", host, port);

    return HystrixFeign.builder()
            .client(new TracingClient(new ApacheHttpClient(HttpClientBuilder.create().build()), tracer))
            .logger(new feign.Logger.ErrorLogger()).logLevel(feign.Logger.Level.BASIC)
            .encoder(new JacksonEncoder())
            .decoder(new JacksonDecoder())
            .target(ApiClient.class, String.format("http://%s:%s", host, port),
                    (LRA lra) -> rx.Observable.empty());

}
 
開發者ID:xstefank,項目名稱:lra-service,代碼行數:19,代碼來源:BeanConfiguration.java

示例7: getTracer

import io.opentracing.Tracer; //導入依賴的package包/類
private Tracer getTracer() {
  try {
    return new com.uber.jaeger.Configuration(
        getName(),
        new com.uber.jaeger.Configuration.SamplerConfiguration("const", 1),
        new com.uber.jaeger.Configuration.ReporterConfiguration(
            true,
            "tracing-jaeger-agent",
            6831,
            1000,   // flush interval in milliseconds
            10000)  /*max buffered Spans*/)
        .getTracer();
  } catch (Exception e) {
    e.printStackTrace();
    return NoopTracerFactory.create();
  }
}
 
開發者ID:jeqo,項目名稱:talk-observing-distributed-systems,代碼行數:18,代碼來源:WorkerServiceApplication.java

示例8: initTracer

import io.opentracing.Tracer; //導入依賴的package包/類
protected void initTracer() {
    synchronized (SYNC) {
        if (tracer == null) {
            if (!GlobalTracer.isRegistered()) {
                // 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);
                    }
                }
            }
            // 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());
        }
    }
}
 
開發者ID:opentracing-contrib,項目名稱:java-agent,代碼行數:21,代碼來源:OpenTracingHelper.java

示例9: getTracer

import io.opentracing.Tracer; //導入依賴的package包/類
/**
 * This method provides tracer if user did not specify any tracer bean.
 * <p>
 * The order of getting the tracer is:
 * <ol>
 *     <li>Tracer registered in {@link GlobalTracer#register(Tracer)}</li>
 *     <li>Tracer resolved from {@link TracerResolver#resolve()}</li>
 *     <li>Default tracer, which is {@link io.opentracing.NoopTracer}</li>
 * </ol>
 * @return tracer
 */
@Bean
@ConditionalOnMissingBean(Tracer.class)
public Tracer getTracer() {
    Tracer tracer;
    if (GlobalTracer.isRegistered()) {
        log.warn("GlobalTracer is already registered. For consistency it is best practice to provide " +
                "a Tracer bean instead of manually registering it with the GlobalTracer");
        tracer = GlobalTracer.get();
    } else {
        tracer = TracerResolver.resolveTracer();
        if (tracer == null) {
            // WARNING: Don't return GlobalTracer.get() as this will result in a
            // stack overflow if the returned tracer is subsequently wrapped by a
            // BeanPostProcessor. The post processed tracer would then be registered
            // with the {@link GlobalTracer) (via the {@link TracerRegisterAutoConfiguration})
            // resulting in the wrapper both wrapping the GlobalTracer, as well as being
            // the tracer used by the GlobalTracer.
            tracer = NoopTracerFactory.create();
        }
    }
    log.warn("Tracer bean is not configured! Switching to " + tracer);
    return tracer;
}
 
開發者ID:opentracing-contrib,項目名稱:java-spring-web,代碼行數:35,代碼來源:TracerAutoConfiguration.java

示例10: intercept

import io.opentracing.Tracer; //導入依賴的package包/類
@Override
public void intercept(FixedInvocation inv) {

    EnableTracing enableOpentracing = inv.getMethod().getAnnotation(EnableTracing.class);
    Tracer tracer = JbootOpentracingManager.me().getTracer();
    Span span = null;

    if (enableOpentracing != null && tracer != null) {
        String spanName = StringUtils.isBlank(enableOpentracing.value())
                ? inv.getController().getClass().getName() + "." + inv.getMethodName()
                : enableOpentracing.value();

        Tracer.SpanBuilder spanBuilder = tracer.buildSpan(spanName);

        span = spanBuilder.startManual();

        span.setTag("requestId", StringUtils.uuid());
        JbootSpanContext.add(span);
    }


    try {
        inv.invoke();
    } finally {
        if (span != null) {
            span.finish();
            JbootSpanContext.release();
        }
    }

}
 
開發者ID:yangfuhai,項目名稱:jboot,代碼行數:32,代碼來源:OpentracingInterceptor.java

示例11: filter

import io.opentracing.Tracer; //導入依賴的package包/類
@Override
public Response filter(Caller<?> caller, Request request) {

    Tracer tracer = JbootOpentracingManager.me().getTracer();


    if (tracer == null) {
        return caller.call(request);
    }

    // 服務器
    if (caller instanceof Provider) {
        return processProviderTrace(tracer, caller, request);
    }

    // 客戶端
    else {
        return processRefererTrace(tracer, caller, request);
    }
}
 
開發者ID:yangfuhai,項目名稱:jboot,代碼行數:21,代碼來源:JbootMotanTracingFilter.java

示例12: startServerSpan

import io.opentracing.Tracer; //導入依賴的package包/類
public static Scope startServerSpan(Tracer tracer, javax.ws.rs.core.HttpHeaders httpHeaders,
        String operationName) {
    // format the headers for extraction
    MultivaluedMap<String, String> rawHeaders = httpHeaders.getRequestHeaders();
    final HashMap<String, String> headers = new HashMap<String, String>();
    for (String key : rawHeaders.keySet()) {
        headers.put(key, rawHeaders.get(key).get(0));
    }

    Tracer.SpanBuilder spanBuilder;
    try {
        SpanContext parentSpanCtx = tracer.extract(Format.Builtin.HTTP_HEADERS, new TextMapExtractAdapter(headers));
        if (parentSpanCtx == null) {
            spanBuilder = tracer.buildSpan(operationName);
        } else {
            spanBuilder = tracer.buildSpan(operationName).asChildOf(parentSpanCtx);
        }
    } catch (IllegalArgumentException e) {
        spanBuilder = tracer.buildSpan(operationName);
    }
    // TODO could add more tags like http.url
    return spanBuilder.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).startActive(true);
}
 
開發者ID:yurishkuro,項目名稱:opentracing-tutorial,代碼行數:24,代碼來源:Tracing.java

示例13: buildChildSpan

import io.opentracing.Tracer; //導入依賴的package包/類
static Scope buildChildSpan(AMQP.BasicProperties props, Tracer tracer) {
  SpanContext context = TracingUtils.extract(props, tracer);
  if (context != null) {
    Tracer.SpanBuilder spanBuilder = tracer.buildSpan("receive")
        .ignoreActiveSpan()
        .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER);

    spanBuilder.addReference(References.FOLLOWS_FROM, context);

    Scope scope = spanBuilder.startActive(true);
    SpanDecorator.onResponse(scope.span());
    return scope;
  }

  return null;
}
 
開發者ID:opentracing-contrib,項目名稱:java-rabbitmq-client,代碼行數:17,代碼來源:TracingUtils.java

示例14: run

import io.opentracing.Tracer; //導入依賴的package包/類
public void run(Configuration configuration, Environment environment) {
  final CollectorRegistry collectorRegistry = new CollectorRegistry();
  collectorRegistry.register(new DropwizardExports(environment.metrics()));

  final PrometheusMetricsReporter reporter =
      PrometheusMetricsReporter.newMetricsReporter()
          .withCollectorRegistry(collectorRegistry)
          .withConstLabel("service", getName())
          .build();

  final Tracer tracer = getTracer();
  final Tracer metricsTracer = io.opentracing.contrib.metrics.Metrics.decorate(tracer, reporter);
  GlobalTracer.register(metricsTracer);

  final String jdbcUrl = "jdbc:tracing:postgresql://tweets-db/postgres";
  final String jdbcUsername = "postgres";
  final String jdbcPassword = "example";
  final TweetsRepository tweetsRepository = new JooqPostgresTweetsRepository(jdbcUrl, jdbcUsername, jdbcPassword);
  final TweetsService tweetsService = new TweetsService(tweetsRepository);
  final TweetsResource tweetsResource = new TweetsResource(tweetsService);

  environment.jersey().register(tweetsResource);

  final DynamicFeature tracing = new ServerTracingDynamicFeature.Builder(metricsTracer).build();
  environment.jersey().register(tracing);

  environment.admin()
      .addServlet("metrics", new MetricsServlet(collectorRegistry))
      .addMapping("/metrics");
}
 
開發者ID:jeqo,項目名稱:talk-observing-distributed-systems,代碼行數:31,代碼來源:TweetsServiceApplication.java

示例15: tracer

import io.opentracing.Tracer; //導入依賴的package包/類
@Produces
@Singleton
public Tracer tracer() {
    String jaegerURL = System.getenv("JAEGER_SERVER_HOSTNAME");
    if (jaegerURL != null) {
        log.info("Using Jaeger tracer");
        return jaegerTracer(jaegerURL);
    }

    log.info("Using Noop tracer");
    return NoopTracerFactory.create();

}
 
開發者ID:xstefank,項目名稱:lra-service,代碼行數:14,代碼來源:BeanConfiguration.java


注:本文中的io.opentracing.Tracer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。