Skip to content

Commit 95128a3

Browse files
committed
initial
1 parent c10ebeb commit 95128a3

File tree

4 files changed

+82
-1
lines changed

4 files changed

+82
-1
lines changed

instrumentation-docs/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id("otel.java-conventions")
3-
id("otel.nullaway-conventions")
3+
// id("otel.nullaway-conventions")
44
}
55

66
otelJava {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 com.fasterxml.jackson.annotation.JsonCreator;
9+
import com.fasterxml.jackson.annotation.JsonValue;
10+
11+
/**
12+
* Represents functionality of instrumentations. This class is internal and is hence not for public
13+
* use. Its APIs are unstable and can change at any time.
14+
*/
15+
public enum InstrumentationFunction {
16+
HTTP_ROUTE_ENRICHER("http-route-enricher"),
17+
LIBRARY_DOMAIN_ENRICHER("library-domain-enricher"),
18+
EXPERIMENTAL_ONLY("experimental-only"),
19+
CONTEXT_PROPAGATOR("context-propagator"),
20+
UPSTREAM_ADAPTER("upstream-adapter"),
21+
CONFIGURATION("configuration"),
22+
CONTROLLER_SPANS("controller-spans"),
23+
VIEW_SPANS("view-spans"),
24+
SYSTEM_METRICS("system-metrics");
25+
26+
private final String yamlName;
27+
28+
InstrumentationFunction(String yamlName) {
29+
this.yamlName = yamlName;
30+
}
31+
32+
@JsonValue
33+
public String getYamlName() {
34+
return yamlName;
35+
}
36+
37+
@JsonCreator
38+
public static InstrumentationFunction fromYamlName(String yamlName) {
39+
for (InstrumentationFunction function : values()) {
40+
if (function.yamlName.equals(yamlName)) {
41+
return function;
42+
}
43+
}
44+
throw new IllegalArgumentException("Unknown instrumentation function: " + yamlName);
45+
}
46+
}

instrumentation-docs/src/main/java/io/opentelemetry/instrumentation/docs/internal/InstrumentationMetadata.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class InstrumentationMetadata {
4747
@Nullable
4848
private Boolean overrideTelemetry;
4949

50+
private List<InstrumentationFunction> functions = emptyList();
51+
5052
public InstrumentationMetadata() {
5153
this.classification = InstrumentationClassification.LIBRARY.name();
5254
}
@@ -147,6 +149,14 @@ public void setOverrideTelemetry(@Nullable Boolean overrideTelemetry) {
147149
this.overrideTelemetry = overrideTelemetry;
148150
}
149151

152+
public List<InstrumentationFunction> getFunctions() {
153+
return functions;
154+
}
155+
156+
public void setFunctions(@Nullable List<InstrumentationFunction> functions) {
157+
this.functions = Objects.requireNonNullElse(functions, emptyList());
158+
}
159+
150160
/**
151161
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
152162
* any time.
@@ -162,6 +172,7 @@ public static class Builder {
162172
private List<SemanticConvention> semanticConventions = emptyList();
163173
private List<ManualTelemetryEntry> additionalTelemetry = emptyList();
164174
@Nullable private Boolean overrideTelemetry;
175+
private List<InstrumentationFunction> functions = emptyList();
165176

166177
@CanIgnoreReturnValue
167178
public Builder description(@Nullable String description) {
@@ -217,6 +228,12 @@ public Builder overrideTelemetry(@Nullable Boolean overrideTelemetry) {
217228
return this;
218229
}
219230

231+
@CanIgnoreReturnValue
232+
public Builder functions(@Nullable List<InstrumentationFunction> functions) {
233+
this.functions = Objects.requireNonNullElse(functions, emptyList());
234+
return this;
235+
}
236+
220237
public InstrumentationMetadata build() {
221238
InstrumentationMetadata metadata =
222239
new InstrumentationMetadata(
@@ -231,6 +248,7 @@ public InstrumentationMetadata build() {
231248
configurations);
232249
metadata.setAdditionalTelemetry(additionalTelemetry);
233250
metadata.setOverrideTelemetry(overrideTelemetry);
251+
metadata.setFunctions(functions);
234252
return metadata;
235253
}
236254
}

instrumentation-docs/src/test/java/io/opentelemetry/instrumentation/docs/utils/YamlHelperTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.opentelemetry.instrumentation.docs.internal.EmittedMetrics;
1717
import io.opentelemetry.instrumentation.docs.internal.EmittedSpans;
1818
import io.opentelemetry.instrumentation.docs.internal.InstrumentationClassification;
19+
import io.opentelemetry.instrumentation.docs.internal.InstrumentationFunction;
1920
import io.opentelemetry.instrumentation.docs.internal.InstrumentationMetadata;
2021
import io.opentelemetry.instrumentation.docs.internal.InstrumentationModule;
2122
import io.opentelemetry.instrumentation.docs.internal.InstrumentationType;
@@ -315,6 +316,22 @@ void testMetadataParserWithOnlyConfigurations() throws JsonProcessingException {
315316
assertThat(config.type()).isEqualTo(ConfigurationType.BOOLEAN);
316317
}
317318

319+
@Test
320+
void testMetadataParserWithOnlyFunctions() throws JsonProcessingException {
321+
String input =
322+
"""
323+
functions:
324+
- http-route-enricher
325+
""";
326+
InstrumentationMetadata metadata = YamlHelper.metaDataParser(input);
327+
328+
assertThat(metadata.getClassification()).isEqualTo(InstrumentationClassification.LIBRARY);
329+
assertThat(metadata.getDescription()).isNull();
330+
assertThat(metadata.getDisabledByDefault()).isFalse();
331+
assertThat(metadata.getFunctions())
332+
.containsExactly(InstrumentationFunction.HTTP_ROUTE_ENRICHER);
333+
}
334+
318335
@Test
319336
void testMetricsParsing() throws Exception {
320337
List<InstrumentationModule> modules = new ArrayList<>();

0 commit comments

Comments
 (0)