Skip to content

Commit f8c07ec

Browse files
authored
Merge pull request #52 from reactivegroup/feature/metrics
feat: telemetry api
2 parents bb9def8 + 623b3f6 commit f8c07ec

File tree

128 files changed

+6428
-1040
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+6428
-1040
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ For a Maven project, add the following to your pom.xml file:
120120
<dependency>
121121
<groupId>group.rxcloud</groupId>
122122
<artifactId>capa-sdk</artifactId>
123-
<version>1.0.6.RELEASE</version>
123+
<version>1.0.7.RELEASE</version>
124124
</dependency>
125125
...
126126
</dependencies>
@@ -140,7 +140,7 @@ Sample implementation library:
140140
<dependency>
141141
<groupId>group.rxcloud</groupId>
142142
<artifactId>capa-sdk-spi-demo</artifactId>
143-
<version>1.0.6.RELEASE</version>
143+
<version>1.0.7.RELEASE</version>
144144
</dependency>
145145
...
146146
</dependencies>

README_ZH.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ For a Maven project, add the following to your pom.xml file:
118118
<dependency>
119119
<groupId>group.rxcloud</groupId>
120120
<artifactId>capa-sdk</artifactId>
121-
<version>1.0.6.RELEASE</version>
121+
<version>1.0.7.RELEASE</version>
122122
</dependency>
123123
...
124124
</dependencies>
@@ -138,7 +138,7 @@ Sample implementation library:
138138
<dependency>
139139
<groupId>group.rxcloud</groupId>
140140
<artifactId>capa-sdk-spi-demo</artifactId>
141-
<version>1.0.6.RELEASE</version>
141+
<version>1.0.7.RELEASE</version>
142142
</dependency>
143143
...
144144
</dependencies>

examples/pom.xml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@
2323
<parent>
2424
<artifactId>capa-parent</artifactId>
2525
<groupId>group.rxcloud</groupId>
26-
<version>1.0.6.RELEASE</version>
26+
<version>1.0.7.RELEASE</version>
2727
</parent>
2828

2929
<artifactId>capa-examples</artifactId>
3030
<packaging>jar</packaging>
3131
<name>capa-sdk-examples</name>
3232

3333
<properties>
34-
<log4j.version>2.14.1</log4j.version>
34+
<log4j.version>2.8.2</log4j.version>
35+
<logback.version>1.1.7</logback.version>
36+
<slf4j-api.version>1.7.32</slf4j-api.version>
3537
</properties>
3638

3739
<dependencies>
@@ -58,21 +60,23 @@
5860
</exclusion>
5961
</exclusions>
6062
</dependency>
61-
<!-- log4j2 and slf4j -->
63+
<!-- slf4j -->
6264
<dependency>
6365
<groupId>org.apache.logging.log4j</groupId>
6466
<artifactId>log4j-slf4j-impl</artifactId>
6567
<version>${log4j.version}</version>
66-
<exclusions>
67-
<exclusion>
68-
<artifactId>log4j-core</artifactId>
69-
<groupId>org.apache.logging.log4j</groupId>
70-
</exclusion>
71-
<exclusion>
72-
<artifactId>log4j-api</artifactId>
73-
<groupId>org.apache.logging.log4j</groupId>
74-
</exclusion>
75-
</exclusions>
68+
</dependency>
69+
<!-- logback -->
70+
<!-- <dependency>
71+
<groupId>ch.qos.logback</groupId>
72+
<artifactId>logback-classic</artifactId>
73+
<version>${logback.version}</version>
74+
</dependency>-->
75+
<!--lombok-->
76+
<dependency>
77+
<groupId>org.projectlombok</groupId>
78+
<artifactId>lombok</artifactId>
79+
<version>1.18.2</version>
7680
</dependency>
7781
</dependencies>
7882

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package group.rxcloud.capa.examples.log;
18+
19+
import lombok.extern.slf4j.Slf4j;
20+
21+
/**
22+
* An application cannot use log4j and logback configuration to print logs at the same time.
23+
* So if you want to test the log4j2 configuration to print logs, then you need to copy the resources/xml/log4j2.xml file to the resources directory, and then add log4j-slf4j-impl dependency to the pom file.
24+
* Else if you want to use logback configuration to print logs, then the resources/xml/logback.xml file needs to be copied to the resources path, and the logback-classic dependency needs to be added to the pom file.
25+
* Notice:
26+
* 1. Resources cannot contain log4j2.xml and logback.xml files at the same time,
27+
* 2. log4j-slf4j-impl and logback-classic cannot exist at the same time.
28+
*/
29+
@Slf4j
30+
public class DemoLog {
31+
32+
public static void main(String[] args) {
33+
log.info("test");
34+
}
35+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package group.rxcloud.capa.examples.telemetry;
18+
19+
import group.rxcloud.capa.component.telemetry.metrics.MetricsReaderConfig;
20+
import group.rxcloud.capa.telemetry.CapaTelemetryClient;
21+
import group.rxcloud.capa.telemetry.CapaTelemetryClientBuilder;
22+
import io.opentelemetry.api.metrics.LongCounter;
23+
import io.opentelemetry.api.trace.Span;
24+
import io.opentelemetry.api.trace.Tracer;
25+
26+
import java.util.concurrent.TimeUnit;
27+
28+
public class DemoTelemetryClient {
29+
30+
public static void main(String[] args) throws InterruptedException {
31+
MetricsReaderConfig readerConfig = new MetricsReaderConfig();
32+
readerConfig.setExporterType(MetricTestExporter.class.getName());
33+
readerConfig.setName("metric-reader");
34+
readerConfig.setExportInterval(1, TimeUnit.SECONDS);
35+
CapaTelemetryClient capaTelemetryClient = new CapaTelemetryClientBuilder()
36+
.addProcessor(new TraceProcessor())
37+
.addMetricReaderConfig(readerConfig)
38+
.build();
39+
40+
// tracer
41+
Tracer tracer = capaTelemetryClient.buildTracer("tracer-test")
42+
.block();
43+
44+
LongCounter counter = capaTelemetryClient.buildMeter("meter-test")
45+
.block()
46+
.counterBuilder("counter-test")
47+
.build();
48+
49+
Span span = tracer.spanBuilder("span-test")
50+
.setAttribute("key1", 1)
51+
.setAttribute("key2", 2)
52+
.startSpan();
53+
// working
54+
for (int i = 0; i < 50; i++) {
55+
Thread.sleep(200);
56+
counter.add(i);
57+
}
58+
59+
span.end();
60+
}
61+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package group.rxcloud.capa.examples.telemetry;
18+
19+
import io.opentelemetry.sdk.common.CompletableResultCode;
20+
import io.opentelemetry.sdk.metrics.data.MetricData;
21+
import io.opentelemetry.sdk.metrics.export.MetricExporter;
22+
23+
import java.util.Collection;
24+
25+
public class MetricTestExporter implements MetricExporter {
26+
27+
@Override
28+
public CompletableResultCode export(Collection<MetricData> metrics) {
29+
metrics.forEach(System.out::println);
30+
return CompletableResultCode.ofSuccess();
31+
}
32+
33+
@Override
34+
public CompletableResultCode flush() {
35+
return CompletableResultCode.ofSuccess();
36+
}
37+
38+
@Override
39+
public CompletableResultCode shutdown() {
40+
return CompletableResultCode.ofSuccess();
41+
}
42+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package group.rxcloud.capa.examples.telemetry;
18+
19+
import io.opentelemetry.context.Context;
20+
import io.opentelemetry.sdk.trace.ReadWriteSpan;
21+
import io.opentelemetry.sdk.trace.ReadableSpan;
22+
import io.opentelemetry.sdk.trace.SpanProcessor;
23+
24+
public class TraceProcessor implements SpanProcessor {
25+
26+
@Override
27+
public void onStart(Context context, ReadWriteSpan span) {
28+
29+
}
30+
31+
@Override
32+
public boolean isStartRequired() {
33+
return false;
34+
}
35+
36+
@Override
37+
public void onEnd(ReadableSpan span) {
38+
System.out.println(span.toSpanData());
39+
}
40+
41+
@Override
42+
public boolean isEndRequired() {
43+
return true;
44+
}
45+
}

examples/src/main/resources/log4j2.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
<Console name="Console" target="SYSTEM_OUT">
2121
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
2222
</Console>
23+
<CapaLog4jAppender name="log"/>
2324
</Appenders>
2425
<Loggers>
25-
<Root level="debug">
26+
<Root level="INFO">
2627
<AppenderRef ref="Console"/>
28+
<AppenderRef ref="log"/>
2729
</Root>
2830
</Loggers>
2931
</Configuration>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<Configuration status="DEBUG">
19+
<Appenders>
20+
<Console name="Console" target="SYSTEM_OUT">
21+
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
22+
</Console>
23+
<CapaLog4jAppender name="log"/>
24+
</Appenders>
25+
<Loggers>
26+
<Root level="INFO">
27+
<AppenderRef ref="Console"/>
28+
<AppenderRef ref="log"/>
29+
</Root>
30+
</Loggers>
31+
</Configuration>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<configuration>
19+
<!--Log-->
20+
<appender name="Log" class="group.rxcloud.capa.component.log.agent.CapaLogbackAppenderAgent">
21+
</appender>
22+
23+
<logger name="com.ctrip.ibu.market.e2c" level="INFO" additivity="false">
24+
<!-- <appender-ref ref="STDOUT"/>-->
25+
<appender-ref ref="Log"/>
26+
</logger>
27+
28+
<logger name="com.ctrip.ibu.telescope.mock.support" level="INFO" additivity="false">
29+
<!-- <appender-ref ref="STDOUT"/>-->
30+
<appender-ref ref="Log"/>
31+
</logger>
32+
33+
<root level="INFO">
34+
<appender-ref ref="Log"/>
35+
</root>
36+
</configuration>

0 commit comments

Comments
 (0)