1 /* 2 * Copyright 2019, 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.metrics.data; 18 19 import com.google.auto.value.AutoValue; 20 import javax.annotation.concurrent.Immutable; 21 22 /** 23 * The value of {@link Exemplar} attachment. 24 * 25 * <p>In Stats API we only provide one subclass {@link AttachmentValueString}. No other subclasses 26 * are added because we don't want to introduce dependencies on other libraries, for example Tracing 27 * APIs. 28 * 29 * <p>Other packages are free to extend this class to hold specific information. As an example, see 30 * {@code io.opencensus.contrib.exemplar.util.AttachmentValueSpanContext}. 31 * 32 * @since 0.20 33 */ 34 public abstract class AttachmentValue { 35 36 /** 37 * Returns the string attachment value. 38 * 39 * @return the string attachment value. 40 * @since 0.20 41 */ getValue()42 public abstract String getValue(); 43 44 /** 45 * String {@link AttachmentValue}. 46 * 47 * @since 0.20 48 */ 49 @AutoValue 50 @Immutable 51 public abstract static class AttachmentValueString extends AttachmentValue { 52 AttachmentValueString()53 AttachmentValueString() {} 54 55 /** 56 * Creates an {@link AttachmentValueString}. 57 * 58 * @param value the string value. 59 * @return an {@code AttachmentValueString}. 60 * @since 0.20 61 */ create(String value)62 public static AttachmentValueString create(String value) { 63 return new AutoValue_AttachmentValue_AttachmentValueString(value); 64 } 65 } 66 } 67