Skip to content

Commit 1b221f8

Browse files
author
chenyijiang
committed
1.Load all defined context propagators.
2.Change the user defined file name suffix to 'sampling'.
1 parent 9e674b6 commit 1b221f8

File tree

13 files changed

+37
-26
lines changed

13 files changed

+37
-26
lines changed

examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<artifactId>capa-parent</artifactId>
2525
<groupId>group.rxcloud</groupId>
26-
<version>1.10.11.RELEASE</version>
26+
<version>1.10.12.RELEASE</version>
2727
</parent>
2828

2929
<artifactId>capa-examples</artifactId>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<groupId>group.rxcloud</groupId>
2424
<artifactId>capa-parent</artifactId>
2525
<packaging>pom</packaging>
26-
<version>1.10.11.RELEASE</version>
26+
<version>1.10.12.RELEASE</version>
2727
<name>capa-sdk-parent</name>
2828
<description>SDK for Capa.</description>
2929
<url>https://github.com/reactivegroup</url>

sdk-component/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>group.rxcloud</groupId>
2525
<artifactId>capa-parent</artifactId>
26-
<version>1.10.11.RELEASE</version>
26+
<version>1.10.12.RELEASE</version>
2727
</parent>
2828

2929
<artifactId>capa-sdk-component</artifactId>

sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/SamplerConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class SamplerConfig implements Serializable {
4949

5050
static {
5151
Mixer.configurationHooksNullable().ifPresent(hooks -> {
52-
String fileName = "capa-component-telemetry-sample.properties";
52+
String fileName = "capa-component-telemetry-sampling.properties";
5353
try {
5454
// TODO: 2021/12/3 Move this to SPI module.
5555
// TODO: 2021/12/3 And use Configuration extension api to get merged file.

sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/context/CapaContextPropagatorBuilder.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,34 @@ public CapaContextPropagatorBuilder addContextPropagators(TextMapPropagator proc
6161
* @return context propagators.
6262
*/
6363
public ContextPropagators buildContextPropagators() {
64-
if (contextPropagatorsInstance != null && !contextPropagatorsInstance.isEmpty()) {
65-
return ContextPropagators
66-
.create(TextMapPropagator.composite(contextPropagatorsInstance.toArray(new TextMapPropagator[0])));
67-
}
68-
64+
List<TextMapPropagator> propagators = new ArrayList<>();
6965
initContextConfig();
7066
if (contextConfig != null) {
7167
List<String> types = contextConfig.getContextPropagators();
7268
if (types != null && !types.isEmpty()) {
73-
return ContextPropagators
74-
.create(TextMapPropagator.composite(types.stream()
75-
.map(path -> SpiUtils
76-
.newInstanceWithConstructorCache(path, TextMapPropagator.class))
77-
.toArray(TextMapPropagator[]::new)));
69+
types.stream()
70+
.map(path -> SpiUtils
71+
.newInstanceWithConstructorCache(path, TextMapPropagator.class))
72+
.forEach(propagator -> propagators.add(propagator));
7873
}
7974
}
8075

76+
if (contextPropagatorsInstance != null && !contextPropagatorsInstance.isEmpty()) {
77+
propagators.addAll(contextPropagatorsInstance);
78+
}
79+
8180
ContextPropagatorLoader loader = SpiUtils.loadFromSpiComponentFileNullable(ContextPropagatorLoader.class, "telemetry");
82-
if (loader == null) {
83-
loader = ContextPropagatorLoader.DEFAULT;
81+
if (loader != null) {
82+
List<TextMapPropagator> loaded = loader.load();
83+
if (loaded != null) {
84+
propagators.addAll(loaded);
85+
}
86+
}
87+
88+
if (propagators.isEmpty()) {
89+
return ContextPropagators.noop();
8490
}
85-
return loader.load();
91+
return ContextPropagators.create(TextMapPropagator.composite(propagators.toArray(new TextMapPropagator[0])));
8692
}
8793

8894
private void initContextConfig() {

sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/context/ContextPropagatorLoader.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
*/
1717
package group.rxcloud.capa.component.telemetry.context;
1818

19-
import io.opentelemetry.context.propagation.ContextPropagators;
19+
import io.opentelemetry.context.propagation.TextMapPropagator;
20+
21+
import java.util.Collections;
22+
import java.util.List;
2023

2124
/**
2225
* Load default context propagator.
@@ -31,7 +34,7 @@ public interface ContextPropagatorLoader {
3134
*
3235
* @return default context propagator.
3336
*/
34-
default ContextPropagators load() {
35-
return ContextPropagators.noop();
37+
default List<TextMapPropagator> load() {
38+
return Collections.emptyList();
3639
}
3740
}

sdk-component/src/test/java/group/rxcloud/capa/component/telemetry/context/CapaContextPropagatorBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void set(@Nullable Object carrier, String key, String value) {
8686
}
8787
});
8888

89-
assertEquals(2, TestPropagator.getCalled());
89+
assertEquals(5, TestPropagator.getCalled());
9090
}
9191

9292

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
traceEnable=true
2+
metricsEnable=true

sdk-infrastructure/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<artifactId>capa-parent</artifactId>
2525
<groupId>group.rxcloud</groupId>
26-
<version>1.10.11.RELEASE</version>
26+
<version>1.10.12.RELEASE</version>
2727
</parent>
2828

2929
<artifactId>capa-sdk-infrastructure</artifactId>

sdk-spi-demo/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<artifactId>capa-parent</artifactId>
2525
<groupId>group.rxcloud</groupId>
26-
<version>1.10.11.RELEASE</version>
26+
<version>1.10.12.RELEASE</version>
2727
</parent>
2828

2929
<artifactId>capa-sdk-spi-demo</artifactId>

0 commit comments

Comments
 (0)