io.opencensus.trace.Span Java Examples

The following examples show how to use io.opencensus.trace.Span. 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: OpenCensusSleuthSpanContextHolderTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testSpanStackCloseSpanFunction() {
  final org.springframework.cloud.sleuth.Span[] sleuthSpans = createSleuthSpans(4);
  // push all the spans
  for (int i = 0; i < sleuthSpans.length; i++) {
    OpenCensusSleuthSpanContextHolder.push(sleuthSpans[i], /* autoClose= */ false);
  }
  // pop all the spans, verify that given SpanFunction is called on the closed span.
  for (int i = sleuthSpans.length - 1; i >= 0; i--) {
    final int index = i;
    OpenCensusSleuthSpanContextHolder.close(
        new OpenCensusSleuthSpanContextHolder.SpanFunction() {
          @Override
          public void apply(org.springframework.cloud.sleuth.Span span) {
            assertThat(span).isEqualTo(sleuthSpans[index]);
          }
        });
  }
}
 
Example #2
Source File: SpanBuilderImplTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void startChildSpan_SampledLinkedParent() {
  Span rootSpanUnsampled =
      SpanBuilderImpl.createWithParent(SPAN_NAME, null, spanBuilderOptions)
          .setSampler(Samplers.neverSample())
          .startSpan();
  assertThat(rootSpanUnsampled.getContext().getTraceOptions().isSampled()).isFalse();
  Span rootSpanSampled =
      SpanBuilderImpl.createWithParent(SPAN_NAME, null, spanBuilderOptions)
          .setSampler(Samplers.alwaysSample())
          .startSpan();
  assertThat(rootSpanSampled.getContext().getTraceOptions().isSampled()).isTrue();
  // Sampled because the linked parent is sampled.
  Span childSpan =
      SpanBuilderImpl.createWithParent(SPAN_NAME, rootSpanUnsampled, spanBuilderOptions)
          .setParentLinks(Collections.singletonList(rootSpanSampled))
          .startSpan();
  assertThat(childSpan.getContext().isValid()).isTrue();
  assertThat(childSpan.getContext().getTraceId())
      .isEqualTo(rootSpanUnsampled.getContext().getTraceId());
  assertThat(childSpan.getContext().getTraceOptions().isSampled()).isTrue();
}
 
Example #3
Source File: SpanBuilderImplTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void startChildSpan_WithSpecifiedSampler() {
  Span rootSpan =
      SpanBuilderImpl.createWithParent(SPAN_NAME, null, spanBuilderOptions)
          .setSampler(Samplers.alwaysSample())
          .startSpan();
  assertThat(rootSpan.getContext().isValid()).isTrue();
  assertThat(rootSpan.getContext().getTraceOptions().isSampled()).isTrue();
  // Apply the given sampler for child spans.
  Span childSpan =
      SpanBuilderImpl.createWithParent(SPAN_NAME, rootSpan, spanBuilderOptions)
          .setSampler(Samplers.neverSample())
          .startSpan();
  assertThat(childSpan.getContext().isValid()).isTrue();
  assertThat(childSpan.getContext().getTraceId()).isEqualTo(rootSpan.getContext().getTraceId());
  assertThat(childSpan.getContext().getTraceOptions().isSampled()).isFalse();
}
 
Example #4
Source File: SamplersTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void probabilitySampler_DifferentProbabilities_SampledParent() {
  final Sampler neverSample = Samplers.probabilitySampler(0.0);
  assertSamplerSamplesWithProbability(
      neverSample, sampledSpanContext, Collections.<Span>emptyList(), 1.0);
  final Sampler alwaysSample = Samplers.probabilitySampler(1.0);
  assertSamplerSamplesWithProbability(
      alwaysSample, sampledSpanContext, Collections.<Span>emptyList(), 1.0);
  final Sampler fiftyPercentSample = Samplers.probabilitySampler(0.5);
  assertSamplerSamplesWithProbability(
      fiftyPercentSample, sampledSpanContext, Collections.<Span>emptyList(), 1.0);
  final Sampler twentyPercentSample = Samplers.probabilitySampler(0.2);
  assertSamplerSamplesWithProbability(
      twentyPercentSample, sampledSpanContext, Collections.<Span>emptyList(), 1.0);
  final Sampler twoThirdsSample = Samplers.probabilitySampler(2.0 / 3.0);
  assertSamplerSamplesWithProbability(
      twoThirdsSample, sampledSpanContext, Collections.<Span>emptyList(), 1.0);
}
 
Example #5
Source File: Handler.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
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 #6
Source File: JaxrsClientFilterTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testResponseFilter() throws Exception {
  Span span = new FakeSpan(SpanContext.INVALID, null);
  TagContext tagContext = mock(TagContext.class);

  HttpRequestContext context = createHttpRequestContext(span, tagContext);

  ClientRequestContext requestContext = mock(ClientRequestContext.class);
  when(requestContext.getProperty("opencensus.context")).thenReturn(context);

  ClientResponseContext responseContext = mock(ClientResponseContext.class);

  filter.filter(requestContext, responseContext);

  verify(requestContext).getProperty("opencensus.context");
  verify(responseContext, times(1)).getStatus();
}
 
Example #7
Source File: DefaultRateLimitedCache.java    From heroic with Apache License 2.0 6 votes vote down vote up
public boolean acquire(K key, final Runnable cacheHit) {
    try (Scope ss = tracer.spanBuilder("DefaultRateLimitedCache").startScopedSpan()) {
        Span span = tracer.getCurrentSpan();

        if (cache.get(key) != null) {
            cacheHit.run();
            span.addAnnotation("Found key in cache");
            return false;
        }

        span.addAnnotation("Acquiring rate limiter");
        rateLimiter.acquire();
        span.addAnnotation("Acquired rate limiter");

        if (cache.putIfAbsent(key, true) != null) {
            cacheHit.run();
            return false;
        }

        return true;
    }
}
 
Example #8
Source File: OpenCensusSleuthSpanContextHolderTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testSpanStackSimple() {
  org.springframework.cloud.sleuth.Span[] sleuthSpans = createSleuthSpans(4);
  // push all the spans
  for (int i = 0; i < sleuthSpans.length; i++) {
    OpenCensusSleuthSpanContextHolder.push(sleuthSpans[i], /* autoClose= */ false);
    assertThat(OpenCensusSleuthSpanContextHolder.getCurrentSpan()).isEqualTo(sleuthSpans[i]);
    assertSpanEquals(tracer.getCurrentSpan(), sleuthSpans[i]);
  }
  // pop all the spans
  for (int i = sleuthSpans.length - 1; i >= 0; i--) {
    assertThat(OpenCensusSleuthSpanContextHolder.getCurrentSpan()).isEqualTo(sleuthSpans[i]);
    assertSpanEquals(tracer.getCurrentSpan(), sleuthSpans[i]);
    OpenCensusSleuthSpanContextHolder.close();
  }
}
 
Example #9
Source File: SamplersTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void probabilitySampler_DifferentProbabilities_NotSampledParent() {
  final Sampler neverSample = Samplers.probabilitySampler(0.0);
  assertSamplerSamplesWithProbability(
      neverSample, notSampledSpanContext, Collections.<Span>emptyList(), 0.0);
  final Sampler alwaysSample = Samplers.probabilitySampler(1.0);
  assertSamplerSamplesWithProbability(
      alwaysSample, notSampledSpanContext, Collections.<Span>emptyList(), 1.0);
  final Sampler fiftyPercentSample = Samplers.probabilitySampler(0.5);
  assertSamplerSamplesWithProbability(
      fiftyPercentSample, notSampledSpanContext, Collections.<Span>emptyList(), 0.5);
  final Sampler twentyPercentSample = Samplers.probabilitySampler(0.2);
  assertSamplerSamplesWithProbability(
      twentyPercentSample, notSampledSpanContext, Collections.<Span>emptyList(), 0.2);
  final Sampler twoThirdsSample = Samplers.probabilitySampler(2.0 / 3.0);
  assertSamplerSamplesWithProbability(
      twoThirdsSample, notSampledSpanContext, Collections.<Span>emptyList(), 2.0 / 3.0);
}
 
Example #10
Source File: CoreQueryManager.java    From heroic with Apache License 2.0 6 votes vote down vote up
private <T> AsyncFuture<T> run(
    final Function<ClusterNode.Group, AsyncFuture<T>> function,
    final Function<ClusterShard, Transform<Throwable, T>> catcher,
    final Collector<T, T> collector
) {
    final List<AsyncFuture<T>> futures = new ArrayList<>(shards.size());

    for (final ClusterShard shard : shards) {

        final Span span = tracer
            .spanBuilder("CoreQueryManager.run")
            .startSpan();

        span.putAttribute("shard", stringAttributeValue(shard.toString()));

        futures.add(shard
            .apply(function::apply, CoreQueryManager::retryTraceHandlerNoop)
            .catchFailed(catcher.apply(shard))
            .onFinished(span::end));
    }

    return async.collect(futures, collector);
}
 
Example #11
Source File: SpanBuilderImpl.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Override
public Span startSpan() {
  if (remoteParentSpanContext != null) {
    return startSpanInternal(
        remoteParentSpanContext,
        Boolean.TRUE,
        name,
        sampler,
        parentLinks,
        recordEvents,
        kind,
        null);
  } else {
    // This is not a child of a remote Span. Get the parent SpanContext from the parent Span if
    // any.
    SpanContext parentContext = null;
    Boolean hasRemoteParent = null;
    if (parent != null) {
      parentContext = parent.getContext();
      hasRemoteParent = Boolean.FALSE;
    }
    return startSpanInternal(
        parentContext, hasRemoteParent, name, sampler, parentLinks, recordEvents, kind, parent);
  }
}
 
Example #12
Source File: OcAgentTraceExporterIntegrationTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
private void doWork(String spanName, int i) {
  try (Scope scope = tracer.spanBuilder(spanName).startScopedSpan()) {
    // Simulate some work.
    Span span = tracer.getCurrentSpan();

    try {
      Thread.sleep(10L);
    } catch (InterruptedException e) {
      span.setStatus(Status.INTERNAL.withDescription(e.toString()));
    }

    Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
    attributes.put("inner work iteration number", AttributeValue.longAttributeValue(i));
    span.addAnnotation("Invoking doWork", attributes);
  }
}
 
Example #13
Source File: BigtableMutatorImpl.java    From heroic with Apache License 2.0 6 votes vote down vote up
private BulkMutation getOrAddBulkMutation(String tableName) {
    final Span span = tracer.spanBuilder("BigtableMutator.getOrAddBulkMutation").startSpan();
    try (Scope ws = tracer.withSpan(span)) {
        span.addAnnotation("Acquiring lock");
        synchronized (tableAccessLock) {
            span.addAnnotation("Lock acquired");

            if (tableToBulkMutation.containsKey(tableName)) {
                span.setStatus(Status.ALREADY_EXISTS.withDescription("Mutation exists in map"));
                span.end();
                return tableToBulkMutation.get(tableName);
            }

            final BulkMutation bulkMutation = session.createBulkMutation(
                session
                    .getOptions()
                    .getInstanceName()
                    .toTableName(tableName));

            tableToBulkMutation.put(tableName, bulkMutation);

            span.end();
            return bulkMutation;
        }
    }
}
 
Example #14
Source File: SpanBuilderImplTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void startChildSpan() {
  Span rootSpan =
      SpanBuilderImpl.createWithParent(SPAN_NAME, null, spanBuilderOptions).startSpan();
  assertThat(rootSpan.getContext().isValid()).isTrue();
  assertThat(rootSpan.getOptions().contains(Options.RECORD_EVENTS)).isTrue();
  assertThat(rootSpan.getContext().getTraceOptions().isSampled()).isTrue();
  assertThat(((RecordEventsSpanImpl) rootSpan).toSpanData().getHasRemoteParent()).isNull();
  Span childSpan =
      SpanBuilderImpl.createWithParent(SPAN_NAME, rootSpan, spanBuilderOptions).startSpan();
  assertThat(childSpan.getContext().isValid()).isTrue();
  assertThat(childSpan.getContext().getTraceId()).isEqualTo(rootSpan.getContext().getTraceId());
  assertThat(((RecordEventsSpanImpl) childSpan).toSpanData().getParentSpanId())
      .isEqualTo(rootSpan.getContext().getSpanId());
  assertThat(((RecordEventsSpanImpl) childSpan).toSpanData().getHasRemoteParent()).isFalse();
  assertThat(((RecordEventsSpanImpl) childSpan).getTimestampConverter())
      .isEqualTo(((RecordEventsSpanImpl) rootSpan).getTimestampConverter());
}
 
Example #15
Source File: CensusModulesTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
  when(spyClientSpanBuilder.startSpan()).thenReturn(spyClientSpan);
  when(tracer.spanBuilderWithExplicitParent(anyString(), ArgumentMatchers.<Span>any()))
      .thenReturn(spyClientSpanBuilder);
  when(spyServerSpanBuilder.startSpan()).thenReturn(spyServerSpan);
  when(tracer.spanBuilderWithRemoteParent(anyString(), ArgumentMatchers.<SpanContext>any()))
      .thenReturn(spyServerSpanBuilder);
  when(mockTracingPropagationHandler.toByteArray(any(SpanContext.class)))
      .thenReturn(binarySpanContext);
  when(mockTracingPropagationHandler.fromByteArray(any(byte[].class)))
      .thenReturn(fakeClientSpanContext);
  censusStats =
      new CensusStatsModule(
          tagger, tagCtxSerializer, statsRecorder, fakeClock.getStopwatchSupplier(),
          true, true, true, false /* real-time */);
  censusTracing = new CensusTracingModule(tracer, mockTracingPropagationHandler);
}
 
Example #16
Source File: BasicOperationsBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Create a child span. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Span createSpanWithExplicitParent(Data data) {
  Span span =
      data.tracer
          .spanBuilderWithExplicitParent("ChildSpan", data.span)
          .setRecordEvents(data.recorded)
          .setSampler(data.sampled ? Samplers.alwaysSample() : Samplers.neverSample())
          .startSpan();
  span.end();
  return span;
}
 
Example #17
Source File: BasicOperationsBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Create a root span. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Span createRootSpan(Data data) {
  Span span =
      data.tracer
          .spanBuilderWithExplicitParent("RootSpan", null)
          .setRecordEvents(data.recorded)
          .setSampler(data.sampled ? Samplers.alwaysSample() : Samplers.neverSample())
          .startSpan();
  span.end();
  return span;
}
 
Example #18
Source File: OpenCensusTraceLoggingEnhancerTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private static LogEntry getEnhancedLogEntry(LoggingEnhancer loggingEnhancer, Span span) {
  Scope scope = tracer.withSpan(span);
  try {
    LogEntry.Builder builder = LogEntry.newBuilder(null);
    loggingEnhancer.enhanceLogEntry(builder);
    return builder.build();
  } finally {
    scope.close();
  }
}
 
Example #19
Source File: BasicOperationsBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Get current trace span. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Span getCurrentSpan(Data data) {
  return data.tracer.getCurrentSpan();
}
 
Example #20
Source File: MemoryBackend.java    From heroic with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncFuture<FetchData.Result> fetch(
    FetchData.Request request,
    FetchQuotaWatcher watcher,
    Consumer<MetricReadResult> metricsConsumer,
    Span parentSpan
) {
    final QueryTrace.NamedWatch w = QueryTrace.watch(FETCH);
    final MemoryKey key = new MemoryKey(request.getType(), request.getSeries().getTags());
    doFetch(key, request.getRange(), watcher, metricsConsumer);
    return async.resolved(new FetchData.Result(w.end()));
}
 
Example #21
Source File: OpenCensusSleuthSpanContextHolderTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private static void assertSpanEquals(
    Span span, org.springframework.cloud.sleuth.Span sleuthSpan) {
  assertThat(Long.parseLong(span.getContext().getTraceId().toLowerBase16().substring(0, 16), 16))
      .isEqualTo(sleuthSpan.getTraceIdHigh());
  assertThat(Long.parseLong(span.getContext().getTraceId().toLowerBase16().substring(16, 32), 16))
      .isEqualTo(sleuthSpan.getTraceId());
  assertThat(Long.parseLong(span.getContext().getSpanId().toLowerBase16(), 16))
      .isEqualTo(sleuthSpan.getSpanId());
  assertThat(span.getContext().getTraceOptions().isSampled())
      .isEqualTo(sleuthSpan.isExportable());
}
 
Example #22
Source File: BigtableBackend.java    From heroic with Apache License 2.0 5 votes vote down vote up
@Override
public AsyncFuture<WriteMetric> write(
    final WriteMetric.Request request, final Span parentSpan
) {
    return connection.doto(c -> {
        final Series series = request.getSeries();
        final List<AsyncFuture<WriteMetric>> results = new ArrayList<>();

        final BigtableDataClient client = c.getDataClient();

        final MetricCollection g = request.getData();
        results.add(writeTyped(series, client, g, parentSpan));
        return async.collect(results, WriteMetric.reduce());
    });
}
 
Example #23
Source File: CensusTracingModule.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #24
Source File: HttpServerHandler.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/**
 * Instrument an incoming request before it is handled.
 *
 * <p>This method will create a span under the deserialized propagated parent context. If the
 * parent context is not present, the span will be created under the current context.
 *
 * <p>The generated span will NOT be set as current context. User can control when to enter the
 * scope of this span. Use {@link AbstractHttpHandler#getSpanFromContext} to retrieve the span.
 *
 * @param carrier the entity that holds the HTTP information.
 * @param request the request entity.
 * @return the {@link HttpRequestContext} that contains stats and trace data associated with the
 *     request.
 * @since 0.19
 */
public HttpRequestContext handleStart(C carrier, Q request) {
  checkNotNull(carrier, "carrier");
  checkNotNull(request, "request");
  SpanBuilder spanBuilder = null;
  String spanName = getSpanName(request, extractor);
  // de-serialize the context
  SpanContext spanContext = null;
  try {
    spanContext = textFormat.extract(carrier, getter);
  } catch (SpanContextParseException e) {
    // TODO: Currently we cannot distinguish between context parse error and missing context.
    // Logging would be annoying so we just ignore this error and do not even log a message.
  }
  if (spanContext == null || publicEndpoint) {
    spanBuilder = tracer.spanBuilder(spanName);
  } else {
    spanBuilder = tracer.spanBuilderWithRemoteParent(spanName, spanContext);
  }

  Span span = spanBuilder.setSpanKind(Kind.SERVER).startSpan();
  if (publicEndpoint && spanContext != null) {
    span.addLink(Link.fromSpanContext(spanContext, Type.PARENT_LINKED_SPAN));
  }

  if (span.getOptions().contains(Options.RECORD_EVENTS)) {
    addSpanRequestAttributes(span, request, extractor);
  }

  return getNewContext(span, tagger.getCurrentTagContext());
}
 
Example #25
Source File: CoreIngestionGroup.java    From heroic with Apache License 2.0 5 votes vote down vote up
protected AsyncFuture<Ingestion> doSuggestWrite(
    final SuggestBackend suggest, final Request write, final DateRange range,
    final Span parentSpan
) {
    return suggest
        .write(new WriteSuggest.Request(write.getSeries(), range), parentSpan)
        .directTransform(Ingestion::fromWriteSuggest);
}
 
Example #26
Source File: RecordTraceEventsBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** This benchmark attempts to measure performance of adding a link to the span. */
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Span addLink(Data data) {
  data.span.addLink(
      Link.fromSpanContext(data.linkedSpan.getContext(), Link.Type.PARENT_LINKED_SPAN));
  return data.span;
}
 
Example #27
Source File: LocalMetricManager.java    From heroic with Apache License 2.0 5 votes vote down vote up
private Transform(
    final FullQuery.Request request,
    final boolean failOnLimits,
    final OptionalLimit seriesLimit,
    final OptionalLimit groupLimit,
    final QuotaWatcher quotaWatcher,
    final DataInMemoryReporter dataInMemoryReporter,
    final Span parentSpan
) {
    this.aggregation = request.aggregation();
    this.range = request.range();
    this.options = request.options();
    this.source = request.source();

    this.failOnLimits = failOnLimits;
    this.seriesLimit = seriesLimit;
    this.groupLimit = groupLimit;

    this.namedWatch = QueryTrace.watch(QUERY);
    this.quotaWatcher = quotaWatcher;

    this.dataInMemoryReporter = dataInMemoryReporter;
    this.parentSpan = parentSpan;

    final Features features = request.features();
    this.bucketStrategy = options
        .bucketStrategy()
        .orElseGet(
            () -> features.withFeature(Feature.END_BUCKET, () -> BucketStrategy.END,
                () -> BucketStrategy.START));
}
 
Example #28
Source File: OpenCensusSleuthSpanContextHolderTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromSleuthUnsampled() {
  org.springframework.cloud.sleuth.Span sleuthSpan =
      createSleuthSpan(21, 22, 23, /* exportable= */ false);
  OpenCensusSleuthSpanContextHolder.setCurrentSpan(sleuthSpan);
  assertThat(OpenCensusSleuthSpanContextHolder.isTracing()).isTrue();
  assertThat(OpenCensusSleuthSpanContextHolder.getCurrentSpan()).isEqualTo(sleuthSpan);
  assertSpanEquals(tracer.getCurrentSpan(), sleuthSpan);
  assertThat(tracer.getCurrentSpan().getContext().getTraceOptions().isSampled()).isFalse();
  OpenCensusSleuthSpanContextHolder.close();
}
 
Example #29
Source File: SpanOperationsBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Add attributes individually. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Span putAttribute(Data data) {
  Span span = data.attributeSpan;
  for (int i = 0; i < data.size; i++) {
    span.putAttribute(data.attributeKeys[i], data.attributeValues[i]);
  }
  return span;
}
 
Example #30
Source File: NeverSampleSampler.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Override
public boolean shouldSample(
    @Nullable SpanContext parentContext,
    @Nullable Boolean hasRemoteParent,
    TraceId traceId,
    SpanId spanId,
    String name,
    List<Span> parentLinks) {
  return false;
}