Skip to content

Commit 00b0e9f

Browse files
authored
Declarative configuration missing pieces (#6677)
1 parent 61a4b46 commit 00b0e9f

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,29 @@
55

66
package io.opentelemetry.sdk.autoconfigure.spi.internal;
77

8+
import io.opentelemetry.context.propagation.TextMapPropagator;
9+
import io.opentelemetry.sdk.logs.LogRecordProcessor;
810
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
911
import io.opentelemetry.sdk.metrics.export.MetricExporter;
12+
import io.opentelemetry.sdk.resources.Resource;
13+
import io.opentelemetry.sdk.trace.SpanProcessor;
1014
import io.opentelemetry.sdk.trace.export.SpanExporter;
15+
import io.opentelemetry.sdk.trace.samplers.Sampler;
1116

1217
/**
1318
* Provides configured instances of SDK extension components. {@link ComponentProvider} allows SDK
1419
* extension components which are not part of the core SDK to be referenced in file based
1520
* configuration.
1621
*
22+
* <p>NOTE: when {@link #getType()} is {@link Resource}, the {@link #getName()} is not (currently)
23+
* used, and {@link #create(StructuredConfigProperties)} is (currently) called with an empty {@link
24+
* StructuredConfigProperties}.
25+
*
1726
* @param <T> the type of the SDK extension component. See {@link #getType()}. Supported values
18-
* include: {@link SpanExporter}, {@link MetricExporter}, {@link LogRecordExporter}.
27+
* include: {@link SpanExporter}, {@link MetricExporter}, {@link LogRecordExporter}, {@link
28+
* SpanProcessor}, {@link LogRecordProcessor}, {@link TextMapPropagator}, {@link Sampler},
29+
* {@link Resource}.
1930
*/
20-
// TODO: add support for Sampler, LogRecordProcessor, SpanProcessor, MetricReader
2131
public interface ComponentProvider<T> {
2232

2333
/**
@@ -31,7 +41,8 @@ public interface ComponentProvider<T> {
3141
* instances of a custom span exporter for the "acme" protocol, the name might be "acme".
3242
*
3343
* <p>This name MUST not be the same as any other component provider name which returns components
34-
* of the same {@link #getType() type}.
44+
* of the same {@link #getType() type}. In other words, {@link #getType()} and name form a
45+
* composite key uniquely identifying the provider.
3546
*/
3647
String getName();
3748

sdk-extensions/incubator/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies {
2626

2727
// io.opentelemetry.sdk.extension.incubator.fileconfig
2828
implementation("com.fasterxml.jackson.core:jackson-databind")
29+
api("com.fasterxml.jackson.core:jackson-annotations")
2930
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
3031
implementation(project(":sdk-extensions:autoconfigure"))
3132

sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/FileConfiguration.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ static Object loadYaml(InputStream inputStream, Map<String, String> environmentV
123123
}
124124

125125
/**
126-
* Convert the {@code model} to a generic {@link StructuredConfigProperties}, which can be used to
127-
* read configuration not part of the model.
126+
* Convert the {@code model} to a generic {@link StructuredConfigProperties}.
128127
*
129128
* @param model the configuration model
130129
* @return a generic {@link StructuredConfigProperties} representation of the model
@@ -133,6 +132,17 @@ public static StructuredConfigProperties toConfigProperties(OpenTelemetryConfigu
133132
return toConfigProperties((Object) model);
134133
}
135134

135+
/**
136+
* Convert the {@code configuration} YAML to a generic {@link StructuredConfigProperties}.
137+
*
138+
* @param configuration configuration YAML
139+
* @return a generic {@link StructuredConfigProperties} representation of the model
140+
*/
141+
public static StructuredConfigProperties toConfigProperties(InputStream configuration) {
142+
Object yamlObj = loadYaml(configuration, System.getenv());
143+
return toConfigProperties(yamlObj);
144+
}
145+
136146
static StructuredConfigProperties toConfigProperties(Object model) {
137147
Map<String, Object> configurationMap =
138148
MAPPER.convertValue(model, new TypeReference<Map<String, Object>>() {});

sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlStructuredConfigProperties.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static YamlStructuredConfigProperties create(Map<String, Object> properties) {
6464
for (Map.Entry<String, Object> entry : properties.entrySet()) {
6565
String key = entry.getKey();
6666
Object value = entry.getValue();
67-
if (isPrimitive(value)) {
67+
if (isPrimitive(value) || value == null) {
6868
simpleEntries.put(key, value);
6969
continue;
7070
}
@@ -283,7 +283,7 @@ public String toString() {
283283
}
284284

285285
/** Return a map representation of the data. */
286-
Map<String, Object> toMap() {
286+
public Map<String, Object> toMap() {
287287
Map<String, Object> result = new HashMap<>(simpleEntries);
288288
listEntries.forEach(
289289
(key, value) ->

sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlStructuredConfigPropertiesTest.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class YamlStructuredConfigPropertiesTest {
3333
+ " int_key: 1\n"
3434
+ " float_key: 1.1\n"
3535
+ " bool_key: true\n"
36+
+ " null_key:\n"
3637
+ " str_list_key: [val1, val2]\n"
3738
+ " int_list_key: [1, 2]\n"
3839
+ " float_list_key: [1.1, 2.2]\n"
@@ -90,6 +91,7 @@ void additionalProperties() {
9091
"int_key",
9192
"float_key",
9293
"bool_key",
94+
"null_key",
9395
"str_list_key",
9496
"int_list_key",
9597
"float_list_key",
@@ -101,7 +103,10 @@ void additionalProperties() {
101103
assertThat(otherProps.getInt("int_key")).isEqualTo(1);
102104
assertThat(otherProps.getLong("int_key")).isEqualTo(1);
103105
assertThat(otherProps.getDouble("float_key")).isEqualTo(1.1);
104-
assertThat(otherProps.getBoolean("bool_key")).isTrue();
106+
assertThat(otherProps.getString("null_key")).isNull();
107+
assertThat(otherProps.getInt("null_key")).isNull();
108+
assertThat(otherProps.getLong("null_key")).isNull();
109+
assertThat(otherProps.getBoolean("null_key")).isNull();
105110
assertThat(otherProps.getScalarList("str_list_key", String.class))
106111
.isEqualTo(Arrays.asList("val1", "val2"));
107112
assertThat(otherProps.getScalarList("int_list_key", Long.class))

0 commit comments

Comments
 (0)