static void exportSpans(String... spans) { SampledSpanStore store = Tracing.getExportComponent().getSampledSpanStore(); if (store != null) { store.registerSpanNamesForCollection(Arrays.asList(spans)); } } }
/** * Unregisters the Stackdriver Trace exporter from the OpenCensus library. * * @throws IllegalStateException if a Stackdriver exporter is not registered. * @since 0.12 */ public static void unregister() { synchronized (monitor) { checkState(handler != null, "Stackdriver exporter is not registered."); unregister(Tracing.getExportComponent().getSpanExporter()); handler = null; } }
@Test public void noopSampledSpanStore_GetRegisteredSpanNamesForCollection() { SampledSpanStore sampledSpanStore = ExportComponent.newNoopExportComponent().getSampledSpanStore(); sampledSpanStore.registerSpanNamesForCollection( Collections.unmodifiableList(Lists.newArrayList("TestSpan3", "TestSpan4"))); Set<String> registeredSpanNames = sampledSpanStore.getRegisteredSpanNamesForCollection(); assertThat(registeredSpanNames).containsExactly("TestSpan3", "TestSpan4"); } }
@Test public void implementationOfActiveSpans() { assertThat(exportComponentWithInProcess.getRunningSpanStore()) .isInstanceOf(InProcessRunningSpanStoreImpl.class); assertThat(exportComponentWithoutInProcess.getRunningSpanStore()) .isInstanceOf(RunningSpanStoreImpl.getNoopRunningSpanStoreImpl().getClass()); }
Tracing.getExportComponent().shutdown(); JaegerTraceExporter.unregister();
/** * Unregisters the Zipkin Trace exporter from the OpenCensus library. * * @throws IllegalStateException if a Zipkin exporter is not registered. * @since 0.12 */ public static void unregister() { synchronized (monitor) { checkState(handler != null, "Zipkin exporter is not registered."); unregister(Tracing.getExportComponent().getSpanExporter()); handler = null; } }
@Test public void noopSampledSpanStore_GetLatencySampledSpans() { SampledSpanStore sampledSpanStore = ExportComponent.newNoopExportComponent().getSampledSpanStore(); Collection<SpanData> latencySampledSpans = sampledSpanStore.getLatencySampledSpans( SampledSpanStore.LatencyFilter.create("TestLatencyFilter", 0, 0, 0)); assertThat(latencySampledSpans).isEmpty(); }
@Test public void implementationOfActiveSpans() { assertThat(exportComponent.getRunningSpanStore()) .isEqualTo(RunningSpanStore.getNoopRunningSpanStore()); }
@Test public void testOpencensusJaeger() { // 1. configure the jaeger exporter JaegerTraceExporter.createAndRegister(JAEGER_COLLECTOR, "my-service"); // 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()); // 3. Get the global singleton Tracer object. Tracer tracer = Tracing.getTracer(); // 4. Create a scoped span, a scoped span will automatically end when closed. // It implements AutoClosable, so it'll be closed when the try block ends. try (Scope scope = tracer.spanBuilder("query").startScopedSpan()) { runTransactions(); } // 5. Gracefully shutdown the exporter, so that it'll flush queued traces to Jaeger. Tracing.getExportComponent().shutdown(); }
/** * Unregisters the {@link JaegerTraceExporter} from the OpenCensus library. * * @throws IllegalStateException if a Jaeger exporter is not registered. * @since 0.13 */ public static void unregister() { synchronized (monitor) { checkState(handler != null, "Jaeger exporter is not registered."); unregister(Tracing.getExportComponent().getSpanExporter()); handler = null; } }
static void registerAllSpanNamesForCollection() { Tracing.getExportComponent() .getSampledSpanStore() .registerSpanNamesForCollection(ALL_SPAN_NAMES); }
@Test public void noopSampledSpanStore_GetErrorSampledSpans() { SampledSpanStore sampledSpanStore = ExportComponent.newNoopExportComponent().getSampledSpanStore(); Collection<SpanData> errorSampledSpans = sampledSpanStore.getErrorSampledSpans( SampledSpanStore.ErrorFilter.create("TestErrorFilter", null, 0)); assertThat(errorSampledSpans).isEmpty(); }
/** * Unregisters the Stackdriver Trace exporter from the OpenCensus library. * * @throws IllegalStateException if a Stackdriver exporter is not registered. * @since 0.12 */ public static void unregister() { synchronized (monitor) { checkState(handler != null, "Stackdriver exporter is not registered."); unregister(Tracing.getExportComponent().getSpanExporter()); handler = null; } }
Tracing.getExportComponent().getSampledSpanStore().registerSpanNamesForCollection( Arrays.asList(SAMPLE_SPAN));
@Test public void noopSampledSpanStore_RegisterUnregisterAndGetSummary() { // should return empty before register SampledSpanStore sampledSpanStore = ExportComponent.newNoopExportComponent().getSampledSpanStore(); SampledSpanStore.Summary summary = sampledSpanStore.getSummary(); assertThat(summary.getPerSpanNameSummary()).isEmpty(); // should return non-empty summaries with zero latency/error sampled spans after register sampledSpanStore.registerSpanNamesForCollection( Collections.unmodifiableList(Lists.newArrayList("TestSpan1", "TestSpan2", "TestSpan3"))); summary = sampledSpanStore.getSummary(); assertThat(summary.getPerSpanNameSummary()) .containsExactly( "TestSpan1", EMPTY_PER_SPAN_NAME_SUMMARY, "TestSpan2", EMPTY_PER_SPAN_NAME_SUMMARY, "TestSpan3", EMPTY_PER_SPAN_NAME_SUMMARY); // should unregister specific spanNames sampledSpanStore.unregisterSpanNamesForCollection( Collections.unmodifiableList(Lists.newArrayList("TestSpan1", "TestSpan3"))); summary = sampledSpanStore.getSummary(); assertThat(summary.getPerSpanNameSummary()) .containsExactly("TestSpan2", EMPTY_PER_SPAN_NAME_SUMMARY); }
/** * Unregisters the Instana Trace exporter from the OpenCensus library. * * @throws IllegalStateException if a Instana exporter is not registered. * @since 0.12 */ public static void unregister() { synchronized (monitor) { checkState(handler != null, "Instana exporter is not registered."); unregister(Tracing.getExportComponent().getSpanExporter()); handler = null; } }
static void exportSpans(String... spans) { SampledSpanStore store = Tracing.getExportComponent().getSampledSpanStore(); if (store != null) { store.registerSpanNamesForCollection(Arrays.asList(spans)); } } }
/** * Unregisters the Datadog Trace exporter from the OpenCensus library. * * @throws IllegalStateException if a Datadog exporter is not registered. * @since 0.19 */ public static void unregister() { synchronized (monitor) { checkState(handler != null, "Datadog exporter is not registered."); Tracing.getExportComponent().getSpanExporter().unregisterHandler(REGISTER_NAME); handler = null; } } }
static void registerAllSpanNamesForCollection() { Tracing.getExportComponent() .getSampledSpanStore() .registerSpanNamesForCollection(ALL_SPAN_NAMES); }
/** * Registers the Logging exporter to the OpenCensus library. * * @since 0.12 */ public static void register() { register(Tracing.getExportComponent().getSpanExporter()); }