• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
18 
19 import com.google.auto.value.AutoValue;
20 import io.opencensus.common.ExperimentalApi;
21 import java.util.Collection;
22 import javax.annotation.Nullable;
23 import javax.annotation.concurrent.Immutable;
24 
25 /**
26  * A class that enables overriding the default values used when ending a {@link Span}. Allows
27  * overriding the {@link Status status}.
28  *
29  * @since 0.5
30  */
31 @Immutable
32 @AutoValue
33 public abstract class EndSpanOptions {
34   /**
35    * The default {@code EndSpanOptions}.
36    *
37    * @since 0.5
38    */
39   public static final EndSpanOptions DEFAULT = builder().build();
40 
41   /**
42    * Returns a new {@link Builder} with default options.
43    *
44    * @return a new {@code Builder} with default options.
45    * @since 0.5
46    */
builder()47   public static Builder builder() {
48     return new AutoValue_EndSpanOptions.Builder().setSampleToLocalSpanStore(false);
49   }
50 
51   /**
52    * If {@code true} this is equivalent with calling the {@link
53    * io.opencensus.trace.export.SampledSpanStore#registerSpanNamesForCollection(Collection)} in
54    * advance for this span name.
55    *
56    * <p>It is strongly recommended to use the {@link
57    * io.opencensus.trace.export.SampledSpanStore#registerSpanNamesForCollection(Collection)} API
58    * instead.
59    *
60    * @return {@code true} if the name of the {@code Span} should be registered to the {@code
61    *     io.opencensus.trace.export.SampledSpanStore}.
62    * @since 0.8
63    */
64   @ExperimentalApi
getSampleToLocalSpanStore()65   public abstract boolean getSampleToLocalSpanStore();
66 
67   /**
68    * Returns the status.
69    *
70    * <p>If {@code null} then the {@link Span} will record the {@link Status} set via {@link
71    * Span#setStatus(Status)} or the default {@link Status#OK} if no status was set.
72    *
73    * @return the status.
74    * @since 0.5
75    */
76   @Nullable
getStatus()77   public abstract Status getStatus();
78 
79   /**
80    * Builder class for {@link EndSpanOptions}.
81    *
82    * @since 0.5
83    */
84   @AutoValue.Builder
85   public abstract static class Builder {
86     /**
87      * Sets the status for the {@link Span}.
88      *
89      * <p>If set, this will override the status set via {@link Span#setStatus(Status)}.
90      *
91      * @param status the status.
92      * @return this.
93      * @since 0.5
94      */
setStatus(Status status)95     public abstract Builder setStatus(Status status);
96 
97     /**
98      * If set to {@code true} this is equivalent with calling the {@link
99      * io.opencensus.trace.export.SampledSpanStore#registerSpanNamesForCollection(Collection)} in
100      * advance for the given span name.
101      *
102      * <p>WARNING: setting this option to a randomly generated span name can OOM your process
103      * because the library will save samples for each name.
104      *
105      * <p>It is strongly recommended to use the {@link
106      * io.opencensus.trace.export.SampledSpanStore#registerSpanNamesForCollection(Collection)} API
107      * instead.
108      *
109      * @return this.
110      * @since 0.8
111      */
112     @ExperimentalApi
setSampleToLocalSpanStore(boolean sampleToLocalSpanStore)113     public abstract Builder setSampleToLocalSpanStore(boolean sampleToLocalSpanStore);
114 
115     /**
116      * Builds and returns a {@code EndSpanOptions} with the desired settings.
117      *
118      * @return a {@code EndSpanOptions} with the desired settings.
119      * @since 0.5
120      */
build()121     public abstract EndSpanOptions build();
122 
Builder()123     Builder() {}
124   }
125 
EndSpanOptions()126   EndSpanOptions() {}
127 }
128