当前位置: 首页>>代码示例>>Java>>正文


Java TraceGrpcApiService类代码示例

本文整理汇总了Java中com.google.cloud.trace.service.TraceGrpcApiService的典型用法代码示例。如果您正苦于以下问题:Java TraceGrpcApiService类的具体用法?Java TraceGrpcApiService怎么用?Java TraceGrpcApiService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TraceGrpcApiService类属于com.google.cloud.trace.service包,在下文中一共展示了TraceGrpcApiService类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.google.cloud.trace.service.TraceGrpcApiService; //导入依赖的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: initTraceService

import com.google.cloud.trace.service.TraceGrpcApiService; //导入依赖的package包/类
@VisibleForTesting
void initTraceService() throws LifecycleException {

  if (traceScheduledDelay != null && traceScheduledDelay <= 0) {
    throw new LifecycleException("The delay for trace must be greater than 0");
  }

  try {
    String projectId = ServiceOptions.getDefaultProjectId();
    TraceGrpcApiService.Builder traceServiceBuilder = getTraceService()
        .setProjectId(projectId);

    if (traceScheduledDelay != null) {
      traceServiceBuilder.setScheduledDelay(traceScheduledDelay);
    }

    traceService = traceServiceBuilder.build();
    Trace.init(traceService);
    log.info("Trace service initialized for project: " + projectId);
  } catch (IOException e) {
    throw new LifecycleException(e);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:tomcat-runtime,代码行数:24,代码来源:TraceValve.java

示例3: main

import com.google.cloud.trace.service.TraceGrpcApiService; //导入依赖的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

示例4: testServiceInitialization

import com.google.cloud.trace.service.TraceGrpcApiService; //导入依赖的package包/类
@Test
public void testServiceInitialization() throws Exception {
  valve.setTraceScheduledDelay(60);
  TraceValve spiedValve = spy(valve);
  Builder builder = spy(TraceGrpcApiService.builder());
  when(builder.build()).thenReturn(traceService);
  when(spiedValve.getTraceService()).thenReturn(builder);
  spiedValve.initTraceService();
  assertEquals(Trace.getTracer(), traceService.getTracer());
}
 
开发者ID:GoogleCloudPlatform,项目名称:tomcat-runtime,代码行数:11,代码来源:TraceValveTest.java

示例5: testServiceInitializationError

import com.google.cloud.trace.service.TraceGrpcApiService; //导入依赖的package包/类
@Test(expected = LifecycleException.class)
public void testServiceInitializationError() throws Exception {
  valve.setTraceScheduledDelay(60);
  TraceValve spiedValve = spy(valve);
  Builder builder = spy(TraceGrpcApiService.builder());
  when(builder.build()).thenThrow(new IOException());
  when(spiedValve.getTraceService()).thenReturn(builder);
  spiedValve.initTraceService();
}
 
开发者ID:GoogleCloudPlatform,项目名称:tomcat-runtime,代码行数:10,代码来源:TraceValveTest.java

示例6: getTraceService

import com.google.cloud.trace.service.TraceGrpcApiService; //导入依赖的package包/类
@VisibleForTesting
TraceGrpcApiService.Builder getTraceService() {
  return TraceGrpcApiService.builder();
}
 
开发者ID:GoogleCloudPlatform,项目名称:tomcat-runtime,代码行数:5,代码来源:TraceValve.java


注:本文中的com.google.cloud.trace.service.TraceGrpcApiService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。