Skip to content

Commit 0a1a2ce

Browse files
authored
Add declarative config support for setting schema url (#8028)
1 parent f42ac7d commit 0a1a2ce

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public Resource create(ResourceModel model, DeclarativeConfigContext context) {
7272
.build();
7373
}
7474

75+
if (model.getSchemaUrl() != null) {
76+
builder.setSchemaUrl(model.getSchemaUrl());
77+
}
78+
7579
return builder.build();
7680
}
7781

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.List;
2222
import java.util.stream.Stream;
2323
import javax.annotation.Nullable;
24-
import org.junit.jupiter.api.Test;
2524
import org.junit.jupiter.params.ParameterizedTest;
2625
import org.junit.jupiter.params.provider.Arguments;
2726
import org.junit.jupiter.params.provider.MethodSource;
@@ -31,28 +30,31 @@ class ResourceFactoryTest {
3130
private final DeclarativeConfigContext context =
3231
new DeclarativeConfigContext(SpiHelper.create(ResourceFactoryTest.class.getClassLoader()));
3332

34-
@Test
35-
void create() {
36-
assertThat(
37-
ResourceFactory.getInstance()
38-
.create(
39-
new ResourceModel()
40-
.withAttributes(
41-
Arrays.asList(
42-
new AttributeNameValueModel()
43-
.withName("service.name")
44-
.withValue("my-service"),
45-
new AttributeNameValueModel().withName("key").withValue("val"),
46-
new AttributeNameValueModel()
47-
.withName("shape")
48-
.withValue("circle"))),
49-
context))
50-
.isEqualTo(
33+
@ParameterizedTest
34+
@MethodSource("createArgs")
35+
void create(ResourceModel model, Resource expectedResource) {
36+
assertThat(ResourceFactory.getInstance().create(model, context)).isEqualTo(expectedResource);
37+
}
38+
39+
private static Stream<Arguments> createArgs() {
40+
return Stream.of(
41+
Arguments.of(
42+
new ResourceModel()
43+
.withAttributes(
44+
Arrays.asList(
45+
new AttributeNameValueModel()
46+
.withName("service.name")
47+
.withValue("my-service"),
48+
new AttributeNameValueModel().withName("key").withValue("val"),
49+
new AttributeNameValueModel().withName("shape").withValue("circle"))),
5150
Resource.getDefault().toBuilder()
5251
.put("shape", "circle")
5352
.put("service.name", "my-service")
5453
.put("key", "val")
55-
.build());
54+
.build()),
55+
Arguments.of(
56+
new ResourceModel().withSchemaUrl("http://foo"),
57+
Resource.getDefault().toBuilder().setSchemaUrl("http://foo").build()));
5658
}
5759

5860
@ParameterizedTest

0 commit comments

Comments
 (0)