Java Code Examples for io.opencensus.trace.Tracing#getTracer()
The following examples show how to use
io.opencensus.trace.Tracing#getTracer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractManagedChannelImplBuilder.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
@VisibleForTesting final List<ClientInterceptor> getEffectiveInterceptors() { List<ClientInterceptor> effectiveInterceptors = new ArrayList<>(this.interceptors); temporarilyDisableRetry = false; if (statsEnabled) { temporarilyDisableRetry = true; CensusStatsModule censusStats = this.censusStatsOverride; if (censusStats == null) { censusStats = new CensusStatsModule(GrpcUtil.STOPWATCH_SUPPLIER, true); } // First interceptor runs last (see ClientInterceptors.intercept()), so that no // other interceptor can override the tracer factory we set in CallOptions. effectiveInterceptors.add( 0, censusStats.getClientInterceptor(recordStartedRpcs, recordFinishedRpcs)); } if (tracingEnabled) { temporarilyDisableRetry = true; CensusTracingModule censusTracing = new CensusTracingModule(Tracing.getTracer(), Tracing.getPropagationComponent().getBinaryFormat()); effectiveInterceptors.add(0, censusTracing.getClientInterceptor()); } return effectiveInterceptors; }
Example 2
Source File: AbstractServerImplBuilder.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
@VisibleForTesting final List<ServerStreamTracer.Factory> getTracerFactories() { ArrayList<ServerStreamTracer.Factory> tracerFactories = new ArrayList<ServerStreamTracer.Factory>(); if (statsEnabled) { CensusStatsModule censusStats = this.censusStatsOverride; if (censusStats == null) { censusStats = new CensusStatsModule(GrpcUtil.STOPWATCH_SUPPLIER, true); } tracerFactories.add( censusStats.getServerTracerFactory(recordStartedRpcs, recordFinishedRpcs)); } if (tracingEnabled) { CensusTracingModule censusTracing = new CensusTracingModule(Tracing.getTracer(), Tracing.getPropagationComponent().getBinaryFormat()); tracerFactories.add(censusTracing.getServerTracerFactory()); } tracerFactories.addAll(streamTracerFactories); return tracerFactories; }
Example 3
Source File: TracingAsyncClientHttpRequestInterceptor.java From opencensus-java with Apache License 2.0 | 6 votes |
TracingAsyncClientHttpRequestInterceptor( @Nullable TextFormat propagator, @Nullable HttpExtractor<HttpRequest, ClientHttpResponse> extractor) { tracer = Tracing.getTracer(); if (propagator == null) { propagator = Tracing.getPropagationComponent().getTraceContextFormat(); } if (extractor == null) { extractor = (HttpExtractor<HttpRequest, ClientHttpResponse>) new HttpClientExtractor(); } handler = new HttpClientHandler<HttpRequest, ClientHttpResponse, HttpRequest>( Tracing.getTracer(), extractor, propagator, setter); }
Example 4
Source File: StackDriverConfigurator.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public Tracer getTracer() { try { StackdriverTraceExporter.createAndRegister(StackdriverTraceConfiguration.builder().build()); } catch (IOException e) { logger.warn("Could not setup stackdriver tracer", e); } return new OpenCensusTracerAdapter(Tracing.getTracer()); }
Example 5
Source File: BenchmarksUtil.java From opencensus-java with Apache License 2.0 | 5 votes |
static Tracer getTracer(String implementation) { if (implementation.equals("impl")) { // We can return the global tracer here because if impl is linked the global tracer will be // the impl one. // TODO(bdrutu): Make everything not be a singleton (disruptor, etc.) and use a new // TraceComponentImpl similar to TraceComponentImplLite. return Tracing.getTracer(); } else if (implementation.equals("impl-lite")) { return traceComponentImplLite.getTracer(); } else { throw new RuntimeException("Invalid tracer implementation requested."); } }
Example 6
Source File: OcJettyHttpClient.java From opencensus-java with Apache License 2.0 | 5 votes |
private static HttpClientHandler<Request, Response, Request> buildHandler( @Nullable HttpExtractor<Request, Response> extractor, @Nullable TextFormat propagator) { if (extractor == null) { extractor = new OcJettyHttpClientExtractor(); } if (propagator == null) { propagator = Tracing.getPropagationComponent().getTraceContextFormat(); } return new HttpClientHandler<Request, Response, Request>( Tracing.getTracer(), extractor, propagator, setter); }
Example 7
Source File: OcHttpServletFilter.java From opencensus-java with Apache License 2.0 | 5 votes |
static HttpServerHandler<HttpServletRequest, HttpServletResponse, HttpServletRequest> buildHttpServerHandlerWithOptions( HttpExtractor<HttpServletRequest, HttpServletResponse> extractor, TextFormat propagator, Boolean publicEndpoint) { return new HttpServerHandler<HttpServletRequest, HttpServletResponse, HttpServletRequest>( Tracing.getTracer(), extractor, propagator, getter, publicEndpoint); }
Example 8
Source File: BeamFnMapTaskExecutor.java From beam with Apache License 2.0 | 5 votes |
@Override public void execute() throws Exception { Tracer tracer = Tracing.getTracer(); SpanBuilder builder = tracer.spanBuilder("MapTaskExecutor.Span").setRecordEvents(true); // Start the progress tracker before execution (which blocks until execution is finished). try (Scope unused = builder.startScopedSpan(); AutoCloseable unused2 = progressTrackerCloseable(progressTracker)) { tracer.getCurrentSpan().addAnnotation("About to execute"); super.execute(); tracer.getCurrentSpan().addAnnotation("Done with execute"); } }
Example 9
Source File: InternalCensusTracingAccessor.java From grpc-java with Apache License 2.0 | 5 votes |
/** * Returns a {@link ClientInterceptor} with default tracing implementation. */ public static ClientInterceptor getClientInterceptor() { CensusTracingModule censusTracing = new CensusTracingModule( Tracing.getTracer(), Tracing.getPropagationComponent().getBinaryFormat()); return censusTracing.getClientInterceptor(); }
Example 10
Source File: InternalCensusTracingAccessor.java From grpc-java with Apache License 2.0 | 5 votes |
/** * Returns a {@link ServerStreamTracer.Factory} with default stats implementation. */ public static ServerStreamTracer.Factory getServerStreamTracerFactory() { CensusTracingModule censusTracing = new CensusTracingModule( Tracing.getTracer(), Tracing.getPropagationComponent().getBinaryFormat()); return censusTracing.getServerTracerFactory(); }
Example 11
Source File: TestOpenCensusAdapter.java From dremio-oss with Apache License 2.0 | 4 votes |
@BeforeClass public static void setup() { LoggingTraceExporter.register(); outerTracer = new OpenCensusTracerAdapter(Tracing.getTracer()); }
Example 12
Source File: TraceWebAsyncClientAutoConfigurationTest.java From opencensus-java with Apache License 2.0 | 4 votes |
@Test(timeout = 10000) @Order(1) public void should_close_span_upon_success_callback() throws ExecutionException, InterruptedException { tracer = Tracing.getTracer(); Span initialSpan = tracer.spanBuilder("initial").startSpan(); try (Scope ws = tracer.withSpan(initialSpan)) { ListenableFuture<ResponseEntity<String>> future = asyncRestTemplate.getForEntity("http://localhost:" + port() + "/async", String.class); String result = future.get().getBody(); assertThat(result).isEqualTo("async"); } finally { initialSpan.end(); } // 3 spans are initial, client, server. List<SpanData> spans = handler.waitForExport(3); SpanData clientSpan = null; for (SpanData span : spans) { if (span.getKind() == CLIENT) { clientSpan = span; assertThat(clientSpan.getName()).isEqualTo("/async"); assertThat(clientSpan.getStatus().isOk()).isTrue(); assertThat( clientSpan .getAttributes() .getAttributeMap() .get(HttpTraceAttributeConstants.HTTP_METHOD)) .isEqualTo(AttributeValue.stringAttributeValue("GET")); assertThat( clientSpan .getAttributes() .getAttributeMap() .get(HttpTraceAttributeConstants.HTTP_HOST)) .isEqualTo(AttributeValue.stringAttributeValue("localhost")); assertThat( clientSpan .getAttributes() .getAttributeMap() .get(HttpTraceAttributeConstants.HTTP_PATH)) .isEqualTo(AttributeValue.stringAttributeValue("/async")); assertThat(clientSpan.getKind()).isEqualTo(CLIENT); break; } } assertThat(clientSpan).isNotNull(); }
Example 13
Source File: JaxrsContainerFilter.java From opencensus-java with Apache License 2.0 | 3 votes |
/** * Construct instance with custom configuration. * * @param extractor the {@code HttpExtractor} used to extract information from the * request/response. * @param propagationFormat the {@code TextFormat} used in HTTP propagation. * @param publicEndpoint set to true for publicly accessible HTTP(S) server. If true then incoming * tracecontext will be added as a link instead of as a parent. */ public JaxrsContainerFilter( HttpExtractor<ExtendedContainerRequest, ContainerResponseContext> extractor, TextFormat propagationFormat, Boolean publicEndpoint) { this.handler = new HttpServerHandler<>( Tracing.getTracer(), extractor, propagationFormat, GETTER, publicEndpoint); }
Example 14
Source File: JaxrsClientFilter.java From opencensus-java with Apache License 2.0 | 2 votes |
/** * Construct new client filter with custom configuration. * * @param extractor the {@code HttpExtractor} used to extract information from the * request/response. * @param propagationFormat the {@code TextFormat} used in HTTP propagation. */ public JaxrsClientFilter( HttpExtractor<ClientRequestContext, ClientResponseContext> extractor, TextFormat propagationFormat) { handler = new HttpClientHandler<>(Tracing.getTracer(), extractor, propagationFormat, SETTER); }