This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push: new ce9794a Add OpenTelemetry extension ce9794a is described below commit ce9794ad7b979e5a0b85bf47270040aee1aecd47 Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Tue Jun 29 07:44:23 2021 +0100 Add OpenTelemetry extension Fixes #2084 --- docs/modules/ROOT/nav.adoc | 1 + .../pages/reference/extensions/opentelemetry.adoc | 120 ++++++++++++++++++ .../partials/reference/others/opentelemetry.adoc | 14 ++- extensions/opentelemetry/deployment/pom.xml | 67 ++++++++++ .../deployment/OpenTelemetryProcessor.java | 40 ++++++ extensions/opentelemetry/pom.xml | 39 ++++++ extensions/opentelemetry/runtime/pom.xml | 117 +++++++++++++++++ .../opentelemetry/runtime/src/main/doc/usage.adoc | 47 +++++++ .../CamelQuarkusOpenTelemetryTracer.java | 47 +++++++ .../opentelemetry/CamelOpenTelemetryConfig.java | 57 +++++++++ .../opentelemetry/OpenTelemetryTracerProducer.java | 53 ++++++++ .../main/resources/META-INF/quarkus-extension.yaml | 31 +++++ extensions/pom.xml | 1 + integration-tests/opentelemetry/pom.xml | 140 +++++++++++++++++++++ .../opentelemetry/it/OpenTelemetryResource.java | 65 ++++++++++ .../it/OpenTelemetryRouteBuilder.java | 33 +++++ .../opentelemetry/it/SpanExporterProducer.java | 33 +++++ .../src/main/resources/application.properties | 18 +++ .../opentelemetry/it/OpenTelemetryIT.java | 24 ++++ .../opentelemetry/it/OpenTelemetryTest.java | 68 ++++++++++ integration-tests/pom.xml | 1 + poms/bom/pom.xml | 15 +++ tooling/scripts/test-categories.yaml | 1 + 23 files changed, 1031 insertions(+), 1 deletion(-) diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index efd3d7c..094a7f0 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -231,6 +231,7 @@ *** xref:reference/extensions/olingo4.adoc[Olingo4] *** xref:reference/extensions/openapi-java.adoc[OpenAPI Java] *** xref:reference/extensions/openstack.adoc[OpenStack] +*** xref:reference/extensions/opentelemetry.adoc[OpenTelemetry] *** xref:reference/extensions/opentracing.adoc[OpenTracing] *** xref:reference/extensions/optaplanner.adoc[OptaPlanner] *** xref:reference/extensions/pdf.adoc[PDF] diff --git a/docs/modules/ROOT/pages/reference/extensions/opentelemetry.adoc b/docs/modules/ROOT/pages/reference/extensions/opentelemetry.adoc new file mode 100644 index 0000000..b048a59 --- /dev/null +++ b/docs/modules/ROOT/pages/reference/extensions/opentelemetry.adoc @@ -0,0 +1,120 @@ +// Do not edit directly! +// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page += OpenTelemetry +:linkattrs: +:cq-artifact-id: camel-quarkus-opentelemetry +:cq-native-supported: true +:cq-status: Stable +:cq-status-deprecation: Stable +:cq-description: Distributed tracing using OpenTelemetry +:cq-deprecated: false +:cq-jvm-since: 2.1.0 +:cq-native-since: 2.1.0 + +[.badges] +[.badge-key]##JVM since##[.badge-supported]##2.1.0## [.badge-key]##Native since##[.badge-supported]##2.1.0## + +Distributed tracing using OpenTelemetry + +== What's inside + +* xref:{cq-camel-components}:others:opentelemetry.adoc[OpenTelemetry] + +Please refer to the above link for usage and configuration details. + +== Maven coordinates + +https://code.quarkus.io/?extension-search=camel-quarkus-opentelemetry[Create a new project with this extension on code.quarkus.io, window="_blank"] + +Or add the coordinates to your existing project: + +[source,xml] +---- +<dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-opentelemetry</artifactId> +</dependency> +---- + +Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. + +== Usage + +The extension automatically creates a Camel `OpenTelemetryTracer` and binds it to the Camel registry. + +In order to send the captured traces to a tracing system, you need to configure some properties within `application.properties` like those below. + +[source,properties] +---- +# Identifier for the origin of spans created by the application +quarkus.application.name=my-camel-application + +# For OTLP +quarkus.opentelemetry.tracer.exporter.otlp.endpoint=http://localhost:55680 + +# For Jaeger +quarkus.opentelemetry.tracer.exporter.jaeger.endpoint=http://localhost:14268/api/traces +---- + +Note that you must add a dependency to the OpenTelemetry exporter that you want to work with. At present, Quarkus has support for +Jaeger and the OpenTelemetry Protocol Specification (OTLP). + +For Jaeger: + +[source,xml] +---- +<dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-opentelemetry-exporter-jaeger</artifactId> +</dependency> +---- + +For OTLP: +[source,xml] +---- +<dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-opentelemetry-exporter-otlp</artifactId> +</dependency> +---- + +Refer to the https://github.com/quarkusio/quarkus/blob/{quarkus-version}/docs/src/main/asciidoc/opentelemetry.adoc[Quarkus OpenTelemetry guide] for a full list of configuration options. + +Route endpoints can be excluded from tracing by configuring a property named `quarkus.camel.opentelemetry.exclude-patterns` in `application.properties`. For example: + +[source,properties] +---- +# Exclude all direct & netty-http endpoints from tracing +quarkus.camel.opentelemetry.exclude-patterns=direct:*,netty-http:* +---- + + +== Additional Camel Quarkus configuration + +[width="100%",cols="80,5,15",options="header"] +|=== +| Configuration property | Type | Default + + +|icon:lock[title=Fixed at build time] [[quarkus.camel.opentelemetry.encoding]]`link:#quarkus.camel.opentelemetry.encoding[quarkus.camel.opentelemetry.encoding]` + +Sets whether header keys need to be encoded +| `boolean` +| `false` + +|icon:lock[title=Fixed at build time] [[quarkus.camel.opentelemetry.exclude-patterns]]`link:#quarkus.camel.opentelemetry.exclude-patterns[quarkus.camel.opentelemetry.exclude-patterns]` + +Sets whether to disable tracing for endpoint URIs that match the given patterns. The pattern can take the following forms: + + 1. An exact match on the endpoint URI. E.g platform-http:/some/path + + 2. A wildcard match. E.g platform-http:++*++ + + 3. A regular expression matching the endpoint URI. E.g platform-http:/prefix/.++*++ +| `string` +| +|=== + +[.configuration-legend] +icon:lock[title=Fixed at build time] Configuration property fixed at build time. All other configuration properties are overridable at runtime. + diff --git a/docs/modules/ROOT/partials/reference/others/opentelemetry.adoc b/docs/modules/ROOT/partials/reference/others/opentelemetry.adoc index a509c1d..bc2a311 100644 --- a/docs/modules/ROOT/partials/reference/others/opentelemetry.adoc +++ b/docs/modules/ROOT/partials/reference/others/opentelemetry.adoc @@ -1 +1,13 @@ -// Empty partial for a Camel bit unsupported by Camel Quarkus to avoid warnings when this file is included from a Camel page +// Do not edit directly! +// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page +:cq-artifact-id: camel-quarkus-opentelemetry +:cq-artifact-id-base: opentelemetry +:cq-native-supported: true +:cq-status: Stable +:cq-deprecated: false +:cq-jvm-since: 2.1.0 +:cq-native-since: 2.1.0 +:cq-camel-part-name: opentelemetry +:cq-camel-part-title: OpenTelemetry +:cq-camel-part-description: Distributed tracing using OpenTelemetry +:cq-extension-page-title: OpenTelemetry diff --git a/extensions/opentelemetry/deployment/pom.xml b/extensions/opentelemetry/deployment/pom.xml new file mode 100644 index 0000000..8f16909 --- /dev/null +++ b/extensions/opentelemetry/deployment/pom.xml @@ -0,0 +1,67 @@ +<?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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-opentelemetry-parent</artifactId> + <version>2.1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-opentelemetry-deployment</artifactId> + <name>Camel Quarkus :: OpenTelemetry :: Deployment</name> + + <dependencies> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-opentelemetry-deployment</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-core-deployment</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-opentelemetry</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <annotationProcessorPaths> + <path> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-extension-processor</artifactId> + <version>${quarkus.version}</version> + </path> + </annotationProcessorPaths> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/extensions/opentelemetry/deployment/src/main/java/org/apache/camel/quarkus/component/opentelemetry/deployment/OpenTelemetryProcessor.java b/extensions/opentelemetry/deployment/src/main/java/org/apache/camel/quarkus/component/opentelemetry/deployment/OpenTelemetryProcessor.java new file mode 100644 index 0000000..9fdf824 --- /dev/null +++ b/extensions/opentelemetry/deployment/src/main/java/org/apache/camel/quarkus/component/opentelemetry/deployment/OpenTelemetryProcessor.java @@ -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. + */ +package org.apache.camel.quarkus.component.opentelemetry.deployment; + +import io.quarkus.arc.deployment.AdditionalBeanBuildItem; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.FeatureBuildItem; +import org.apache.camel.quarkus.component.opentelemetry.OpenTelemetryTracerProducer; + +class OpenTelemetryProcessor { + + private static final String FEATURE = "camel-opentelemetry"; + + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); + } + + @BuildStep + AdditionalBeanBuildItem openTelemetryTracerProducerBean() { + return AdditionalBeanBuildItem.builder() + .setUnremovable() + .addBeanClass(OpenTelemetryTracerProducer.class) + .build(); + } +} diff --git a/extensions/opentelemetry/pom.xml b/extensions/opentelemetry/pom.xml new file mode 100644 index 0000000..0524a25 --- /dev/null +++ b/extensions/opentelemetry/pom.xml @@ -0,0 +1,39 @@ +<?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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-build-parent</artifactId> + <version>2.1.0-SNAPSHOT</version> + <relativePath>../../poms/build-parent/pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-opentelemetry-parent</artifactId> + <name>Camel Quarkus :: OpenTelemetry</name> + <packaging>pom</packaging> + + <modules> + <module>deployment</module> + <module>runtime</module> + </modules> +</project> diff --git a/extensions/opentelemetry/runtime/pom.xml b/extensions/opentelemetry/runtime/pom.xml new file mode 100644 index 0000000..bab56aa --- /dev/null +++ b/extensions/opentelemetry/runtime/pom.xml @@ -0,0 +1,117 @@ +<?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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-opentelemetry-parent</artifactId> + <version>2.1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-opentelemetry</artifactId> + <name>Camel Quarkus :: OpenTelemetry :: Runtime</name> + <description>Distributed tracing using OpenTelemetry</description> + + <properties> + <camel.quarkus.jvmSince>2.1.0</camel.quarkus.jvmSince> + <camel.quarkus.nativeSince>2.1.0</camel.quarkus.nativeSince> + </properties> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bom</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-opentelemetry</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-opentelemetry</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-bootstrap-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <annotationProcessorPaths> + <path> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-extension-processor</artifactId> + <version>${quarkus.version}</version> + </path> + </annotationProcessorPaths> + </configuration> + </plugin> + </plugins> + </build> + + + <profiles> + <profile> + <id>full</id> + <activation> + <property> + <name>!quickly</name> + </property> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-maven-plugin</artifactId> + <executions> + <execution> + <id>update-extension-doc-page</id> + <goals> + <goal>update-extension-doc-page</goal> + </goals> + <phase>process-classes</phase> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> diff --git a/extensions/opentelemetry/runtime/src/main/doc/usage.adoc b/extensions/opentelemetry/runtime/src/main/doc/usage.adoc new file mode 100644 index 0000000..6fe2e76 --- /dev/null +++ b/extensions/opentelemetry/runtime/src/main/doc/usage.adoc @@ -0,0 +1,47 @@ +The extension automatically creates a Camel `OpenTelemetryTracer` and binds it to the Camel registry. + +In order to send the captured traces to a tracing system, you need to configure some properties within `application.properties` like those below. + +[source,properties] +---- +# Identifier for the origin of spans created by the application +quarkus.application.name=my-camel-application + +# For OTLP +quarkus.opentelemetry.tracer.exporter.otlp.endpoint=http://localhost:55680 + +# For Jaeger +quarkus.opentelemetry.tracer.exporter.jaeger.endpoint=http://localhost:14268/api/traces +---- + +Note that you must add a dependency to the OpenTelemetry exporter that you want to work with. At present, Quarkus has support for +Jaeger and the OpenTelemetry Protocol Specification (OTLP). + +For Jaeger: + +[source,xml] +---- +<dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-opentelemetry-exporter-jaeger</artifactId> +</dependency> +---- + +For OTLP: +[source,xml] +---- +<dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-opentelemetry-exporter-otlp</artifactId> +</dependency> +---- + +Refer to the https://github.com/quarkusio/quarkus/blob/{quarkus-version}/docs/src/main/asciidoc/opentelemetry.adoc[Quarkus OpenTelemetry guide] for a full list of configuration options. + +Route endpoints can be excluded from tracing by configuring a property named `quarkus.camel.opentelemetry.exclude-patterns` in `application.properties`. For example: + +[source,properties] +---- +# Exclude all direct & netty-http endpoints from tracing +quarkus.camel.opentelemetry.exclude-patterns=direct:*,netty-http:* +---- \ No newline at end of file diff --git a/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/opentelemetry/CamelQuarkusOpenTelemetryTracer.java b/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/opentelemetry/CamelQuarkusOpenTelemetryTracer.java new file mode 100644 index 0000000..5d0df1f --- /dev/null +++ b/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/opentelemetry/CamelQuarkusOpenTelemetryTracer.java @@ -0,0 +1,47 @@ +/* + * 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.apache.camel.opentelemetry; + +import io.opentelemetry.api.baggage.Baggage; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.context.Context; +import org.apache.camel.Exchange; +import org.apache.camel.tracing.SpanAdapter; +import org.apache.camel.tracing.SpanDecorator; +import org.apache.camel.tracing.SpanKind; +import org.apache.camel.tracing.decorators.PlatformHttpSpanDecorator; +import org.apache.camel.tracing.decorators.ServletSpanDecorator; + +/** + * Custom {@link OpenTelemetryTracer} to integrate better with the existing Vert.x tracing configured by the + * Quarkus OpenTelemetry extension + */ +public class CamelQuarkusOpenTelemetryTracer extends OpenTelemetryTracer { + + @Override + protected SpanAdapter startExchangeBeginSpan(Exchange exchange, SpanDecorator sd, String operationName, SpanKind kind, + SpanAdapter parent) { + // Quarkus configures Vert.x for OpenTelemetry HTTP tracing. Therefore, avoid creating duplicate spans and + // augment the existing incoming one with additional camel specific tags & attributes + if (sd instanceof PlatformHttpSpanDecorator || sd instanceof ServletSpanDecorator) { + Span span = Span.fromContext(Context.current()); + Baggage baggage = Baggage.fromContext(Context.current()); + return new OpenTelemetrySpanAdapter(span, baggage); + } + return super.startExchangeBeginSpan(exchange, sd, operationName, kind, parent); + } +} diff --git a/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry/CamelOpenTelemetryConfig.java b/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry/CamelOpenTelemetryConfig.java new file mode 100644 index 0000000..af75824 --- /dev/null +++ b/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry/CamelOpenTelemetryConfig.java @@ -0,0 +1,57 @@ +/* + * 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.apache.camel.quarkus.component.opentelemetry; + +import java.util.List; +import java.util.Optional; + +import io.quarkus.runtime.annotations.ConfigItem; +import io.quarkus.runtime.annotations.ConfigPhase; +import io.quarkus.runtime.annotations.ConfigRoot; + +@ConfigRoot(name = "camel.opentelemetry", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) +public final class CamelOpenTelemetryConfig { + + /** + * Sets whether header keys need to be encoded + */ + @ConfigItem(defaultValue = "false") + public boolean encoding; + + /** + * Sets whether to disable tracing for endpoint URIs that match the given patterns. The pattern can take the following + * forms: + * <p> + * <p> + * 1. An exact match on the endpoint URI. E.g platform-http:/some/path + * <p> + * <p> + * 2. A wildcard match. E.g platform-http:* + * <p> + * <p> + * 3. A regular expression matching the endpoint URI. E.g platform-http:/prefix/.* + */ + @ConfigItem + public Optional<List<String>> excludePatterns; +} + +/* + * <li>exact match, returns true</li> + * <li>wildcard match (pattern ends with a * and the uri starts with the pattern), returns true</li> + * <li>regular expression match, returns true</li> + * <li>exact match with uri normalization of the pattern if possible, returns true</li> + */ diff --git a/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry/OpenTelemetryTracerProducer.java b/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry/OpenTelemetryTracerProducer.java new file mode 100644 index 0000000..5bc2fdf --- /dev/null +++ b/extensions/opentelemetry/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry/OpenTelemetryTracerProducer.java @@ -0,0 +1,53 @@ +/* + * 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.apache.camel.quarkus.component.opentelemetry; + +import java.util.LinkedHashSet; + +import javax.enterprise.inject.Produces; +import javax.inject.Inject; +import javax.inject.Singleton; + +import io.opentelemetry.api.trace.Tracer; +import io.quarkus.arc.DefaultBean; +import org.apache.camel.opentelemetry.CamelQuarkusOpenTelemetryTracer; +import org.apache.camel.opentelemetry.OpenTelemetryTracer; + +@Singleton +public class OpenTelemetryTracerProducer { + + @Inject + CamelOpenTelemetryConfig config; + + @Inject + Tracer tracer; + + @Produces + @Singleton + @DefaultBean + public OpenTelemetryTracer getOpenTelemetry() { + OpenTelemetryTracer openTelemetryTracer = new CamelQuarkusOpenTelemetryTracer(); + if (tracer != null) { + openTelemetryTracer.setTracer(tracer); + if (config.excludePatterns.isPresent()) { + openTelemetryTracer.setExcludePatterns(new LinkedHashSet<>(config.excludePatterns.get())); + } + openTelemetryTracer.setEncoding(config.encoding); + } + return openTelemetryTracer; + } +} diff --git a/extensions/opentelemetry/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/opentelemetry/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 0000000..3ec436e --- /dev/null +++ b/extensions/opentelemetry/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,31 @@ +# +# 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. +# + +# This is a generated file. Do not edit directly! +# To re-generate, run the following command from the top level directory: +# +# mvn -N cq:update-quarkus-metadata +# +--- +name: "Camel OpenTelemetry" +description: "Distributed tracing using OpenTelemetry" +metadata: + guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/opentelemetry.html" + categories: + - "integration" + status: + - "stable" diff --git a/extensions/pom.xml b/extensions/pom.xml index 8c34c99..4e8023f 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -178,6 +178,7 @@ <module>olingo4</module> <module>openapi-java</module> <module>openstack</module> + <module>opentelemetry</module> <module>opentracing</module> <module>optaplanner</module> <module>paho</module> diff --git a/integration-tests/opentelemetry/pom.xml b/integration-tests/opentelemetry/pom.xml new file mode 100644 index 0000000..81095d2 --- /dev/null +++ b/integration-tests/opentelemetry/pom.xml @@ -0,0 +1,140 @@ +<?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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-tests</artifactId> + <version>2.1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-integration-test-opentelemetry</artifactId> + <name>Camel Quarkus :: Integration Tests :: OpenTelemetry</name> + <description>Integration tests for Camel Quarkus OpenTelemetry extension</description> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bom-test</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-opentelemetry</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-platform-http</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy-jsonb</artifactId> + </dependency> + <dependency> + <groupId>io.opentelemetry</groupId> + <artifactId>opentelemetry-sdk-testing</artifactId> + </dependency> + + <!-- test dependencies --> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> + <scope>test</scope> + </dependency> + + <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-opentelemetry-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-platform-http-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + + <profiles> + <profile> + <id>native</id> + <activation> + <property> + <name>native</name> + </property> + </activation> + <properties> + <quarkus.package.type>native</quarkus.package.type> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> + +</project> diff --git a/integration-tests/opentelemetry/src/main/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryResource.java b/integration-tests/opentelemetry/src/main/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryResource.java new file mode 100644 index 0000000..4525aab --- /dev/null +++ b/integration-tests/opentelemetry/src/main/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryResource.java @@ -0,0 +1,65 @@ +/* + * 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.apache.camel.quarkus.component.opentelemetry.it; + +import java.util.Map; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.json.Json; +import javax.json.JsonArray; +import javax.json.JsonArrayBuilder; +import javax.json.JsonObjectBuilder; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter; +import io.opentelemetry.sdk.trace.data.SpanData; + +@Path("/opentelemetry") +@ApplicationScoped +public class OpenTelemetryResource { + + @Inject + InMemorySpanExporter exporter; + + @Path("/spans") + @GET + @Produces(MediaType.APPLICATION_JSON) + public JsonArray getSpans() { + JsonArrayBuilder arrayBuilder = Json.createArrayBuilder(); + + for (SpanData span : exporter.getFinishedSpanItems()) { + + Map<AttributeKey<?>, Object> attributes = span.getAttributes().asMap(); + if (attributes.containsKey(AttributeKey.stringKey("component"))) { + JsonObjectBuilder objectBuilder = Json.createObjectBuilder(); + objectBuilder.add("spanId", span.getSpanId()); + objectBuilder.add("traceId", span.getTraceId()); + + attributes.forEach((k, v) -> objectBuilder.add(String.valueOf(k), v.toString())); + + arrayBuilder.add(objectBuilder.build()); + } + } + + return arrayBuilder.build(); + } +} diff --git a/integration-tests/opentelemetry/src/main/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryRouteBuilder.java b/integration-tests/opentelemetry/src/main/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryRouteBuilder.java new file mode 100644 index 0000000..12a3a0e --- /dev/null +++ b/integration-tests/opentelemetry/src/main/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryRouteBuilder.java @@ -0,0 +1,33 @@ +/* + * 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.apache.camel.quarkus.component.opentelemetry.it; + +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; + +public class OpenTelemetryRouteBuilder extends RouteBuilder { + + @Override + public void configure() throws Exception { + from("platform-http:/opentelemetry/test/trace?httpMethodRestrict=GET") + .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(200)) + .setBody(constant("GET: /opentelemetry/test/trace")); + + from("platform-http:/opentelemetry/test/trace/filtered") + .setBody(constant("GET: /opentelemetry/test/trace/filtered")); + } +} diff --git a/integration-tests/opentelemetry/src/main/java/org/apache/camel/quarkus/component/opentelemetry/it/SpanExporterProducer.java b/integration-tests/opentelemetry/src/main/java/org/apache/camel/quarkus/component/opentelemetry/it/SpanExporterProducer.java new file mode 100644 index 0000000..3a90507 --- /dev/null +++ b/integration-tests/opentelemetry/src/main/java/org/apache/camel/quarkus/component/opentelemetry/it/SpanExporterProducer.java @@ -0,0 +1,33 @@ +/* + * 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.apache.camel.quarkus.component.opentelemetry.it; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.inject.Singleton; + +import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter; + +@ApplicationScoped +public class SpanExporterProducer { + + @Produces + @Singleton + public InMemorySpanExporter createInMemoryExporter() { + return InMemorySpanExporter.create(); + } +} diff --git a/integration-tests/opentelemetry/src/main/resources/application.properties b/integration-tests/opentelemetry/src/main/resources/application.properties new file mode 100644 index 0000000..0d36a0a --- /dev/null +++ b/integration-tests/opentelemetry/src/main/resources/application.properties @@ -0,0 +1,18 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +quarkus.camel.opentelemetry.exclude-patterns = platform-http:/opentelemetry/test/trace/filtered diff --git a/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryIT.java b/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryIT.java new file mode 100644 index 0000000..b53566f --- /dev/null +++ b/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryIT.java @@ -0,0 +1,24 @@ +/* + * 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.apache.camel.quarkus.component.opentelemetry.it; + +import io.quarkus.test.junit.NativeImageTest; + +@NativeImageTest +class OpenTelemetryIT extends OpenTelemetryTest { + +} diff --git a/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryTest.java b/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryTest.java new file mode 100644 index 0000000..3419a4c --- /dev/null +++ b/integration-tests/opentelemetry/src/test/java/org/apache/camel/quarkus/component/opentelemetry/it/OpenTelemetryTest.java @@ -0,0 +1,68 @@ +/* + * 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.apache.camel.quarkus.component.opentelemetry.it; + +import java.util.List; +import java.util.Map; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import io.restassured.path.json.JsonPath; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@QuarkusTest +class OpenTelemetryTest { + + @Test + public void testTraceRoute() { + // Generate messages + for (int i = 0; i < 5; i++) { + RestAssured.get("/opentelemetry/test/trace/") + .then() + .statusCode(200); + + // No spans should be recorded for this route as they are excluded by camel.opentelemetry.exclude-patterns in + // application.properties + RestAssured.get("/opentelemetry/test/trace/filtered") + .then() + .statusCode(200); + } + + // Retrieve recorded spans + JsonPath jsonPath = RestAssured.given() + .get("/opentelemetry/spans") + .then() + .statusCode(200) + .extract() + .body() + .jsonPath(); + + List<Map<String, String>> spans = jsonPath.get(); + assertEquals(5, spans.size()); + + for (Map<String, String> span : spans) { + assertEquals("camel-platform-http", span.get("component")); + assertEquals("200", span.get("http.status_code")); + assertEquals("GET", span.get("http.method")); + assertEquals("platform-http:///opentelemetry/test/trace?httpMethodRestrict=GET", span.get("camel.uri")); + assertTrue(span.get("http.url").endsWith("/opentelemetry/test/trace/")); + } + } +} diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index dc838e3..109698b 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -165,6 +165,7 @@ <module>olingo4</module> <module>openapi-java</module> <module>openstack</module> + <module>opentelemetry</module> <module>opentracing</module> <module>optaplanner</module> <module>paho-mqtt5</module> diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index 3ca210d..7b800b9 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -1695,6 +1695,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-opentelemetry</artifactId> + <version>${camel.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-opentracing</artifactId> <version>${camel.version}</version> </dependency> @@ -4415,6 +4420,16 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-opentelemetry</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-opentelemetry-deployment</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-opentracing</artifactId> <version>${camel-quarkus.version}</version> </dependency> diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml index 0ff9dc6..f694c98 100644 --- a/tooling/scripts/test-categories.yaml +++ b/tooling/scripts/test-categories.yaml @@ -96,6 +96,7 @@ group-06: - lra - micrometer - openstack + - opentelemetry - quartz - rabbitmq - saga