io.opencensus.trace.Tracer Java Examples
The following examples show how to use
io.opencensus.trace.Tracer.
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: CensusTracingModule.java From grpc-java with Apache License 2.0 | 6 votes |
CensusTracingModule( Tracer censusTracer, final BinaryFormat censusPropagationBinaryFormat) { this.censusTracer = checkNotNull(censusTracer, "censusTracer"); checkNotNull(censusPropagationBinaryFormat, "censusPropagationBinaryFormat"); this.tracingHeader = Metadata.Key.of("grpc-trace-bin", new Metadata.BinaryMarshaller<SpanContext>() { @Override public byte[] toBytes(SpanContext context) { return censusPropagationBinaryFormat.toByteArray(context); } @Override public SpanContext parseBytes(byte[] serialized) { try { return censusPropagationBinaryFormat.fromByteArray(serialized); } catch (Exception e) { logger.log(Level.FINE, "Failed to parse tracing header", e); return SpanContext.INVALID; } } }); }
Example #2
Source File: HttpClientHandler.java From opencensus-java with Apache License 2.0 | 6 votes |
/** * Creates a {@link HttpClientHandler} with given parameters. * * @param tracer the Open Census tracing component. * @param extractor the {@code HttpExtractor} used to extract information from the * request/response. * @param textFormat the {@code TextFormat} used in HTTP propagation. * @param setter the setter used when injecting information to the {@code carrier}. * @since 0.19 */ public HttpClientHandler( Tracer tracer, HttpExtractor<Q, P> extractor, TextFormat textFormat, TextFormat.Setter<C> setter) { super(extractor); checkNotNull(setter, "setter"); checkNotNull(textFormat, "textFormat"); checkNotNull(tracer, "tracer"); this.setter = setter; this.textFormat = textFormat; this.tracer = tracer; this.statsRecorder = Stats.getStatsRecorder(); this.tagger = Tags.getTagger(); }
Example #3
Source File: HttpServerHandler.java From opencensus-java with Apache License 2.0 | 6 votes |
/** * Creates a {@link HttpServerHandler} with given parameters. * * @param tracer the Open Census tracing component. * @param extractor the {@code HttpExtractor} used to extract information from the * request/response. * @param textFormat the {@code TextFormat} used in HTTP propagation. * @param getter the getter used when extracting information from the {@code carrier}. * @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. * @since 0.19 */ public HttpServerHandler( Tracer tracer, HttpExtractor<Q, P> extractor, TextFormat textFormat, TextFormat.Getter<C> getter, Boolean publicEndpoint) { super(extractor); checkNotNull(tracer, "tracer"); checkNotNull(textFormat, "textFormat"); checkNotNull(getter, "getter"); checkNotNull(publicEndpoint, "publicEndpoint"); this.tracer = tracer; this.textFormat = textFormat; this.getter = getter; this.publicEndpoint = publicEndpoint; this.statsRecorder = Stats.getStatsRecorder(); this.tagger = Tags.getTagger(); }
Example #4
Source File: Handler.java From opencensus-java with Apache License 2.0 | 6 votes |
static Object proceed( ProceedingJoinPoint call, Tracer tracer, String spanName, String... annotations) throws Throwable { Scope scope = tracer.spanBuilder(spanName).startScopedSpan(); try { for (String annotation : annotations) { tracer.getCurrentSpan().addAnnotation(annotation); } return call.proceed(); } catch (Throwable t) { Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>(); String message = t.getMessage(); attributes.put( "message", AttributeValue.stringAttributeValue(message == null ? "null" : message)); attributes.put("type", AttributeValue.stringAttributeValue(t.getClass().toString())); Span span = tracer.getCurrentSpan(); span.addAnnotation("error", attributes); span.setStatus(Status.UNKNOWN); throw t; } finally { scope.close(); } }
Example #5
Source File: CensusTracingModule.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
CensusTracingModule( Tracer censusTracer, final BinaryFormat censusPropagationBinaryFormat) { this.censusTracer = checkNotNull(censusTracer, "censusTracer"); checkNotNull(censusPropagationBinaryFormat, "censusPropagationBinaryFormat"); this.tracingHeader = Metadata.Key.of("grpc-trace-bin", new Metadata.BinaryMarshaller<SpanContext>() { @Override public byte[] toBytes(SpanContext context) { return censusPropagationBinaryFormat.toByteArray(context); } @Override public SpanContext parseBytes(byte[] serialized) { try { return censusPropagationBinaryFormat.fromByteArray(serialized); } catch (Exception e) { logger.log(Level.FINE, "Failed to parse tracing header", e); return SpanContext.INVALID; } } }); }
Example #6
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 #7
Source File: TracingProxy.java From styx with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static <T> T instrument(Class<T> iface, T delegate, Tracer tracer) { return (T) Proxy.newProxyInstance( iface.getClassLoader(), new Class[]{iface}, new TracingProxy(delegate, tracer)); }
Example #8
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 #9
Source File: RecordTraceEventsBenchmark.java From opencensus-java with Apache License 2.0 | 5 votes |
@Setup public void setup() { Tracer tracer = BenchmarksUtil.getTracer(implementation); linkedSpan = tracer .spanBuilderWithExplicitParent(SPAN_NAME, null) .setSampler(sampled ? Samplers.alwaysSample() : Samplers.neverSample()) .startSpan(); span = tracer .spanBuilderWithExplicitParent(SPAN_NAME, null) .setSampler(sampled ? Samplers.alwaysSample() : Samplers.neverSample()) .startSpan(); }
Example #10
Source File: TraceComponentImpl.java From opencensus-java with Apache License 2.0 | 4 votes |
@Override public Tracer getTracer() { return traceComponentImplBase.getTracer(); }
Example #11
Source File: TraceComponentImplBase.java From opencensus-java with Apache License 2.0 | 4 votes |
public Tracer getTracer() { return tracer; }
Example #12
Source File: TraceComponentImplLite.java From opencensus-java with Apache License 2.0 | 4 votes |
@Override public Tracer getTracer() { return traceComponentImplBase.getTracer(); }
Example #13
Source File: TracingProxy.java From styx with Apache License 2.0 | 4 votes |
private TracingProxy(Object delegate, Tracer tracer) { this.delegate = Objects.requireNonNull(delegate); this.delegateName = delegate.getClass().getSimpleName(); this.tracer = tracer; }
Example #14
Source File: OpenCensusTracerAdapter.java From dremio-oss with Apache License 2.0 | 4 votes |
OpenCensusSpanBuilderAdapter(Tracer tracer, String opName) { this.tracer = tracer; this.opName = opName; }
Example #15
Source File: OpenCensusTracerAdapter.java From dremio-oss with Apache License 2.0 | 4 votes |
public OpenCensusTracerAdapter(Tracer ocTracer) { this.ocTracer = ocTracer; }
Example #16
Source File: CensusSpringAspect.java From opencensus-java with Apache License 2.0 | 2 votes |
/** * Creates a {@code CensusSpringAspect} with the given tracer. * * @param tracer the tracer responsible for building new spans * @since 0.16.0 */ public CensusSpringAspect(Tracer tracer) { this.tracer = tracer; }
Example #17
Source File: CensusSpringSqlAspect.java From opencensus-java with Apache License 2.0 | 2 votes |
/** * Creates a {@code CensusSpringSqlAspect} with the given tracer. * * @param tracer the tracer responsible for building new spans * @since 0.16.0 */ public CensusSpringSqlAspect(Tracer tracer) { this.tracer = tracer; }
Example #18
Source File: OpenCensusUtils.java From google-http-java-client with Apache License 2.0 | 2 votes |
/** * Returns the tracing component of OpenCensus. * * @return the tracing component of OpenCensus. */ public static Tracer getTracer() { return tracer; }