Home | History | Annotate | Download | only in export
      1 /*
      2  * Copyright 2017, OpenCensus Authors
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package io.opencensus.trace.export;
     18 
     19 import io.opencensus.trace.TraceOptions;
     20 
     21 /**
     22  * Class that holds the implementation instances for {@link SpanExporter}, {@link RunningSpanStore}
     23  * and {@link SampledSpanStore}.
     24  *
     25  * <p>Unless otherwise noted all methods (on component) results are cacheable.
     26  *
     27  * @since 0.5
     28  */
     29 public abstract class ExportComponent {
     30 
     31   /**
     32    * Returns the no-op implementation of the {@code ExportComponent}.
     33    *
     34    * @return the no-op implementation of the {@code ExportComponent}.
     35    * @since 0.5
     36    */
     37   public static ExportComponent newNoopExportComponent() {
     38     return new NoopExportComponent();
     39   }
     40 
     41   /**
     42    * Returns the {@link SpanExporter} which can be used to register handlers to export all the spans
     43    * that are part of a distributed sampled trace (see {@link TraceOptions#isSampled()}).
     44    *
     45    * @return the implementation of the {@code SpanExporter} or no-op if no implementation linked in
     46    *     the binary.
     47    * @since 0.5
     48    */
     49   public abstract SpanExporter getSpanExporter();
     50 
     51   /**
     52    * Returns the {@link RunningSpanStore} that can be used to get useful debugging information about
     53    * all the current active spans.
     54    *
     55    * @return the {@code RunningSpanStore}.
     56    * @since 0.5
     57    */
     58   public abstract RunningSpanStore getRunningSpanStore();
     59 
     60   /**
     61    * Returns the {@link SampledSpanStore} that can be used to get useful debugging information, such
     62    * as latency based sampled spans, error based sampled spans.
     63    *
     64    * @return the {@code SampledSpanStore}.
     65    * @since 0.5
     66    */
     67   public abstract SampledSpanStore getSampledSpanStore();
     68 
     69   /**
     70    * Will shutdown this ExportComponent after flushing any pending spans.
     71    *
     72    * @since 0.14
     73    */
     74   public void shutdown() {}
     75 
     76   private static final class NoopExportComponent extends ExportComponent {
     77     private final SampledSpanStore noopSampledSpanStore =
     78         SampledSpanStore.newNoopSampledSpanStore();
     79 
     80     @Override
     81     public SpanExporter getSpanExporter() {
     82       return SpanExporter.getNoopSpanExporter();
     83     }
     84 
     85     @Override
     86     public RunningSpanStore getRunningSpanStore() {
     87       return RunningSpanStore.getNoopRunningSpanStore();
     88     }
     89 
     90     @Override
     91     public SampledSpanStore getSampledSpanStore() {
     92       return noopSampledSpanStore;
     93     }
     94   }
     95 }
     96