aboutsummaryrefslogtreecommitdiff
path: root/impl_core/src/main/java/io/opencensus/implcore/trace/export/SampledSpanStoreImpl.java
blob: 0c83a05ac0d75c8e38ca9d8cd9a7af26454660ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * Copyright 2018, OpenCensus Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.opencensus.implcore.trace.export;

import io.opencensus.implcore.trace.SpanImpl;
import io.opencensus.trace.export.SampledSpanStore;
import io.opencensus.trace.export.SampledSpanStore.ErrorFilter;
import io.opencensus.trace.export.SampledSpanStore.LatencyFilter;
import io.opencensus.trace.export.SampledSpanStore.PerSpanNameSummary;
import io.opencensus.trace.export.SampledSpanStore.Summary;
import io.opencensus.trace.export.SpanData;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;

/** Abstract implementation of the {@link SampledSpanStore}. */
public abstract class SampledSpanStoreImpl extends SampledSpanStore {
  private static final SampledSpanStoreImpl NOOP_SAMPLED_SPAN_STORE_IMPL =
      new NoopSampledSpanStoreImpl();

  /** Returns the new no-op implmentation of {@link SampledSpanStoreImpl}. */
  public static SampledSpanStoreImpl getNoopSampledSpanStoreImpl() {
    return NOOP_SAMPLED_SPAN_STORE_IMPL;
  }

  /**
   * Considers to save the given spans to the stored samples. This must be called at the end of each
   * Span with the option RECORD_EVENTS.
   *
   * @param span the span to be consider for storing into the store buckets.
   */
  public abstract void considerForSampling(SpanImpl span);

  private static final class NoopSampledSpanStoreImpl extends SampledSpanStoreImpl {
    private static final Summary EMPTY_SUMMARY =
        Summary.create(Collections.<String, PerSpanNameSummary>emptyMap());
    private static final Set<String> EMPTY_REGISTERED_SPAN_NAMES = Collections.<String>emptySet();
    private static final Collection<SpanData> EMPTY_SPANDATA = Collections.<SpanData>emptySet();

    @Override
    public Summary getSummary() {
      return EMPTY_SUMMARY;
    }

    @Override
    public void considerForSampling(SpanImpl span) {}

    @Override
    public void registerSpanNamesForCollection(Collection<String> spanNames) {}

    @Override
    public void unregisterSpanNamesForCollection(Collection<String> spanNames) {}

    @Override
    public Set<String> getRegisteredSpanNamesForCollection() {
      return EMPTY_REGISTERED_SPAN_NAMES;
    }

    @Override
    public Collection<SpanData> getErrorSampledSpans(ErrorFilter filter) {
      return EMPTY_SPANDATA;
    }

    @Override
    public Collection<SpanData> getLatencySampledSpans(LatencyFilter filter) {
      return EMPTY_SPANDATA;
    }
  }
}