Skip to content

Commit c9bd266

Browse files
zeitlingertrask
andauthored
Align SemconvStability with newer declarative config (#18908)
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com> Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
1 parent b156312 commit c9bd266

5 files changed

Lines changed: 994 additions & 57 deletions

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.api.internal;
7+
8+
import static java.util.Arrays.asList;
9+
10+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
11+
import java.util.HashSet;
12+
import java.util.Set;
13+
import javax.annotation.Nullable;
14+
15+
class SemconvDomain {
16+
private final String configName;
17+
private final String flagKey;
18+
private final boolean hasStructuredConfig;
19+
private final SemconvMode defaultMode;
20+
private final Set<SemconvMode> supportedModes;
21+
22+
static Builder builder(String configName) {
23+
return new Builder(configName);
24+
}
25+
26+
private SemconvDomain(
27+
String configName,
28+
String flagKey,
29+
boolean hasStructuredConfig,
30+
SemconvMode defaultMode,
31+
Set<SemconvMode> supportedModes) {
32+
this.configName = configName;
33+
this.flagKey = flagKey;
34+
this.hasStructuredConfig = hasStructuredConfig;
35+
this.defaultMode = defaultMode;
36+
this.supportedModes = new HashSet<>(supportedModes);
37+
}
38+
39+
String configName() {
40+
return configName;
41+
}
42+
43+
String flagKey() {
44+
return flagKey;
45+
}
46+
47+
boolean hasStructuredConfig() {
48+
return hasStructuredConfig;
49+
}
50+
51+
SemconvMode defaultMode() {
52+
return defaultMode;
53+
}
54+
55+
Set<SemconvMode> supportedModes() {
56+
return supportedModes;
57+
}
58+
59+
static class Builder {
60+
private final String configName;
61+
private String flagKey;
62+
private boolean hasStructuredConfig = true;
63+
@Nullable private SemconvMode defaultMode;
64+
private final Set<SemconvMode> supportedModes = new HashSet<>();
65+
66+
private Builder(String configName) {
67+
this.configName = configName;
68+
this.flagKey = configName;
69+
}
70+
71+
@CanIgnoreReturnValue
72+
Builder flagKey(String flagKey) {
73+
this.flagKey = flagKey;
74+
return this;
75+
}
76+
77+
@CanIgnoreReturnValue
78+
Builder withoutStructuredConfig() {
79+
hasStructuredConfig = false;
80+
return this;
81+
}
82+
83+
@CanIgnoreReturnValue
84+
Builder defaultMode(SemconvMode defaultMode) {
85+
this.defaultMode = defaultMode;
86+
supportedModes.add(defaultMode);
87+
return this;
88+
}
89+
90+
@CanIgnoreReturnValue
91+
Builder otherSupportedModes(SemconvMode... modes) {
92+
supportedModes.addAll(asList(modes));
93+
return this;
94+
}
95+
96+
SemconvDomain build() {
97+
if (defaultMode == null) {
98+
throw new IllegalStateException("defaultMode is required");
99+
}
100+
return new SemconvDomain(
101+
configName, flagKey, hasStructuredConfig, defaultMode, supportedModes);
102+
}
103+
}
104+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.api.internal;
7+
8+
import java.util.Objects;
9+
10+
final class SemconvMode {
11+
static final SemconvMode V0_STABLE = new SemconvMode(0, false, false);
12+
static final SemconvMode V1_STABLE = new SemconvMode(1, false, false);
13+
static final SemconvMode V1_EXPERIMENTAL = new SemconvMode(1, true, false);
14+
15+
private final int version;
16+
private final boolean experimental;
17+
private final boolean dualEmit;
18+
19+
private SemconvMode(int version, boolean experimental, boolean dualEmit) {
20+
this.version = version;
21+
this.experimental = experimental;
22+
this.dualEmit = dualEmit;
23+
}
24+
25+
int version() {
26+
return version;
27+
}
28+
29+
boolean experimental() {
30+
return experimental;
31+
}
32+
33+
boolean dualEmit() {
34+
return dualEmit;
35+
}
36+
37+
SemconvMode withDualEmit() {
38+
return new SemconvMode(version, experimental, true);
39+
}
40+
41+
SemconvMode withoutDualEmit() {
42+
return new SemconvMode(version, experimental, false);
43+
}
44+
45+
SemconvMode stable() {
46+
return new SemconvMode(version, false, false);
47+
}
48+
49+
@Override
50+
public boolean equals(Object obj) {
51+
if (!(obj instanceof SemconvMode)) {
52+
return false;
53+
}
54+
SemconvMode other = (SemconvMode) obj;
55+
return version == other.version
56+
&& experimental == other.experimental
57+
&& dualEmit == other.dualEmit;
58+
}
59+
60+
@Override
61+
public int hashCode() {
62+
return Objects.hash(version, experimental, dualEmit);
63+
}
64+
}

0 commit comments

Comments
 (0)