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 * @return {@code true} if the name of the {@code Span} should be registered to the {@code 57 * io.opencensus.trace.export.SampledSpanStore}. 58 * @since 0.8 59 */ 60 @ExperimentalApi getSampleToLocalSpanStore()61 public abstract boolean getSampleToLocalSpanStore(); 62 63 /** 64 * Returns the status. 65 * 66 * <p>If {@code null} then the {@link Span} will record the {@link Status} set via {@link 67 * Span#setStatus(Status)} or the default {@link Status#OK} if no status was set. 68 * 69 * @return the status. 70 * @since 0.5 71 */ 72 @Nullable getStatus()73 public abstract Status getStatus(); 74 75 /** 76 * Builder class for {@link EndSpanOptions}. 77 * 78 * @since 0.5 79 */ 80 @AutoValue.Builder 81 public abstract static class Builder { 82 /** 83 * Sets the status for the {@link Span}. 84 * 85 * <p>If set, this will override the status set via {@link Span#setStatus(Status)}. 86 * 87 * @param status the status. 88 * @return this. 89 * @since 0.5 90 */ setStatus(Status status)91 public abstract Builder setStatus(Status status); 92 93 /** 94 * If set to {@code true} this is equivalent with calling the {@link 95 * io.opencensus.trace.export.SampledSpanStore#registerSpanNamesForCollection(Collection)} in 96 * advance for the given span name. 97 * 98 * <p>WARNING: setting this option to a randomly generated span name can OOM your process 99 * because the library will save samples for each name. 100 * 101 * <p>It is strongly recommended to use the {@link 102 * io.opencensus.trace.export.SampledSpanStore#registerSpanNamesForCollection(Collection)} API 103 * instead. 104 * 105 * @return this. 106 * @since 0.8 107 */ 108 @ExperimentalApi setSampleToLocalSpanStore(boolean sampleToLocalSpanStore)109 public abstract Builder setSampleToLocalSpanStore(boolean sampleToLocalSpanStore); 110 111 /** 112 * Builds and returns a {@code EndSpanOptions} with the desired settings. 113 * 114 * @return a {@code EndSpanOptions} with the desired settings. 115 * @since 0.5 116 */ build()117 public abstract EndSpanOptions build(); 118 Builder()119 Builder() {} 120 } 121 EndSpanOptions()122 EndSpanOptions() {} 123 } 124