io.opencensus.trace.config.TraceParams Java Examples

The following examples show how to use io.opencensus.trace.config.TraceParams. 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: RecordEventsSpanImplTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void sampleToLocalSpanStore_RunningSpan() {
  RecordEventsSpanImpl span =
      RecordEventsSpanImpl.startSpan(
          spanContext,
          SPAN_NAME,
          null,
          parentSpanId,
          false,
          TraceParams.DEFAULT,
          startEndHandler,
          timestampConverter,
          testClock);
  exception.expect(IllegalStateException.class);
  exception.expectMessage("Running span does not have the SampleToLocalSpanStore set.");
  span.getSampleToLocalSpanStore();
}
 
Example #2
Source File: TraceProtoUtils.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
/**
 * Converts {@link TraceConfig} to {@link TraceParams}.
 *
 * @param traceConfigProto {@code TraceConfig}.
 * @param currentTraceParams current {@code TraceParams}.
 * @return updated {@code TraceParams}.
 * @since 0.17
 */
static TraceParams fromTraceConfigProto(
    TraceConfig traceConfigProto, TraceParams currentTraceParams) {
  TraceParams.Builder builder = currentTraceParams.toBuilder();
  if (traceConfigProto.hasConstantSampler()) {
    ConstantSampler constantSampler = traceConfigProto.getConstantSampler();
    ConstantDecision decision = constantSampler.getDecision();
    if (ConstantDecision.ALWAYS_ON.equals(decision)) {
      builder.setSampler(Samplers.alwaysSample());
    } else if (ConstantDecision.ALWAYS_OFF.equals(decision)) {
      builder.setSampler(Samplers.neverSample());
    } // else if (ConstantDecision.ALWAYS_PARENT.equals(decision)) {
    // For ALWAYS_PARENT, don't need to update configs since in Java by default parent sampling
    // decision always takes precedence.
    // }
  } else if (traceConfigProto.hasProbabilitySampler()) {
    builder.setSampler(
        Samplers.probabilitySampler(
            traceConfigProto.getProbabilitySampler().getSamplingProbability()));
  } // TODO: add support for RateLimitingSampler.
  return builder.build();
}
 
Example #3
Source File: TraceProtoUtils.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
/**
 * Converts {@link TraceParams} to {@link TraceConfig}.
 *
 * @param traceParams the {@code TraceParams}.
 * @return {@code TraceConfig}.
 */
static TraceConfig toTraceConfigProto(TraceParams traceParams) {
  TraceConfig.Builder traceConfigProtoBuilder = TraceConfig.newBuilder();
  Sampler librarySampler = traceParams.getSampler();

  if (Samplers.alwaysSample().equals(librarySampler)) {
    traceConfigProtoBuilder.setConstantSampler(
        ConstantSampler.newBuilder().setDecision(ConstantDecision.ALWAYS_ON).build());
  } else if (Samplers.neverSample().equals(librarySampler)) {
    traceConfigProtoBuilder.setConstantSampler(
        ConstantSampler.newBuilder().setDecision(ConstantDecision.ALWAYS_OFF).build());
  } else {
    // TODO: consider exposing the sampling probability of ProbabilitySampler.
    double samplingProbability = parseSamplingProbability(librarySampler);
    traceConfigProtoBuilder.setProbabilitySampler(
        ProbabilitySampler.newBuilder().setSamplingProbability(samplingProbability).build());
  } // TODO: add support for RateLimitingSampler.

  return traceConfigProtoBuilder.build();
}
 
Example #4
Source File: HttpServletFilterIntegrationTests.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Before
@Override
public void setup() {
  super.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);
}
 
Example #5
Source File: InProcessRunningSpanStoreImplTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
private RecordEventsSpanImpl createSpan(String spanName) {
  final SpanContext spanContext =
      SpanContext.create(
          TraceId.generateRandomId(random),
          SpanId.generateRandomId(random),
          TraceOptions.DEFAULT,
          Tracestate.builder().build());
  return RecordEventsSpanImpl.startSpan(
      spanContext,
      spanName,
      null,
      SpanId.generateRandomId(random),
      false,
      TraceParams.DEFAULT,
      startEndHandler,
      null,
      MillisClock.getInstance());
}
 
Example #6
Source File: SpanExporterImplTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
private RecordEventsSpanImpl createNotSampledEndedSpan(
    StartEndHandler startEndHandler, String spanName) {
  RecordEventsSpanImpl span =
      RecordEventsSpanImpl.startSpan(
          notSampledSpanContext,
          spanName,
          null,
          null,
          false,
          TraceParams.DEFAULT,
          startEndHandler,
          null,
          MillisClock.getInstance());
  span.end();
  return span;
}
 
Example #7
Source File: SpanExporterImplTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
private RecordEventsSpanImpl createSampledEndedSpan(
    StartEndHandler startEndHandler, String spanName) {
  RecordEventsSpanImpl span =
      RecordEventsSpanImpl.startSpan(
          sampledSpanContext,
          spanName,
          null,
          null,
          false,
          TraceParams.DEFAULT,
          startEndHandler,
          null,
          MillisClock.getInstance());
  span.end();
  return span;
}
 
Example #8
Source File: TraceConfigImplTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void updateTraceParams() {
  TraceParams traceParams =
      TraceParams.DEFAULT
          .toBuilder()
          .setSampler(Samplers.alwaysSample())
          .setMaxNumberOfAttributes(8)
          .setMaxNumberOfAnnotations(9)
          .setMaxNumberOfNetworkEvents(10)
          .setMaxNumberOfLinks(11)
          .build();
  traceConfig.updateActiveTraceParams(traceParams);
  assertThat(traceConfig.getActiveTraceParams()).isEqualTo(traceParams);
  traceConfig.updateActiveTraceParams(TraceParams.DEFAULT);
  assertThat(traceConfig.getActiveTraceParams()).isEqualTo(TraceParams.DEFAULT);
}
 
Example #9
Source File: RecordEventsSpanImplTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void status_ViaEndSpanOptions() {
  RecordEventsSpanImpl span =
      RecordEventsSpanImpl.startSpan(
          spanContext,
          SPAN_NAME,
          null,
          parentSpanId,
          false,
          TraceParams.DEFAULT,
          startEndHandler,
          timestampConverter,
          testClock);
  Mockito.verify(startEndHandler, Mockito.times(1)).onStart(span);
  testClock.advanceTime(Duration.create(0, 100));
  assertThat(span.getStatus()).isEqualTo(Status.OK);
  span.setStatus(Status.CANCELLED);
  assertThat(span.getStatus()).isEqualTo(Status.CANCELLED);
  span.end(EndSpanOptions.builder().setStatus(Status.ABORTED).build());
  assertThat(span.getStatus()).isEqualTo(Status.ABORTED);
}
 
Example #10
Source File: RecordEventsSpanImplTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void status_ViaSetStatus() {
  RecordEventsSpanImpl span =
      RecordEventsSpanImpl.startSpan(
          spanContext,
          SPAN_NAME,
          null,
          parentSpanId,
          false,
          TraceParams.DEFAULT,
          startEndHandler,
          timestampConverter,
          testClock);
  Mockito.verify(startEndHandler, Mockito.times(1)).onStart(span);
  testClock.advanceTime(Duration.create(0, 100));
  assertThat(span.getStatus()).isEqualTo(Status.OK);
  span.setStatus(Status.CANCELLED);
  assertThat(span.getStatus()).isEqualTo(Status.CANCELLED);
  span.end();
  assertThat(span.getStatus()).isEqualTo(Status.CANCELLED);
}
 
Example #11
Source File: TraceProtoUtilsTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void applyUpdatedConfig() {
  TraceConfig configProto =
      TraceConfig.newBuilder()
          .setProbabilitySampler(
              ProbabilitySampler.newBuilder().setSamplingProbability(0.01).build())
          .build();
  UpdatedLibraryConfig updatedLibraryConfig =
      UpdatedLibraryConfig.newBuilder().setConfig(configProto).build();
  TraceParams traceParams =
      TraceProtoUtils.getUpdatedTraceParams(updatedLibraryConfig, mockTraceConfig);
  TraceParams expectedParams =
      DEFAULT_PARAMS.toBuilder().setSampler(Samplers.probabilitySampler(0.01)).build();
  Mockito.verify(mockTraceConfig, Mockito.times(1)).getActiveTraceParams();
  assertThat(traceParams).isEqualTo(expectedParams);
}
 
Example #12
Source File: RecordEventsSpanImplTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void deprecatedAddAttributesStillWorks() {
  RecordEventsSpanImpl span =
      RecordEventsSpanImpl.startSpan(
          spanContext,
          SPAN_NAME,
          null,
          parentSpanId,
          false,
          TraceParams.DEFAULT,
          startEndHandler,
          timestampConverter,
          testClock);
  span.addAttributes(attributes);
  span.end();
  SpanData spanData = span.toSpanData();
  assertThat(spanData.getAttributes().getAttributeMap()).isEqualTo(attributes);
}
 
Example #13
Source File: RecordEventsSpanImpl.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
private RecordEventsSpanImpl(
    SpanContext context,
    String name,
    @Nullable Kind kind,
    @Nullable SpanId parentSpanId,
    @Nullable Boolean hasRemoteParent,
    TraceParams traceParams,
    StartEndHandler startEndHandler,
    @Nullable TimestampConverter timestampConverter,
    Clock clock) {
  super(context, RECORD_EVENTS_SPAN_OPTIONS);
  this.parentSpanId = parentSpanId;
  this.hasRemoteParent = hasRemoteParent;
  this.name = name;
  this.kind = kind;
  this.traceParams = traceParams;
  this.startEndHandler = startEndHandler;
  this.clock = clock;
  this.hasBeenEnded = false;
  this.sampleToLocalSpanStore = false;
  this.numberOfChildren = 0;
  this.timestampConverter =
      timestampConverter != null ? timestampConverter : TimestampConverter.now(clock);
  startNanoTime = clock.nowNanos();
}
 
Example #14
Source File: SpanBuilderImpl.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
private static boolean makeSamplingDecision(
    @Nullable SpanContext parent,
    @Nullable Boolean hasRemoteParent,
    String name,
    @Nullable Sampler sampler,
    List<Span> parentLinks,
    TraceId traceId,
    SpanId spanId,
    TraceParams activeTraceParams) {
  // If users set a specific sampler in the SpanBuilder, use it.
  if (sampler != null) {
    return sampler.shouldSample(parent, hasRemoteParent, traceId, spanId, name, parentLinks);
  }
  // Use the default sampler if this is a root Span or this is an entry point Span (has remote
  // parent).
  if (Boolean.TRUE.equals(hasRemoteParent) || parent == null || !parent.isValid()) {
    return activeTraceParams
        .getSampler()
        .shouldSample(parent, hasRemoteParent, traceId, spanId, name, parentLinks);
  }
  // Parent is always different than null because otherwise we use the default sampler.
  return parent.getTraceOptions().isSampled() || isAnyParentLinkSampled(parentLinks);
}
 
Example #15
Source File: MetaStoreServer.java    From metastore with Apache License 2.0 5 votes vote down vote up
/** Main method. This comment makes the linter happy. */
public static void main(String[] args) throws Exception {
  LOG.info("MetaStore server");
  printVersion();

  ArgumentParser parser = ArgumentParsers.newFor("metastore").build();
  parser.addArgument("-c", "--config").required(false);

  Namespace res = parser.parseArgs(args);
  String configPath = res.getString("config");
  if (configPath == null) {
    LOG.info("No configuration file set via argument, setting from environment.");
    configPath = System.getenv("METASTORE_CONFIG_PATH");
    LOG.info("Taking configuration file: " + configPath);
  } else {
    LOG.info("Taking configuration file: " + configPath);
  }

  // 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());

  String port = System.getenv("PORT");
  if (port == null) {
    port = "8980";
  }
  MetaStoreServer server = new MetaStoreServer(configPath, Integer.valueOf(port));
  server.start();
  server.blockUntilShutdown();
}
 
Example #16
Source File: RecordEventsSpanImpl.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and starts a span with the given configuration.
 *
 * @param context supplies the trace_id and span_id for the newly started span.
 * @param name the displayed name for the new span.
 * @param parentSpanId the span_id of the parent span, or null if the new span is a root span.
 * @param hasRemoteParent {@code true} if the parentContext is remote. {@code null} if this is a
 *     root span.
 * @param traceParams trace parameters like sampler and probability.
 * @param startEndHandler handler called when the span starts and ends.
 * @param timestampConverter null if the span is a root span or the parent is not sampled. If the
 *     parent is sampled, we should use the same converter to ensure ordering between tracing
 *     events.
 * @param clock the clock used to get the time.
 * @return a new and started span.
 */
@VisibleForTesting
public static RecordEventsSpanImpl startSpan(
    SpanContext context,
    String name,
    @Nullable Kind kind,
    @Nullable SpanId parentSpanId,
    @Nullable Boolean hasRemoteParent,
    TraceParams traceParams,
    StartEndHandler startEndHandler,
    @Nullable TimestampConverter timestampConverter,
    Clock clock) {
  RecordEventsSpanImpl span =
      new RecordEventsSpanImpl(
          context,
          name,
          kind,
          parentSpanId,
          hasRemoteParent,
          traceParams,
          startEndHandler,
          timestampConverter,
          clock);
  // Call onStart here instead of calling in the constructor to make sure the span is completely
  // initialized.
  startEndHandler.onStart(span);
  return span;
}
 
Example #17
Source File: TraceConfigzZPageHandler.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private static void emitTraceParamsTable(TraceParams params, PrintWriter out) {
  out.write(
      "<b class=\"title\">Active tracing parameters:</b><br>\n"
          + "<table class=\"small\" rules=\"all\">\n"
          + "  <tr>\n"
          + "    <td class=\"col_headR\">Name</td>\n"
          + "    <td class=\"col_head\">Value</td>\n"
          + "  </tr>\n");
  out.printf(
      "  <tr>%n    <td>Sampler</td>%n    <td>%s</td>%n  </tr>%n",
      params.getSampler().getDescription());
  out.printf(
      "  <tr>%n    <td>MaxNumberOfAttributes</td>%n    <td>%d</td>%n  </tr>%n",
      params.getMaxNumberOfAttributes());
  out.printf(
      "  <tr>%n    <td>MaxNumberOfAnnotations</td>%n    <td>%d</td>%n  </tr>%n",
      params.getMaxNumberOfAnnotations());
  out.printf(
      "  <tr>%n    <td>MaxNumberOfNetworkEvents</td>%n    <td>%d</td>%n  </tr>%n",
      params.getMaxNumberOfNetworkEvents());
  out.printf(
      "  <tr>%n    <td>MaxNumberOfLinks</td>%n    <td>%d</td>%n  </tr>%n",
      params.getMaxNumberOfLinks());

  out.write("</table>\n");
}
 
Example #18
Source File: TraceConfigzZPageHandler.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void maybeApplyChanges(Map<String, String> queryMap) {
  String changeStr = queryMap.get(CHANGE);
  if (PERMANENT_CHANGE.equals(changeStr)) {
    TraceParams.Builder traceParamsBuilder = traceConfig.getActiveTraceParams().toBuilder();
    String samplingProbabilityStr = queryMap.get(QUERY_COMPONENT_SAMPLING_PROBABILITY);
    if (!isNullOrEmpty(samplingProbabilityStr)) {
      double samplingProbability = Double.parseDouble(samplingProbabilityStr);
      traceParamsBuilder.setSampler(Samplers.probabilitySampler(samplingProbability));
    }
    String maxNumberOfAttributesStr = queryMap.get(QUERY_COMPONENT_MAX_NUMBER_OF_ATTRIBUTES);
    if (!isNullOrEmpty(maxNumberOfAttributesStr)) {
      int maxNumberOfAttributes = Integer.parseInt(maxNumberOfAttributesStr);
      traceParamsBuilder.setMaxNumberOfAttributes(maxNumberOfAttributes);
    }
    String maxNumberOfAnnotationsStr = queryMap.get(QUERY_COMPONENT_MAX_NUMBER_OF_ANNOTATIONS);
    if (!isNullOrEmpty(maxNumberOfAnnotationsStr)) {
      int maxNumberOfAnnotations = Integer.parseInt(maxNumberOfAnnotationsStr);
      traceParamsBuilder.setMaxNumberOfAnnotations(maxNumberOfAnnotations);
    }
    String maxNumberOfNetworkEventsStr =
        queryMap.get(QUERY_COMPONENT_MAX_NUMBER_OF_NETWORK_EVENTS);
    if (!isNullOrEmpty(maxNumberOfNetworkEventsStr)) {
      int maxNumberOfNetworkEvents = Integer.parseInt(maxNumberOfNetworkEventsStr);
      traceParamsBuilder.setMaxNumberOfNetworkEvents(maxNumberOfNetworkEvents);
    }
    String maxNumverOfLinksStr = queryMap.get(QUERY_COMPONENT_MAX_NUMBER_OF_LINKS);
    if (!isNullOrEmpty(maxNumverOfLinksStr)) {
      int maxNumberOfLinks = Integer.parseInt(maxNumverOfLinksStr);
      traceParamsBuilder.setMaxNumberOfLinks(maxNumberOfLinks);
    }
    traceConfig.updateActiveTraceParams(traceParamsBuilder.build());
  } else if (RESTORE_DEFAULT_CHANGE.equals(changeStr)) {
    traceConfig.updateActiveTraceParams(TraceParams.DEFAULT);
  }
}
 
Example #19
Source File: BasicSetup.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/**
 * Enables OpenCensus metric and traces.
 *
 * <p>This will register all basic {@link io.opencensus.stats.View}s. When coupled with an agent,
 * it allows users to monitor application behavior.
 *
 * <p>Example usage for maven:
 *
 * <pre>{@code
 * <dependency>
 *   <groupId>io.opencensus</groupId>
 *   <artifactId>opencensus-contrib-observability-ready-util</artifactId>
 *   <version>${opencensus.version}</version>
 * </dependency>
 * }</pre>
 *
 * <p>It is recommended to call this method before doing any RPC call to avoid missing stats.
 *
 * <pre>{@code
 * BasicSetup.enableOpenCensus();
 * }</pre>
 *
 * @param endPoint the end point of OC-Agent.
 * @param probability the desired probability of sampling. Must be within [0.0, 1.0].
 * @since 0.25
 */
public static void enableOpenCensus(String endPoint, double probability) {
  // register basic rpc views
  RpcViews.registerAllGrpcBasicViews();

  // set sampling rate
  TraceConfig traceConfig = Tracing.getTraceConfig();
  TraceParams activeTraceParams = traceConfig.getActiveTraceParams();
  traceConfig.updateActiveTraceParams(
      activeTraceParams.toBuilder().setSampler(Samplers.probabilitySampler(probability)).build());

  String serviceName = firstNonNull(System.getenv("SERVICE_NAME"), DEAFULT_SERVICE_NAME);
  // create and register Trace Agent Exporter
  OcAgentTraceExporter.createAndRegister(
      OcAgentTraceExporterConfiguration.builder()
          .setEndPoint(endPoint)
          .setServiceName(serviceName)
          .setUseInsecure(true)
          .setEnableConfig(false)
          .build());

  // create and register Metrics Agent Exporter
  OcAgentMetricsExporter.createAndRegister(
      OcAgentMetricsExporterConfiguration.builder()
          .setEndPoint(endPoint)
          .setServiceName(serviceName)
          .setUseInsecure(true)
          .build());
}
 
Example #20
Source File: CensusSpringAspectTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #21
Source File: TraceWebAsyncClientAutoConfigurationTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #22
Source File: NoopSampledSpanStoreImplTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void noopImplementation() {
  // None of the get methods should yield non-empty result.
  getMethodsShouldReturnEmpty();

  // registerSpanNamesForCollection() should do nothing and do not affect the result.
  sampledSpanStoreImpl.registerSpanNamesForCollection(NAMES_FOR_COLLECTION);
  getMethodsShouldReturnEmpty();

  // considerForSampling() should do nothing and do not affect the result.
  // It should be called after registerSpanNamesForCollection.
  recordEventsSpanImpl =
      RecordEventsSpanImpl.startSpan(
          spanContext,
          SPAN_NAME,
          null,
          null,
          false,
          TraceParams.DEFAULT,
          startEndHandler,
          timestampConverter,
          testClock);
  recordEventsSpanImpl.end();
  sampledSpanStoreImpl.considerForSampling(recordEventsSpanImpl);
  getMethodsShouldReturnEmpty();

  // unregisterSpanNamesForCollection() should do nothing and do not affect the result.
  sampledSpanStoreImpl.unregisterSpanNamesForCollection(NAMES_FOR_COLLECTION);
  getMethodsShouldReturnEmpty();
}
 
Example #23
Source File: HttpRequestTracingTest.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
@Before
public void setupTestTracer() {
  Tracing.getExportComponent().getSpanExporter().registerHandler("test", testHandler);
  TraceParams params =
      Tracing.getTraceConfig()
          .getActiveTraceParams()
          .toBuilder()
          .setSampler(Samplers.alwaysSample())
          .build();
  Tracing.getTraceConfig().updateActiveTraceParams(params);
}
 
Example #24
Source File: NoopInProcessRunningSpanStoreTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  recordEventsSpanImpl =
      RecordEventsSpanImpl.startSpan(
          spanContext,
          SPAN_NAME,
          null,
          null,
          false,
          TraceParams.DEFAULT,
          startEndHandler,
          timestampConverter,
          testClock);
}
 
Example #25
Source File: InProcessSampledSpanStoreImplTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private RecordEventsSpanImpl createNotSampledSpan(String spanName) {
  return RecordEventsSpanImpl.startSpan(
      notSampledSpanContext,
      spanName,
      null,
      parentSpanId,
      false,
      TraceParams.DEFAULT,
      startEndHandler,
      null,
      testClock);
}
 
Example #26
Source File: InProcessSampledSpanStoreImplTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private RecordEventsSpanImpl createSampledSpan(String spanName) {
  return RecordEventsSpanImpl.startSpan(
      sampledSpanContext,
      spanName,
      null,
      parentSpanId,
      false,
      TraceParams.DEFAULT,
      startEndHandler,
      null,
      testClock);
}
 
Example #27
Source File: OcAgentTraceServiceRpcHandlersTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws IOException {
  MockitoAnnotations.initMocks(this);
  Mockito.doReturn(TraceParams.DEFAULT).when(mockTraceConfig).getActiveTraceParams();
  Mockito.doNothing().when(mockTraceConfig).updateActiveTraceParams(any(TraceParams.class));

  traceServiceGrpc = new FakeOcAgentTraceServiceGrpcImpl();
  serverName = InProcessServerBuilder.generateName();
  server =
      InProcessServerBuilder.forName(serverName)
          .directExecutor() // directExecutor is fine for unit tests
          .addService(traceServiceGrpc)
          .build()
          .start();
}
 
Example #28
Source File: OcAgentTraceServiceConfigRpcHandler.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Override
public void onNext(UpdatedLibraryConfig value) {
  // First, apply the incoming updated config.
  TraceParams updatedTraceParams = TraceProtoUtils.getUpdatedTraceParams(value, traceConfig);
  traceConfig.updateActiveTraceParams(updatedTraceParams);

  // Then echo back current config.
  configRpcHandler.sendCurrentConfig();
}
 
Example #29
Source File: RecordEventsSpanImplTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getSpanKind() {
  RecordEventsSpanImpl span =
      RecordEventsSpanImpl.startSpan(
          spanContext,
          SPAN_NAME,
          Kind.SERVER,
          parentSpanId,
          false,
          TraceParams.DEFAULT,
          startEndHandler,
          timestampConverter,
          testClock);
  assertThat(span.getKind()).isEqualTo(Kind.SERVER);
}
 
Example #30
Source File: RecordEventsSpanImplTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void sampleToLocalSpanStore() {
  RecordEventsSpanImpl span =
      RecordEventsSpanImpl.startSpan(
          spanContext,
          SPAN_NAME,
          null,
          parentSpanId,
          false,
          TraceParams.DEFAULT,
          startEndHandler,
          timestampConverter,
          testClock);
  span.end(EndSpanOptions.builder().setSampleToLocalSpanStore(true).build());
  Mockito.verify(startEndHandler, Mockito.times(1)).onEnd(span);
  assertThat(span.getSampleToLocalSpanStore()).isTrue();
  span =
      RecordEventsSpanImpl.startSpan(
          spanContext,
          SPAN_NAME,
          null,
          parentSpanId,
          false,
          TraceParams.DEFAULT,
          startEndHandler,
          timestampConverter,
          testClock);
  span.end();
  Mockito.verify(startEndHandler, Mockito.times(1)).onEnd(span);
  assertThat(span.getSampleToLocalSpanStore()).isFalse();
}