|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.instrumentation.docs.internal; |
| 7 | + |
| 8 | +import static java.util.Collections.emptyList; |
| 9 | + |
| 10 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 11 | +import com.google.errorprone.annotations.CanIgnoreReturnValue; |
| 12 | +import java.util.List; |
| 13 | +import java.util.Objects; |
| 14 | +import javax.annotation.Nonnull; |
| 15 | +import javax.annotation.Nullable; |
| 16 | + |
| 17 | +/** |
| 18 | + * Represents the data in a metadata.yaml file. This class is internal and is hence not for public |
| 19 | + * use. Its APIs are unstable and can change at any time. |
| 20 | + */ |
| 21 | +public class InstrumentationMetadata { |
| 22 | + @Nullable private String description; |
| 23 | + |
| 24 | + @JsonProperty("disabled_by_default") |
| 25 | + @Nullable |
| 26 | + private Boolean disabledByDefault; |
| 27 | + |
| 28 | + private String classification; |
| 29 | + |
| 30 | + @JsonProperty("library_link") |
| 31 | + @Nullable |
| 32 | + private String libraryLink; |
| 33 | + |
| 34 | + @JsonProperty("display_name") |
| 35 | + @Nullable |
| 36 | + private String displayName; |
| 37 | + |
| 38 | + private List<ConfigurationOption> configurations = emptyList(); |
| 39 | + |
| 40 | + public InstrumentationMetadata() { |
| 41 | + this.classification = InstrumentationClassification.LIBRARY.name(); |
| 42 | + } |
| 43 | + |
| 44 | + public InstrumentationMetadata( |
| 45 | + @Nullable String description, |
| 46 | + @Nullable Boolean disabledByDefault, |
| 47 | + String classification, |
| 48 | + @Nullable String libraryLink, |
| 49 | + @Nullable String displayName, |
| 50 | + @Nullable List<ConfigurationOption> configurations) { |
| 51 | + this.classification = classification; |
| 52 | + this.disabledByDefault = disabledByDefault; |
| 53 | + this.description = description; |
| 54 | + this.libraryLink = libraryLink; |
| 55 | + this.displayName = displayName; |
| 56 | + this.configurations = Objects.requireNonNullElse(configurations, emptyList()); |
| 57 | + } |
| 58 | + |
| 59 | + @Nullable |
| 60 | + public String getDescription() { |
| 61 | + return description; |
| 62 | + } |
| 63 | + |
| 64 | + public void setDisplayName(@Nullable String displayName) { |
| 65 | + this.displayName = displayName; |
| 66 | + } |
| 67 | + |
| 68 | + @Nullable |
| 69 | + public String getDisplayName() { |
| 70 | + return displayName; |
| 71 | + } |
| 72 | + |
| 73 | + @Nonnull |
| 74 | + public InstrumentationClassification getClassification() { |
| 75 | + return Objects.requireNonNullElse( |
| 76 | + InstrumentationClassification.fromString(classification), |
| 77 | + InstrumentationClassification.LIBRARY); |
| 78 | + } |
| 79 | + |
| 80 | + public Boolean getDisabledByDefault() { |
| 81 | + return Objects.requireNonNullElse(disabledByDefault, false); |
| 82 | + } |
| 83 | + |
| 84 | + public void setDescription(@Nullable String description) { |
| 85 | + this.description = description; |
| 86 | + } |
| 87 | + |
| 88 | + public void setClassification(String classification) { |
| 89 | + this.classification = classification; |
| 90 | + } |
| 91 | + |
| 92 | + public void setDisabledByDefault(@Nullable Boolean disabledByDefault) { |
| 93 | + this.disabledByDefault = disabledByDefault; |
| 94 | + } |
| 95 | + |
| 96 | + public List<ConfigurationOption> getConfigurations() { |
| 97 | + return configurations; |
| 98 | + } |
| 99 | + |
| 100 | + public void setConfigurations(@Nullable List<ConfigurationOption> configurations) { |
| 101 | + this.configurations = Objects.requireNonNullElse(configurations, emptyList()); |
| 102 | + } |
| 103 | + |
| 104 | + @Nullable |
| 105 | + public String getLibraryLink() { |
| 106 | + return libraryLink; |
| 107 | + } |
| 108 | + |
| 109 | + public void setLibraryLink(@Nullable String libraryLink) { |
| 110 | + this.libraryLink = libraryLink; |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * This class is internal and is hence not for public use. Its APIs are unstable and can change at |
| 115 | + * any time. |
| 116 | + */ |
| 117 | + public static class Builder { |
| 118 | + |
| 119 | + @Nullable private String description; |
| 120 | + @Nullable private Boolean disabledByDefault; |
| 121 | + @Nullable private String classification; |
| 122 | + @Nullable private String libraryLink; |
| 123 | + @Nullable private String displayName; |
| 124 | + private List<ConfigurationOption> configurations = emptyList(); |
| 125 | + |
| 126 | + @CanIgnoreReturnValue |
| 127 | + public Builder description(@Nullable String description) { |
| 128 | + this.description = description; |
| 129 | + return this; |
| 130 | + } |
| 131 | + |
| 132 | + @CanIgnoreReturnValue |
| 133 | + public Builder disabledByDefault(@Nullable Boolean disabledByDefault) { |
| 134 | + this.disabledByDefault = disabledByDefault; |
| 135 | + return this; |
| 136 | + } |
| 137 | + |
| 138 | + @CanIgnoreReturnValue |
| 139 | + public Builder classification(@Nullable String classification) { |
| 140 | + this.classification = classification; |
| 141 | + return this; |
| 142 | + } |
| 143 | + |
| 144 | + @CanIgnoreReturnValue |
| 145 | + public Builder libraryLink(@Nullable String libraryLink) { |
| 146 | + this.libraryLink = libraryLink; |
| 147 | + return this; |
| 148 | + } |
| 149 | + |
| 150 | + @CanIgnoreReturnValue |
| 151 | + public Builder displayName(@Nullable String displayName) { |
| 152 | + this.displayName = displayName; |
| 153 | + return this; |
| 154 | + } |
| 155 | + |
| 156 | + @CanIgnoreReturnValue |
| 157 | + public Builder configurations(@Nullable List<ConfigurationOption> configurations) { |
| 158 | + this.configurations = Objects.requireNonNullElse(configurations, emptyList()); |
| 159 | + return this; |
| 160 | + } |
| 161 | + |
| 162 | + public InstrumentationMetadata build() { |
| 163 | + return new InstrumentationMetadata( |
| 164 | + description, |
| 165 | + disabledByDefault, |
| 166 | + classification != null ? classification : InstrumentationClassification.LIBRARY.name(), |
| 167 | + libraryLink, |
| 168 | + displayName, |
| 169 | + configurations); |
| 170 | + } |
| 171 | + } |
| 172 | +} |
0 commit comments