-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from reactivegroup/feature/metrics
feat: telemetry api
- Loading branch information
Showing
128 changed files
with
6,428 additions
and
1,040 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
examples/src/main/java/group/rxcloud/capa/examples/log/DemoLog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package group.rxcloud.capa.examples.log; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* An application cannot use log4j and logback configuration to print logs at the same time. | ||
* 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. | ||
* 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. | ||
* Notice: | ||
* 1. Resources cannot contain log4j2.xml and logback.xml files at the same time, | ||
* 2. log4j-slf4j-impl and logback-classic cannot exist at the same time. | ||
*/ | ||
@Slf4j | ||
public class DemoLog { | ||
|
||
public static void main(String[] args) { | ||
log.info("test"); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
examples/src/main/java/group/rxcloud/capa/examples/telemetry/DemoTelemetryClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package group.rxcloud.capa.examples.telemetry; | ||
|
||
import group.rxcloud.capa.component.telemetry.metrics.MetricsReaderConfig; | ||
import group.rxcloud.capa.telemetry.CapaTelemetryClient; | ||
import group.rxcloud.capa.telemetry.CapaTelemetryClientBuilder; | ||
import io.opentelemetry.api.metrics.LongCounter; | ||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.api.trace.Tracer; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public class DemoTelemetryClient { | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
MetricsReaderConfig readerConfig = new MetricsReaderConfig(); | ||
readerConfig.setExporterType(MetricTestExporter.class.getName()); | ||
readerConfig.setName("metric-reader"); | ||
readerConfig.setExportInterval(1, TimeUnit.SECONDS); | ||
CapaTelemetryClient capaTelemetryClient = new CapaTelemetryClientBuilder() | ||
.addProcessor(new TraceProcessor()) | ||
.addMetricReaderConfig(readerConfig) | ||
.build(); | ||
|
||
// tracer | ||
Tracer tracer = capaTelemetryClient.buildTracer("tracer-test") | ||
.block(); | ||
|
||
LongCounter counter = capaTelemetryClient.buildMeter("meter-test") | ||
.block() | ||
.counterBuilder("counter-test") | ||
.build(); | ||
|
||
Span span = tracer.spanBuilder("span-test") | ||
.setAttribute("key1", 1) | ||
.setAttribute("key2", 2) | ||
.startSpan(); | ||
// working | ||
for (int i = 0; i < 50; i++) { | ||
Thread.sleep(200); | ||
counter.add(i); | ||
} | ||
|
||
span.end(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
examples/src/main/java/group/rxcloud/capa/examples/telemetry/MetricTestExporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package group.rxcloud.capa.examples.telemetry; | ||
|
||
import io.opentelemetry.sdk.common.CompletableResultCode; | ||
import io.opentelemetry.sdk.metrics.data.MetricData; | ||
import io.opentelemetry.sdk.metrics.export.MetricExporter; | ||
|
||
import java.util.Collection; | ||
|
||
public class MetricTestExporter implements MetricExporter { | ||
|
||
@Override | ||
public CompletableResultCode export(Collection<MetricData> metrics) { | ||
metrics.forEach(System.out::println); | ||
return CompletableResultCode.ofSuccess(); | ||
} | ||
|
||
@Override | ||
public CompletableResultCode flush() { | ||
return CompletableResultCode.ofSuccess(); | ||
} | ||
|
||
@Override | ||
public CompletableResultCode shutdown() { | ||
return CompletableResultCode.ofSuccess(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
examples/src/main/java/group/rxcloud/capa/examples/telemetry/TraceProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package group.rxcloud.capa.examples.telemetry; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.sdk.trace.ReadWriteSpan; | ||
import io.opentelemetry.sdk.trace.ReadableSpan; | ||
import io.opentelemetry.sdk.trace.SpanProcessor; | ||
|
||
public class TraceProcessor implements SpanProcessor { | ||
|
||
@Override | ||
public void onStart(Context context, ReadWriteSpan span) { | ||
|
||
} | ||
|
||
@Override | ||
public boolean isStartRequired() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void onEnd(ReadableSpan span) { | ||
System.out.println(span.toSpanData()); | ||
} | ||
|
||
@Override | ||
public boolean isEndRequired() { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<Configuration status="DEBUG"> | ||
<Appenders> | ||
<Console name="Console" target="SYSTEM_OUT"> | ||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> | ||
</Console> | ||
<CapaLog4jAppender name="log"/> | ||
</Appenders> | ||
<Loggers> | ||
<Root level="INFO"> | ||
<AppenderRef ref="Console"/> | ||
<AppenderRef ref="log"/> | ||
</Root> | ||
</Loggers> | ||
</Configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<configuration> | ||
<!--Log--> | ||
<appender name="Log" class="group.rxcloud.capa.component.log.agent.CapaLogbackAppenderAgent"> | ||
</appender> | ||
|
||
<logger name="com.ctrip.ibu.market.e2c" level="INFO" additivity="false"> | ||
<!-- <appender-ref ref="STDOUT"/>--> | ||
<appender-ref ref="Log"/> | ||
</logger> | ||
|
||
<logger name="com.ctrip.ibu.telescope.mock.support" level="INFO" additivity="false"> | ||
<!-- <appender-ref ref="STDOUT"/>--> | ||
<appender-ref ref="Log"/> | ||
</logger> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="Log"/> | ||
</root> | ||
</configuration> |
Oops, something went wrong.