This is an automated email from the ASF dual-hosted git repository. zhfeng pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-quarkus-examples.git
commit d212e3d88f0e649b57e9f3b5a56c849e7279d092 Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Fri May 13 10:59:39 2022 +0100 Use OpenTelemetry instead of deprecated OpenTracing in observability example --- observability/README.adoc | 8 ++--- observability/docker-compose.yml | 40 +++++++++++++++++++++ observability/otel-collector-config.yaml | 42 ++++++++++++++++++++++ observability/pom.xml | 10 +++++- .../tracing/LoggingSpanExporterProducer.java | 35 ++++++++++++++++++ .../src/main/resources/application.properties | 10 +++--- 6 files changed, 135 insertions(+), 10 deletions(-) diff --git a/observability/README.adoc b/observability/README.adoc index 5c990f0..fad3fff 100644 --- a/observability/README.adoc +++ b/observability/README.adoc @@ -63,19 +63,19 @@ You can also directly leverage MicroProfile Health APIs to create checks. Class The tracing configuration for the application can be found within `application.properties`. -To view tracing events, start a Jaeger tracing server. A simple way of doing this is with Docker: +To view tracing events, start a tracing server. A simple way of doing this is with Docker Compose: [source,shell] ---- -$ docker run -e COLLECTOR_ZIPKIN_HTTP_PORT=9411 -p 5775:5775/udp -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 \ - -p 16686:16686 -p 14268:14268 -p 9411:9411 jaegertracing/all-in-one:latest +$ docker-compose up -d ---- -With the server running, browse to http://localhost:16686. Then choose 'greetings-service' from the 'Service' drop down and click the 'Find Traces' button. +With the server running, browse to http://localhost:16686. Then choose 'camel-quarkus-observability' from the 'Service' drop down and click the 'Find Traces' button. The `netty-http` consumer route introduces a random delay to simulate latency, hence the overall time of each trace should be different. When viewing a trace, you should see a hierarchy of 3 spans showing the progression of the message exchange through each endpoint. +For convenience, tracing events are also logged to the application console. === Package and run the application diff --git a/observability/docker-compose.yml b/observability/docker-compose.yml new file mode 100644 index 0000000..eb60f01 --- /dev/null +++ b/observability/docker-compose.yml @@ -0,0 +1,40 @@ +# +# 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. +# + +version: "2" +services: + + # Jaeger + jaeger-all-in-one: + image: jaegertracing/all-in-one:1.33 + ports: + - "16686:16686" + - "14268" + - "14250" + + # Collector + otel-collector: + image: otel/opentelemetry-collector:0.50.0 + command: [ "--config=/etc/otel-collector-config.yaml" ] + volumes: + - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml + ports: + - "13133:13133" # Health_check extension + - "4317:4317" # OTLP gRPC receiver + - "55680:55680" # OTLP gRPC receiver alternative port + depends_on: + - jaeger-all-in-one diff --git a/observability/otel-collector-config.yaml b/observability/otel-collector-config.yaml new file mode 100644 index 0000000..b108831 --- /dev/null +++ b/observability/otel-collector-config.yaml @@ -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. +# + +receivers: + otlp: + protocols: + grpc: + endpoint: otel-collector:4317 + +exporters: + jaeger: + endpoint: jaeger-all-in-one:14250 + tls: + insecure: true + +processors: + batch: + +extensions: + health_check: + +service: + extensions: [health_check] + pipelines: + traces: + receivers: [otlp] + processors: [batch] + exporters: [jaeger] \ No newline at end of file diff --git a/observability/pom.xml b/observability/pom.xml index 680c9dc..04d1a11 100644 --- a/observability/pom.xml +++ b/observability/pom.xml @@ -92,12 +92,20 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-opentracing</artifactId> + <artifactId>camel-quarkus-opentelemetry</artifactId> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> </dependency> + <dependency> + <groupId>io.opentelemetry</groupId> + <artifactId>opentelemetry-exporter-logging</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-opentelemetry-exporter-otlp</artifactId> + </dependency> <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-resteasy</artifactId> diff --git a/observability/src/main/java/org/acme/observability/tracing/LoggingSpanExporterProducer.java b/observability/src/main/java/org/acme/observability/tracing/LoggingSpanExporterProducer.java new file mode 100644 index 0000000..e3ccd2d --- /dev/null +++ b/observability/src/main/java/org/acme/observability/tracing/LoggingSpanExporterProducer.java @@ -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 org.acme.observability.tracing; + +import javax.enterprise.inject.Produces; + +import io.opentelemetry.exporter.logging.LoggingSpanExporter; +import io.opentelemetry.sdk.trace.export.SpanExporter; + +/** + * Quarkus OpenTelemetry automatically discovers and configures SpanExporter beans at build time. + * + * The LoggingSpanExporter outputs span details to the application console. + */ +public class LoggingSpanExporterProducer { + + @Produces + public SpanExporter loggingSpanExporter() { + return LoggingSpanExporter.create(); + } +} diff --git a/observability/src/main/resources/application.properties b/observability/src/main/resources/application.properties index 5b14547..876d847 100644 --- a/observability/src/main/resources/application.properties +++ b/observability/src/main/resources/application.properties @@ -20,11 +20,11 @@ # quarkus.banner.enabled = false -# Configure Quarkus Jaeger OpenTracing support -quarkus.jaeger.service-name = greetings-service -quarkus.jaeger.sampler-type = const -quarkus.jaeger.sampler-param = 1 -quarkus.jaeger.endpoint = http://localhost:14268/api/traces +# Identifier for the origin of spans created by the application +quarkus.application.name=camel-quarkus-observability + +# gRPC endpoint for sending spans +quarkus.opentelemetry.tracer.exporter.otlp.endpoint=http://localhost:4317 # Allow metrics to be exported as JSON. Not strictly required and is disabled by default quarkus.micrometer.export.json.enabled = true