|
| 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 | +} |
0 commit comments