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


Java Tracer類代碼示例

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


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

示例1: main

import com.google.cloud.trace.Tracer; //導入依賴的package包/類
public static void main(String[] args) throws IOException, SQLException {
  checkNotNull(args);
  checkArgument(
      args.length == 1, "Expected exactly one command line argument, the cloud project ID");

  String projectId = args[0];
  Tracer tracer = TraceGrpcApiService.builder().setProjectId(projectId).build().getTracer();

  // Make the Tracer available to Stackdriver Trace for JDBC.
  // TODO: Replace this with the upcoming mechanism in the Cloud Trace for Java SDK.
  ThreadLocalTracerStore.setCurrent(tracer);

  TraceContext traceContext = tracer.startSpan("example request");

  System.out.println("Hello Stackdriver Trace for JDBC!");
  System.out.println("Your lucky number is " + doStuff());
  System.out.println("Help me find out why this request is so slow!");
  System.out.println(
      "Hint: https://console.cloud.google.com/traces/overview?project=" + projectId);

  tracer.endSpan(traceContext);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-trace-java-instrumentation,代碼行數:23,代碼來源:Main.java

示例2: SpanImpl

import com.google.cloud.trace.Tracer; //導入依賴的package包/類
SpanImpl(Tracer tracer, String name) {
  checkNotNull(tracer);
  checkNotNull(name);

  this.tracer = tracer;
  this.traceContext = tracer.startSpan(name);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-trace-java-instrumentation,代碼行數:8,代碼來源:CloudTraceSdkTraceService.java

示例3: getCurrent_threadlocal

import com.google.cloud.trace.Tracer; //導入依賴的package包/類
@Test
public void getCurrent_threadlocal() {
  ThreadLocalTracerStore.setCurrent(mockTracer);
  Tracer tracer = new Tracers().getCurrent();
  assertThat(tracer).isSameAs(mockTracer);
  ThreadLocalTracerStore.remove();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-trace-java-instrumentation,代碼行數:8,代碼來源:TracersTest.java

示例4: configure

import com.google.cloud.trace.Tracer; //導入依賴的package包/類
@Override
protected void configure() {
  bindInterceptor(Matchers.any(), Matchers.annotatedWith(Span.class),
      new TracerSpanInterceptor(getProvider(Tracer.class),
          getProvider(Key.get(new TypeLiteral<Map<String, Labeler>>(){})), labelHost));
  MapBinder<String, Labeler> mapBinder =
      MapBinder.newMapBinder(binder(), String.class, Labeler.class);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-trace-java,代碼行數:9,代碼來源:TracerSpanModule.java

示例5: TracerSpanInterceptor

import com.google.cloud.trace.Tracer; //導入依賴的package包/類
public TracerSpanInterceptor(
    Provider<Tracer> tracerProvider,
    Provider<Map<String, Labeler>> labelerMapProvider,
    String labelHost) {
  this.tracerProvider = tracerProvider;
  this.labelerMapProvider = labelerMapProvider;
  this.labelHost = labelHost;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-trace-java,代碼行數:9,代碼來源:TracerSpanInterceptor.java

示例6: getTracer

import com.google.cloud.trace.Tracer; //導入依賴的package包/類
@Test
public void getTracer() {
  Tracer tracer = traceService.getTracer();

  assertThat(tracer).isNotNull();
  assertThat(tracer).isInstanceOf(AppEngineTracer.class);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-trace-java,代碼行數:8,代碼來源:AppEngineTraceServiceTest.java

示例7: main

import com.google.cloud.trace.Tracer; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
  String projectId = System.getProperty("projectId");
  String clientSecretsFile = System.getProperty("clientSecretsFile");

  // Create the trace sink.
  TraceProducer traceProducer = new TraceProducer();
  TraceConsumer traceConsumer = GrpcTraceConsumer.createWithCredentials(
      GoogleCredentials.fromStream(new FileInputStream(clientSecretsFile))
          .createScoped(Arrays.asList("https://www.googleapis.com/auth/trace.append")));
  FlushableTraceConsumer flushableSink = new SimpleBufferingTraceConsumer(traceConsumer);
  TraceSink traceSink = new TraceSinkV1(projectId, traceProducer, flushableSink);

  // Create the tracer.
  SpanContextFactory spanContextFactory = new SpanContextFactory(
      new ConstantTraceOptionsFactory(true, false));
  TimestampFactory timestampFactory = new JavaTimestampFactory();
  SpanContextHandler contextHandler = new GrpcSpanContextHandler(spanContextFactory.initialContext());
  Tracer tracer = new SpanContextHandlerTracer(traceSink, contextHandler, spanContextFactory, timestampFactory);

  // Create a span using the given timestamps.
  TraceContext context1 = tracer.startSpan("my span 1");

  TraceContext context2 = tracer.startSpan("my span 2");

  StackTrace.Builder stackTraceBuilder = ThrowableStackTraceHelper.createBuilder(new Exception());
  tracer.setStackTrace(context2, stackTraceBuilder.build());
  tracer.endSpan(context2);

  tracer.endSpan(context1);

  flushableSink.flush();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-trace-java,代碼行數:33,代碼來源:SimpleBufferingGrpc.java

示例8: main

import com.google.cloud.trace.Tracer; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
  String projectId = System.getProperty("projectId");

  // Create the trace sink.
  TraceProducer traceProducer = new TraceProducer();
  TraceConsumer traceConsumer = GrpcTraceConsumer.create();
  TraceSink traceSink = new TraceSinkV1(projectId, traceProducer, traceConsumer);

  // Create the tracer.
  SpanContextFactory spanContextFactory = new SpanContextFactory(
      new ConstantTraceOptionsFactory(true, false));
  TimestampFactory timestampFactory = new JavaTimestampFactory();
  SpanContextHandler spanContextHandler = new GrpcSpanContextHandler(
      spanContextFactory.initialContext());
  Tracer tracer = new SpanContextHandlerTracer(traceSink, spanContextHandler, spanContextFactory, timestampFactory);

  // Create some trace data.
  TraceContext context1 = tracer.startSpan("my span 1");

  TraceContext context2 = tracer.startSpan("my span 2");

  StackTrace.Builder stackTraceBuilder = ThrowableStackTraceHelper.createBuilder(new Exception());
  tracer.setStackTrace(context2, stackTraceBuilder.build());
  tracer.endSpan(context2);

  tracer.endSpan(context1);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-trace-java,代碼行數:28,代碼來源:ManagedGrpc.java

示例9: main

import com.google.cloud.trace.Tracer; //導入依賴的package包/類
public static void main(String[] args) {
  Tracer tracer = Trace.getTracer();

  // Create a span using the given timestamps.
  TraceContext context = tracer.startSpan("my span 1");
  StackTrace.Builder stackTraceBuilder = ThrowableStackTraceHelper.createBuilder(new Exception());
  tracer.setStackTrace(context, stackTraceBuilder.build());
  tracer.endSpan(context);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-trace-java,代碼行數:10,代碼來源:BasicLogging.java

示例10: main

import com.google.cloud.trace.Tracer; //導入依賴的package包/類
public static void main(String[] args) {
  Injector injector = Guice.createInjector(
      new SpanContextHandlerTracerModule(),
      new JavaTimestampFactoryModule(),
      new GrpcSpanContextHandlerModule(),
      new TraceSinkV1Module(),
      new ConstantTraceOptionsFactoryModule(),
      new ProjectIdPropertiesModule(),
      new ScheduledBufferingTraceSinkModule(),
      new TraceEnabledModule(),
      new StackTraceDisabledModule(),
      new GrpcTraceSinkModule(),
      new RoughTraceSizerModule(),
      new SinkBufferSizePropertiesModule(),
      new SinkScheduledDelayPropertiesModule(),
      new SingleThreadScheduledExecutorModule(),
      new ClientSecretsGoogleCredentialsModule(),
      new ClientSecretsFilePropertiesModule(),
      new TraceAppendScopesModule());

  Tracer tracer = injector.getInstance(Tracer.class);

  TraceContext context1 = tracer.startSpan("my span 1",
      new StartSpanOptions().setEnableTrace(true));
  TraceContext context2 = tracer.startSpan("my span 2");

  StackTrace.Builder stackTraceBuilder = ThrowableStackTraceHelper.createBuilder(new Exception());
  tracer.setStackTrace(context2, stackTraceBuilder.build());
  tracer.endSpan(context1);

  tracer.endSpan(context1);

  FlushableTraceConsumer flushableSink = injector.getInstance(FlushableTraceConsumer.class);

  flushableSink.flush();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-trace-java,代碼行數:37,代碼來源:ScheduledBufferingGrpc.java

示例11: main

import com.google.cloud.trace.Tracer; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
  String projectId = System.getProperty("projectId");

  // Initialize the Tracer.
  TraceService traceService =
      TraceGrpcApiService.builder()
          // Set the projectId.
          .setProjectId(projectId)
          // Uncomment this if you want to provide your own credentials for the Stackdriver Trace
          // API.
          // On GCE, this is optional because the Application Default Credentials are used by
          // default.
          // .setCredentials(
          //    GoogleCredentials.fromStream(new FileInputStream("/path/to/my/credentials.json")))
          // Use a short delay of 1 second for this example. In production, you may want to use a
          // higher value so that more trace events are batched together in a single request to
          // the
          // Stackdriver Trace API. By default, the delay is 15 seconds.
          .setScheduledDelay(1)
          .build();
  Trace.init(traceService);

  Tracer tracer = Trace.getTracer();
  // Force tracing for this span to see the trace in Stackdriver console.
  StartSpanOptions startSpanOptions = new StartSpanOptions().setEnableTrace(true);
  TraceContext context = tracer.startSpan("test-span", startSpanOptions);
  tracer.annotateSpan(
      context, Labels.builder().add("MyTestLabelKey", "MyTestLabelValue").build());
  tracer.endSpan(context);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-trace-java,代碼行數:31,代碼來源:StackdriverTraceApi.java

示例12: endSpan

import com.google.cloud.trace.Tracer; //導入依賴的package包/類
@VisibleForTesting
private void endSpan(TraceContext context) {
  if (context != null) {
    Tracer tracer = Trace.getTracer();
    tracer.endSpan(context);
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:tomcat-runtime,代碼行數:8,代碼來源:DatastoreStore.java

示例13: invoke

import com.google.cloud.trace.Tracer; //導入依賴的package包/類
/**
 * {@inheritDoc}
 *
 * <p>Create a new trace containing information about the requests.
 *    The traces are buffered by the TraceService and regularly sent to Stackdriver</p>
 */
@Override
public void invoke(Request request, Response response) throws IOException, ServletException {
  Tracer tracer = traceService.getTracer();
  SpanContextHandle contextHandle = null;

  String traceHeader = request.getHeader(X_CLOUD_TRACE_HEADER);
  if (traceHeader != null) {
    SpanContext spanContext = traceService
        .getSpanContextFactory()
        .fromHeader(traceHeader);
    contextHandle = traceService.getSpanContextHandler().attach(spanContext);
    log.debug("Tracing request with header: " + request.getHeader(X_CLOUD_TRACE_HEADER));
  }

  TraceContext context = tracer.startSpan(request.getRequestURI());

  getNext().invoke(request, response);

  tracer.annotateSpan(context, createLabels(request, response));

  tracer.endSpan(context);
  if (contextHandle != null) {
    contextHandle.detach();
  }

}
 
開發者ID:GoogleCloudPlatform,項目名稱:tomcat-runtime,代碼行數:33,代碼來源:TraceValve.java

示例14: TraceHttpResponseInterceptor

import com.google.cloud.trace.Tracer; //導入依賴的package包/類
public TraceHttpResponseInterceptor(Tracer tracer) {
  this.tracer = tracer;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-trace-java-instrumentation,代碼行數:4,代碼來源:TraceHttpResponseInterceptor.java

示例15: TraceHttpRequestInterceptor

import com.google.cloud.trace.Tracer; //導入依賴的package包/類
public TraceHttpRequestInterceptor(Tracer tracer) {
  this.tracer = tracer;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-trace-java-instrumentation,代碼行數:4,代碼來源:TraceHttpRequestInterceptor.java


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