io.opencensus.trace.Tracing.getTraceConfig()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(3.3k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中io.opencensus.trace.Tracing.getTraceConfig()方法的一些代码示例,展示了Tracing.getTraceConfig()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tracing.getTraceConfig()方法的具体详情如下:
包路径:io.opencensus.trace.Tracing
类名称:Tracing
方法名:getTraceConfig

Tracing.getTraceConfig介绍

[英]Returns the global TraceConfig.
[中]返回全局跟踪图。

代码示例

代码示例来源:origin: census-instrumentation/opencensus-java

/** Creates a new {@code OcHttpServletFilter}. */
public OcHttpServletFilter() {
 TraceConfig traceConfig = Tracing.getTraceConfig();
 traceConfig.updateActiveTraceParams(traceConfig.getActiveTraceParams().toBuilder().build());
 handler = buildHttpServerHandler();
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
 public void defaultTraceConfig() {
  assertThat(Tracing.getTraceConfig()).isSameAs(TraceConfig.getNoopTraceConfig());
 }
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Before
public void setup() {
 handler = new TestHandler();
 SpanExporter exporter = Tracing.getExportComponent().getSpanExporter();
 exporter.registerHandler("testing", handler);
 TraceParams params =
   Tracing.getTraceConfig()
     .getActiveTraceParams()
     .toBuilder()
     .setSampler(Samplers.alwaysSample())
     .build();
 Tracing.getTraceConfig().updateActiveTraceParams(params);
}

代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-examples

public static void main(String[] args) throws IOException, InterruptedException {
 // Consult system properties to get project/instance
 String projectId = requiredProperty("bigtable.projectID");
 String instanceId = requiredProperty("bigtable.instanceID");
 // Force tracing for every request for demo purposes.  Use the default settings
 // in most cases.
 Tracing.getTraceConfig().updateActiveTraceParams(
   TraceParams.DEFAULT.toBuilder().setSampler(Samplers.probabilitySampler(1)).build());
 StackdriverTraceExporter.createAndRegister(
     StackdriverTraceConfiguration.builder()
       .setProjectId(projectId)
       .build());
 // Enable stats exporter to Stackdriver with a 5 second export time.
 // Production settings may vary.
 StackdriverStatsExporter.createAndRegister(
     StackdriverStatsConfiguration.builder()
        .setProjectId(projectId)
        .setExportInterval(Duration.create(5, 0))
        .build());
 RpcViews.registerAllViews();
 // HBase Bigtable specific setup for zpages
 HBaseTracingUtilities.setupTracingConfig();
 // Start a web server on port 8080 for tracing data
 ZPageHandlers.startHttpServerAndRegisterAll(8080);
 doHelloWorld(projectId, instanceId);
 System.out.println("Sleeping for 1 minute so that you can view http://localhost:8080/tracez");
 // Sleep for 1 minute.
 Thread.sleep(TimeUnit.MINUTES.toMillis(1));
}

代码示例来源:origin: dgraph-io/dgraph4j

@Test
public void testOpencensusJaeger() {
 // 1. configure the jaeger exporter
 JaegerTraceExporter.createAndRegister(JAEGER_COLLECTOR, "my-service");
 // 2. Configure 100% sample rate, otherwise, few traces will be sampled.
 TraceConfig traceConfig = Tracing.getTraceConfig();
 TraceParams activeTraceParams = traceConfig.getActiveTraceParams();
 traceConfig.updateActiveTraceParams(
   activeTraceParams.toBuilder().setSampler(Samplers.alwaysSample()).build());
 // 3. Get the global singleton Tracer object.
 Tracer tracer = Tracing.getTracer();
 // 4. Create a scoped span, a scoped span will automatically end when closed.
 // It implements AutoClosable, so it'll be closed when the try block ends.
 try (Scope scope = tracer.spanBuilder("query").startScopedSpan()) {
  runTransactions();
 }
 // 5. Gracefully shutdown the exporter, so that it'll flush queued traces to Jaeger.
 Tracing.getExportComponent().shutdown();
}

相关文章