static void exportSpans(String... spans) { SampledSpanStore store = Tracing.getExportComponent().getSampledSpanStore(); if (store != null) { store.registerSpanNamesForCollection(Arrays.asList(spans)); } } }
TransactionManagerImpl(SessionImpl session) { this.session = session; this.span = Tracing.getTracer().getCurrentSpan(); }
/** Create a new {@code OcJettyHttpClient}. */ public OcJettyHttpClient() { super(); OcJettyHttpClientExtractor extractor = new OcJettyHttpClientExtractor(); handler = new HttpClientHandler<Request, Response, Request>( Tracing.getTracer(), extractor, Tracing.getPropagationComponent().getTraceContextFormat(), setter); }
@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(); }
Tracing.getExportComponent().getSampledSpanStore().registerSpanNamesForCollection( Arrays.asList(SAMPLE_SPAN)); options.getProjectId(), instanceId, databaseId)); try (Scope ss = Tracing.getTracer() .spanBuilderWithExplicitParent(SAMPLE_SPAN, null) .setSampler(Samplers.alwaysSample())
@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); }
/** * Default constructor construct new instance with {@link JaxrsContainerExtractor}, {@link * io.opencensus.trace.propagation.PropagationComponent#getTraceContextFormat()} and as public * endpoint. * * @see #JaxrsContainerFilter(HttpExtractor, TextFormat, Boolean) */ public JaxrsContainerFilter() { this( new JaxrsContainerExtractor(), Tracing.getPropagationComponent().getTraceContextFormat(), /* publicEndpoint= */ true); }
/** Creates a new {@code OcHttpServletFilter}. */ public OcHttpServletFilter() { TraceConfig traceConfig = Tracing.getTraceConfig(); traceConfig.updateActiveTraceParams(traceConfig.getActiveTraceParams().toBuilder().build()); handler = buildHttpServerHandler(); }
@Test public void implementationOfClock() { assertThat(Tracing.getClock()).isInstanceOf(MillisClock.class); }
static HttpServerHandler<HttpServletRequest, HttpServletResponse, HttpServletRequest> buildHttpServerHandler() { return new HttpServerHandler<HttpServletRequest, HttpServletResponse, HttpServletRequest>( Tracing.getTracer(), // TODO[rghetia]: // 1. provide options to configure custom extractor, propagator and endpoint. new OcHttpServletExtractor(), Tracing.getPropagationComponent().getTraceContextFormat(), getter, true); }
@Test public void exportToJaeger() throws IOException, InterruptedException { Tracer tracer = Tracing.getTracer(); final long startTimeInMicros = MILLISECONDS.toMicros(currentTimeMillis()); final long startNanoTime = System.nanoTime(); Tracing.getExportComponent().shutdown(); JaegerTraceExporter.unregister();
/** Constructs new client filter with default configuration. */ public JaxrsClientFilter() { this(new JaxrsClientExtractor(), Tracing.getPropagationComponent().getTraceContextFormat()); }
@Test public void defaultTraceConfig() { assertThat(Tracing.getTraceConfig()).isSameAs(TraceConfig.getNoopTraceConfig()); } }
@Test public void implementationOfClock() { assertThat(Tracing.getClock()).isInstanceOf(MillisClock.class); }
static void registerAllSpanNamesForCollection() { Tracing.getExportComponent() .getSampledSpanStore() .registerSpanNamesForCollection(ALL_SPAN_NAMES); }
private AbstractReadContext(SessionImpl session, SpannerRpc rpc, int defaultPrefetchChunks) { this(session, rpc, defaultPrefetchChunks, Tracing.getTracer().getCurrentSpan()); }
@VisibleForTesting final List<? extends ServerStreamTracer.Factory> getTracerFactories() { ArrayList<ServerStreamTracer.Factory> tracerFactories = new ArrayList<>(); if (statsEnabled) { CensusStatsModule censusStats = censusStatsOverride; if (censusStats == null) { censusStats = new CensusStatsModule( GrpcUtil.STOPWATCH_SUPPLIER, true, recordStartedRpcs, recordFinishedRpcs, recordRealTimeMetrics); } tracerFactories.add(censusStats.getServerTracerFactory()); } if (tracingEnabled) { CensusTracingModule censusTracing = new CensusTracingModule(Tracing.getTracer(), Tracing.getPropagationComponent().getBinaryFormat()); tracerFactories.add(censusTracing.getServerTracerFactory()); } tracerFactories.addAll(streamTracerFactories); tracerFactories.trimToSize(); return Collections.unmodifiableList(tracerFactories); }
@Test public void implementationOfBinaryPropagationHandler() { assertThat(Tracing.getPropagationComponent()).isInstanceOf(PropagationComponent.class); }
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)); }
Optional.ofNullable(sd.getEndTimestamp()).orElseGet(() -> Tracing.getClock().now()); final long endTime = timestampToNanos(endTimestamp); final long duration = endTime - startTime;