本文整理汇总了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);
}
示例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);
}
}
示例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);
}
示例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());
}
示例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();
}
示例6: getTraceService
import com.google.cloud.trace.service.TraceGrpcApiService; //导入依赖的package包/类
@VisibleForTesting
TraceGrpcApiService.Builder getTraceService() {
return TraceGrpcApiService.builder();
}