Tabnine Logo
Tracer
Code IndexAdd Tabnine to your IDE (free)

How to use
Tracer
in
io.opencensus.trace

Best Java code snippets using io.opencensus.trace.Tracer (Showing top 20 results out of 369)

Refine searchRefine arrow

  • SpanBuilder
origin: googleapis/google-cloud-java

/** Transaction functions that returns its result in the provided SettableFuture. */
private <T> void runTransaction(
  final Transaction.Function<T> transactionCallback,
  final SettableApiFuture<T> resultFuture,
  final TransactionOptions options) {
 // span is intentionally not ended here. It will be ended by runTransactionAttempt on success
 // or error.
 Span span = tracer.spanBuilder("CloudFirestore.Transaction").startSpan();
 try (Scope s = tracer.withSpan(span)) {
  runTransactionAttempt(transactionCallback, resultFuture, options, span);
 }
}
origin: googleapis/google-cloud-java

TransactionManagerImpl(SessionImpl session) {
 this.session = session;
 this.span = Tracing.getTracer().getCurrentSpan();
}
origin: googleapis/google-cloud-java

protected ResumableStreamIterator(int maxBufferSize, String streamName, Span parent) {
 checkArgument(maxBufferSize >= 0);
 this.maxBufferSize = maxBufferSize;
 this.span = tracer.spanBuilderWithExplicitParent(streamName, parent).startSpan();
}
origin: census-instrumentation/opencensus-java

@Test
public void startSpanWithParentFromContext() {
 Scope ws = tracer.withSpan(span);
 try {
  assertThat(tracer.getCurrentSpan()).isSameAs(span);
  when(tracer.spanBuilderWithExplicitParent(same(SPAN_NAME), same(span)))
    .thenReturn(spanBuilder);
  assertThat(tracer.spanBuilder(SPAN_NAME)).isSameAs(spanBuilder);
 } finally {
  ws.close();
 }
}
origin: googleapis/google-cloud-java

/** Helper method to start a span. */
private Span startSpan(String spanName) {
 return tracer
   .spanBuilder(spanName)
   .setRecordEvents(censusHttpModule.isRecordEvents())
   .startSpan();
}
origin: googleapis/google-cloud-java

@Override
public TransactionContext begin() {
 Preconditions.checkState(txn == null, "begin can only be called once");
 try (Scope s = tracer.withSpan(span)) {
  txn = session.newTransaction();
  session.setActive(this);
  txn.ensureTxn();
  txnState = TransactionState.STARTED;
  return txn;
 }
}
origin: io.grpc/grpc-core

ClientCallTracer(@Nullable Span parentSpan, MethodDescriptor<?, ?> method) {
 checkNotNull(method, "method");
 this.isSampledToLocalTracing = method.isSampledToLocalTracing();
 this.span =
   censusTracer
     .spanBuilderWithExplicitParent(
       generateTraceSpanName(false, method.getFullMethodName()),
       parentSpan)
     .setRecordEvents(true)
     .startSpan();
}
origin: census-instrumentation/opencensus-java

 @Test
 public void doNotCrash_NoopImplementation() throws Exception {
  SpanBuilder spanBuilder = tracer.spanBuilder("MySpanName");
  spanBuilder.setParentLinks(Collections.<Span>emptyList());
  spanBuilder.setRecordEvents(true);
  spanBuilder.setSampler(Samplers.alwaysSample());
  spanBuilder.setSpanKind(Kind.SERVER);
  assertThat(spanBuilder.startSpan()).isSameAs(BlankSpan.INSTANCE);
 }
}
origin: census-instrumentation/opencensus-java

@Override
public final void handle(HttpExchange httpExchange) throws IOException {
 Span span =
   tracer
     .spanBuilderWithExplicitParent(httpServerSpanName, null)
     .setRecordEvents(true)
     .startSpan();
 try (Scope ss = tracer.withSpan(span)) {
  span.putAttribute(
    "/http/method ", AttributeValue.stringAttributeValue(httpExchange.getRequestMethod()));
  httpExchange.sendResponseHeaders(200, 0);
  zpageHandler.emitHtml(
    uriQueryToMap(httpExchange.getRequestURI()), httpExchange.getResponseBody());
 } finally {
  httpExchange.close();
  span.end(END_SPAN_OPTIONS);
 }
}
origin: census-instrumentation/opencensus-java

@MustBeClosed
@Override
public Closeable startScopedSpan(String spanName) {
 checkNotNull(spanName, "spanName");
 return Tracing.getTracer()
   .spanBuilder(spanName)
   .setSampler(Samplers.alwaysSample())
   .setRecordEvents(true)
   .startScopedSpan();
}
origin: io.grpc/grpc-core

ServerTracer(String fullMethodName, @Nullable SpanContext remoteSpan) {
 checkNotNull(fullMethodName, "fullMethodName");
 this.span =
   censusTracer
     .spanBuilderWithRemoteParent(
       generateTraceSpanName(true, fullMethodName),
       remoteSpan)
     .setRecordEvents(true)
     .startSpan();
}
origin: googleapis/google-cloud-java

Span opSpan = tracer.spanBuilderWithExplicitParent(COMMIT, span).startSpan();
try (Scope s = tracer.withSpan(opSpan)) {
 CommitResponse commitResponse =
   runWithRetries(
origin: census-instrumentation/opencensus-java

@MustBeClosed
private static Scope newExportScope() {
 // Start a new span with explicit sampler (with low probability) to avoid the case when user
 // sets the default sampler to always sample and we get the Thrift span of the Jaeger
 // export call always sampled and go to an infinite loop.
 return tracer.spanBuilder(EXPORT_SPAN_NAME).setSampler(lowProbabilitySampler).startScopedSpan();
}
origin: census-instrumentation/opencensus-java

@Test
public void getCurrentSpan_WithSpan() {
 assertThat(noopTracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
 Scope ws = noopTracer.withSpan(span);
 try {
  assertThat(noopTracer.getCurrentSpan()).isSameAs(span);
 } finally {
  ws.close();
 }
 assertThat(noopTracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
}
origin: census-instrumentation/opencensus-java

@Test
public void defaultSpanBuilderWithRemoteParent_NullParent() {
 assertThat(noopTracer.spanBuilderWithRemoteParent(SPAN_NAME, null).startSpan())
   .isSameAs(BlankSpan.INSTANCE);
}
origin: census-instrumentation/opencensus-java

@Before
public void setUp() throws SpanContextParseException {
 MockitoAnnotations.initMocks(this);
 handler =
   new HttpServerHandler<Object, Object, Object>(
     tracer, extractor, textFormat, textFormatGetter, false);
 handlerForPublicEndpoint =
   new HttpServerHandler<Object, Object, Object>(
     tracer, extractor, textFormat, textFormatGetter, true);
 when(tracer.spanBuilderWithRemoteParent(any(String.class), same(spanContextRemote)))
   .thenReturn(spanBuilderWithRemoteParent);
 when(tracer.spanBuilderWithExplicitParent(any(String.class), any(Span.class)))
   .thenReturn(spanBuilderWithLocalParent);
 when(spanBuilderWithRemoteParent.startSpan()).thenReturn(spanWithRemoteParent);
 when(spanBuilderWithLocalParent.startSpan()).thenReturn(spanWithLocalParent);
 when(textFormat.extract(same(carrier), same(textFormatGetter))).thenReturn(spanContextRemote);
}
origin: GoogleCloudPlatform/java-docs-samples

 .spanBuilderWithExplicitParent(SAMPLE_SPAN, null)
 .setSampler(Samplers.alwaysSample())
 .startScopedSpan()) {
ResultSet resultSet = dbClient.singleUse().executeQuery(Statement.of("SELECT 1"));
origin: census-instrumentation/opencensus-java

@Test
public void startScopedSpan() {
 assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
 Scope scope = spanBuilder.startScopedSpan();
 try {
  assertThat(tracer.getCurrentSpan()).isSameAs(span);
 } finally {
  scope.close();
 }
 verify(span).end(EndSpanOptions.DEFAULT);
 assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
}
origin: census-instrumentation/opencensus-java

@Test
public void handleStartShouldCreateChildSpanInCurrentContext() {
 Scope scope = tracer.withSpan(parentSpan);
 try {
  HttpRequestContext context = handler.handleStart(null, carrier, request);
  verify(tracer).spanBuilderWithExplicitParent(any(String.class), same(parentSpan));
  assertThat(context.span).isEqualTo(childSpan);
 } finally {
  scope.close();
 }
}
origin: census-instrumentation/opencensus-java

/**
 * Returns a {@link SpanBuilder} to create and start a new child {@link Span} as a child of to the
 * current {@code Span} if any, otherwise creates a root {@code Span}.
 *
 * <p>See {@link SpanBuilder} for usage examples.
 *
 * <p>This <b>must</b> be used to create a {@code Span} when automatic Context propagation is
 * used.
 *
 * <p>This is equivalent with:
 *
 * <pre>{@code
 * tracer.spanBuilderWithExplicitParent("MySpanName",tracer.getCurrentSpan());
 * }</pre>
 *
 * @param spanName The name of the returned Span.
 * @return a {@code SpanBuilder} to create and start a new {@code Span}.
 * @throws NullPointerException if {@code spanName} is {@code null}.
 * @since 0.5
 */
public final SpanBuilder spanBuilder(String spanName) {
 return spanBuilderWithExplicitParent(spanName, CurrentSpanUtils.getCurrentSpan());
}
io.opencensus.traceTracer

Javadoc

Tracer is a simple, thin class for Span creation and in-process context interaction.

Users may choose to use manual or automatic Context propagation. Because of that this class offers APIs to facilitate both usages.

The automatic context propagation is done using io.grpc.Context which is a gRPC independent implementation for in-process Context propagation mechanism which can carry scoped-values across API boundaries and between threads. Users of the library must propagate the io.grpc.Context between different threads.

Example usage with automatic context propagation:

 
class MyClass } 
} 
}

Example usage with manual context propagation:

 
class MyClass finally  
// To make sure we end the span even in case of an exception. 
childSpan.end();  // Manually end the span. 
} 
} 
} 
}

Most used methods

  • spanBuilder
    Returns a SpanBuilder to create and start a new child Span as a child of to the current Span if any,
  • getCurrentSpan
    Gets the current Span from the current Context.To install a Span to the current Context use #withSpa
  • withSpan
    Returns a Callable that runs the given task with the given Span in the current context.Users may con
  • spanBuilderWithExplicitParent
    Returns a SpanBuilder to create and start a new child Span (or root if parent is null or has an inva
  • spanBuilderWithRemoteParent
    Returns a SpanBuilder to create and start a new child Span (or root if parent is SpanContext#INVALID
  • getNoopTracer
    Returns the no-op implementation of the Tracer.

Popular in Java

  • Finding current android device location
  • requestLocationUpdates (LocationManager)
  • getSharedPreferences (Context)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • String (java.lang)
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now