.setSampler(Samplers.alwaysSample()) .startScopedSpan()) { ResultSet resultSet = dbClient.singleUse().executeQuery(Statement.of("SELECT 1"));
@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(); }
tracer .spanBuilder("ExportDatadogTraces") .setSampler(probabilitySpampler) .startScopedSpan()) {
private void pollPods() { try { try (Scope ss = tracer.spanBuilder("Styx.KubernetesDockerRunner.pollPods") .setRecordEvents(true) .setSampler(Samplers.alwaysSample()) .startScopedSpan()) { tryPollPods(); } } catch (Throwable t) { LOG.warn("Error while polling pods", t); } }
tracer.spanBuilder("ExportInstanaTraces").setSampler(probabilitySpampler).startScopedSpan(); try { String json = convertToJson(spanDataList);
@Override public void export(Collection<SpanData> spanDataList) { // Start a new span with explicit 1/10000 sampling probability to avoid the case when user // sets the default sampler to always sample and we get the gRPC span of the zipkin // export call always sampled and go to an infinite loop. Scope scope = tracer.spanBuilder("SendZipkinSpans").setSampler(probabilitySampler).startScopedSpan(); try { List<byte[]> encodedSpans = new ArrayList<byte[]>(spanDataList.size()); for (SpanData spanData : spanDataList) { encodedSpans.add(encoder.encode(generateSpan(spanData, localEndpoint))); } try { sender.sendSpans(encodedSpans).execute(); } catch (IOException e) { tracer .getCurrentSpan() .setStatus( Status.UNKNOWN.withDescription( e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage())); throw new RuntimeException(e); // TODO: should we instead do drop metrics? } } finally { scope.close(); } } }
void tick() { try (Scope ss = tracer.spanBuilder("Styx.TriggerManager.tick") .setRecordEvents(true) .setSampler(Samplers.alwaysSample()) .startScopedSpan()) { tick0(); } }
void tick() { try (Scope ss = tracer.spanBuilder("Styx.Scheduler.tick") .setRecordEvents(true) .setSampler(Samplers.alwaysSample()) .startScopedSpan()) { tick0(); } }
void tick() { try (Scope ss = tracer.spanBuilder("Styx.BackfillTriggerManager.tick") .setRecordEvents(true) .setSampler(Samplers.alwaysSample()) .startScopedSpan()) { tick0(); } }
private static void updateRuntimeConfig(Supplier<StyxConfig> config, RateLimiter rateLimiter) { try (Scope ss = tracer.spanBuilder("Styx.StyxScheduler.updateRuntimeConfig") .setRecordEvents(true) .setSampler(Samplers.alwaysSample()) .startScopedSpan()) { updateRuntimeConfig0(config, rateLimiter); } }
void tick() { try (Scope ss = tracer.spanBuilder("Styx.Cleaner.tick") .setRecordEvents(true) .setSampler(Samplers.alwaysSample()) .startScopedSpan()) { tick0(); } }
@Override public void export(Collection<SpanData> spanDataList) { // Start a new span with explicit 1/10000 sampling probability to avoid the case when user // sets the default sampler to always sample and we get the gRPC span of the stackdriver // export call always sampled and go to an infinite loop. io.opencensus.trace.Span span = tracer .spanBuilder(EXPORT_STACKDRIVER_TRACES) .setSampler(probabilitySampler) .setRecordEvents(true) .startSpan(); Scope scope = tracer.withSpan(span); try { List<Span> spans = new ArrayList<>(spanDataList.size()); for (SpanData spanData : spanDataList) { spans.add(generateSpan(spanData, RESOURCE_LABELS, fixedAttributes)); } // Sync call because it is already called for a batch of data, and on a separate thread. // TODO(bdrutu): Consider to make this async in the future. traceServiceClient.batchWriteSpans(projectName, spans); } finally { scope.close(); span.end(END_SPAN_OPTIONS); } } }
@Override public void export(Collection<SpanData> spanDataList) { // Start a new span with explicit 1/10000 sampling probability to avoid the case when user // sets the default sampler to always sample and we get the gRPC span of the stackdriver // export call always sampled and go to an infinite loop. io.opencensus.trace.Span span = tracer .spanBuilder(EXPORT_STACKDRIVER_TRACES) .setSampler(probabilitySampler) .setRecordEvents(true) .startSpan(); Scope scope = tracer.withSpan(span); try { List<Span> spans = new ArrayList<>(spanDataList.size()); for (SpanData spanData : spanDataList) { spans.add(generateSpan(spanData, RESOURCE_LABELS, fixedAttributes)); } // Sync call because it is already called for a batch of data, and on a separate thread. // TODO(bdrutu): Consider to make this async in the future. traceServiceClient.batchWriteSpans(projectName, spans); } finally { scope.close(); span.end(END_SPAN_OPTIONS); } } }
@MustBeClosed @Override public Closeable startScopedSpan(String spanName) { checkNotNull(spanName, "spanName"); return Tracing.getTracer() .spanBuilder(spanName) .setSampler(Samplers.alwaysSample()) .setRecordEvents(true) .startScopedSpan(); }
/** * Reads the metrics from the {@link MetricProducerManager} and exports them to the {@code * metricExporter}. * * @param metricExporter the exporter called to export the metrics read. * @since 0.19 */ public void readAndExport(MetricExporter metricExporter) { Span span = tracer .spanBuilder(spanName) .setRecordEvents(true) .setSampler(probabilitySampler) .startSpan(); Scope scope = tracer.withSpan(span); try { ArrayList<Metric> metricsList = new ArrayList<>(); for (MetricProducer metricProducer : metricProducerManager.getAllMetricProducer()) { metricsList.addAll(metricProducer.getMetrics()); } metricExporter.export(metricsList); } catch (Throwable e) { logger.log(Level.WARNING, "Exception thrown by the metrics exporter.", e); span.setStatus( Status.UNKNOWN.withDescription("Exception when export metrics: " + exceptionMessage(e))); } finally { scope.close(); span.end(); } }
/** * Reads the metrics from the {@link MetricProducerManager} and exports them to the {@code * metricExporter}. * * @param metricExporter the exporter called to export the metrics read. * @since 0.19 */ public void readAndExport(MetricExporter metricExporter) { Span span = tracer .spanBuilder(spanName) .setRecordEvents(true) .setSampler(probabilitySampler) .startSpan(); Scope scope = tracer.withSpan(span); try { ArrayList<Metric> metricsList = new ArrayList<>(); for (MetricProducer metricProducer : metricProducerManager.getAllMetricProducer()) { metricsList.addAll(metricProducer.getMetrics()); } metricExporter.export(metricsList); } catch (Throwable e) { logger.log(Level.WARNING, "Exception thrown by the metrics exporter.", e); span.setStatus( Status.UNKNOWN.withDescription("Exception when export metrics: " + exceptionMessage(e))); } finally { scope.close(); span.end(); } }
@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); } }
tracer.spanBuilder(SPAN_NAME).setRecordEvents(true).setSampler(Samplers.alwaysSample()); int spanDurationInMillis = new Random().nextInt(10) + 1;