This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch camel-main in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 87769111d2eaea001ec29eab50990382c74b276d Author: Pasquale Congiusti <pasquale.congiu...@gmail.com> AuthorDate: Tue Mar 11 11:27:31 2025 +0100 feat(extension): onboard opentelemetry2 Closes #7119 --- catalog/pom.xml | 13 ++ .../ROOT/examples/others/opentelemetry2.yml | 13 ++ docs/modules/ROOT/nav.adoc | 1 + .../pages/reference/extensions/opentelemetry2.adoc | 149 +++++++++++++++++ .../pages/reference/extensions/telemetry-dev.adoc | 6 +- extensions/opentelemetry2/deployment/pom.xml | 78 +++++++++ .../deployment/Opentelemetry2Processor.java | 47 ++++++ .../deployment/Opentelemetry2Test.java} | 21 ++- extensions/opentelemetry2/pom.xml | 39 +++++ extensions/opentelemetry2/runtime/pom.xml | 115 ++++++++++++++ .../opentelemetry2/runtime/src/main/doc/usage.adoc | 65 ++++++++ .../opentelemetry2/CamelOpenTelemetry2Config.java | 51 ++++++ .../OpenTelemetry2TracerProducer.java | 53 +++++++ .../main/resources/META-INF/quarkus-extension.yaml | 33 ++++ extensions/pom.xml | 1 + .../dev/deployment}/TelemetryDevTest.java | 0 integration-tests/opentelemetry2/pom.xml | 176 +++++++++++++++++++++ .../opentelemetry2/it/OpenTelemetry2Resource.java | 41 +++++ .../it/OpenTelemetry2RouteBuilder.java | 29 ++++ .../opentelemetry2/it/SpanExporterProducer.java | 32 ++++ .../opentelemetry2/it/SpanExporterResource.java | 73 +++++++++ .../src/main/resources/application.properties | 18 +++ .../opentelemetry2/it/Opentelemetry2IT.java | 24 +++ .../opentelemetry2/it/Opentelemetry2Test.java | 65 ++++++++ .../opentelemetry2/it/SpanExporterProducer.java | 32 ++++ integration-tests/pom.xml | 1 + poms/bom/pom.xml | 15 ++ poms/bom/src/main/generated/flattened-full-pom.xml | 15 ++ .../src/main/generated/flattened-reduced-pom.xml | 15 ++ .../generated/flattened-reduced-verbose-pom.xml | 15 ++ tooling/scripts/test-categories.yaml | 1 + 31 files changed, 1223 insertions(+), 14 deletions(-) diff --git a/catalog/pom.xml b/catalog/pom.xml index cc66554e53..5df829cb44 100644 --- a/catalog/pom.xml +++ b/catalog/pom.xml @@ -2970,6 +2970,19 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-opentelemetry2</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-optaplanner</artifactId> diff --git a/docs/modules/ROOT/examples/others/opentelemetry2.yml b/docs/modules/ROOT/examples/others/opentelemetry2.yml new file mode 100644 index 0000000000..fe201358c1 --- /dev/null +++ b/docs/modules/ROOT/examples/others/opentelemetry2.yml @@ -0,0 +1,13 @@ +# Do not edit directly! +# This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page +cqArtifactId: camel-quarkus-opentelemetry2 +cqArtifactIdBase: opentelemetry2 +cqNativeSupported: true +cqStatus: Stable +cqDeprecated: false +cqJvmSince: 3.20.0 +cqNativeSince: 3.20.0 +cqCamelPartName: opentelemetry2 +cqCamelPartTitle: Opentelemetry2 +cqCamelPartDescription: Implementation of Camel Opentelemetry based on the Camel Telemetry spec +cqExtensionPageTitle: Opentelemetry2 diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index c1006cbd6d..847149d576 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -235,6 +235,7 @@ *** xref:reference/extensions/opensearch.adoc[OpenSearch] *** xref:reference/extensions/openstack.adoc[OpenStack] *** xref:reference/extensions/opentelemetry.adoc[OpenTelemetry] +*** xref:reference/extensions/opentelemetry2.adoc[Opentelemetry2] *** xref:reference/extensions/optaplanner.adoc[OptaPlanner] *** xref:reference/extensions/pdf.adoc[PDF] *** xref:reference/extensions/crypto-pgp.adoc[PGP] diff --git a/docs/modules/ROOT/pages/reference/extensions/opentelemetry2.adoc b/docs/modules/ROOT/pages/reference/extensions/opentelemetry2.adoc new file mode 100644 index 0000000000..d7da9f4308 --- /dev/null +++ b/docs/modules/ROOT/pages/reference/extensions/opentelemetry2.adoc @@ -0,0 +1,149 @@ +// Do not edit directly! +// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page +[id="extensions-opentelemetry2"] += Opentelemetry2 +:linkattrs: +:cq-artifact-id: camel-quarkus-opentelemetry2 +:cq-native-supported: true +:cq-status: Stable +:cq-status-deprecation: Stable +:cq-description: Implementation of Camel Opentelemetry based on the Camel Telemetry spec +:cq-deprecated: false +:cq-jvm-since: 3.20.0 +:cq-native-since: 3.20.0 + +ifeval::[{doc-show-badges} == true] +[.badges] +[.badge-key]##JVM since##[.badge-supported]##3.20.0## [.badge-key]##Native since##[.badge-supported]##3.20.0## +endif::[] + +Implementation of Camel Opentelemetry based on the Camel Telemetry spec + +[id="extensions-opentelemetry2-whats-inside"] +== What's inside + +* xref:{cq-camel-components}:others:opentelemetry2.adoc[Opentelemetry2] + +Please refer to the above link for usage and configuration details. + +[id="extensions-opentelemetry2-maven-coordinates"] +== Maven coordinates + +https://{link-quarkus-code-generator}/?extension-search=camel-quarkus-opentelemetry2[Create a new project with this extension on {link-quarkus-code-generator}, window="_blank"] + +Or add the coordinates to your existing project: + +[source,xml] +---- +<dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-opentelemetry2</artifactId> +</dependency> +---- +ifeval::[{doc-show-user-guide-link} == true] +Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. +endif::[] + +[id="extensions-opentelemetry2-usage"] +== 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. + +NOTE: this extension may eventually replace the `opentelemetry` extension. You're invited to change the older extension usage with this one. + +[source,properties] +---- +# OTLP exporter endpoint +quarkus.otel.exporter.otlp.traces.endpoint=http://localhost:4317 +---- + +Refer to the https://quarkus.io/guides/opentelemetry[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:* +---- + +NOTE: The use of the https://opentelemetry.io/docs/zero-code/java/agent/[OpenTelemetry Agent] *is not needed nor recommended*. +Quarkus Extensions and the libraries they provide, are directly instrumented. +Also, the agent does not work in native mode. + +[id="extensions-opentelemetry2-usage-exporters"] +=== Exporters + +Quarkus OpenTelemetry defaults to the standard OTLP exporter defined in OpenTelemetry. +Additional exporters will be available in the Quarkiverse https://github.com/quarkiverse/quarkus-opentelemetry-exporter/blob/main/README.md[quarkus-opentelemetry-exporter] project. + +[id="extensions-opentelemetry2-usage-tracing-cdi-bean-method-execution"] +=== Tracing CDI bean method execution + +When instrumenting the execution of CDI bean methods from Camel routes, you should annotate such methods with `io.opentelemetry.extension.annotations.WithSpan`. Methods annotated with `@WithSpan` will create a new Span and establish any required relationships with the current Trace context. + +For example, to instrument a CDI bean from a Camel route, first ensure the appropriate methods are annotated with `@WithSpan`. + +[source,java] +---- +@ApplicationScoped +@Named("myBean") +public class MyBean { + @WithSpan + public String greet() { + return "Hello World!"; + } +} +---- + +Next, use the bean in your Camel route. + +IMPORTANT: To ensure that the sequence of recorded spans is correct, you must use the full `to("bean:")` endpoint URI and not the shortened `.bean()` EIP DSL method. + +[source,java] +---- +public class MyRoutes extends RouteBuilder { + @Override + public void configure() throws Exception { + from("direct:executeBean") + .to("bean:myBean?method=greet"); + } +} +---- + +There is more information about CDI instrumentation in the https://quarkus.io/guides/opentelemetry#cdi[Quarkus OpenTelemetry guide]. + + +[id="extensions-opentelemetry2-additional-camel-quarkus-configuration"] +== Additional Camel Quarkus configuration + +[width="100%",cols="80,5,15",options="header"] +|=== +| Configuration property | Type | Default + + +a| [[quarkus.camel.opentelemetry2.exclude-patterns]]`link:#quarkus.camel.opentelemetry2.exclude-patterns[quarkus.camel.opentelemetry2.exclude-patterns]` + +Sets whether to disable tracing for endpoint URIs or Processor ids that match the given comma separated 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` +| + +a| [[quarkus.camel.opentelemetry2.trace-processors]]`link:#quarkus.camel.opentelemetry2.trace-processors[quarkus.camel.opentelemetry2.trace-processors]` + +Sets whether to create new OpenTelemetry spans for each Camel Processor. Use the excludePatterns property to filter +out Processors. +| `boolean` +| `false` +|=== + +[.configuration-legend] +{doc-link-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/pages/reference/extensions/telemetry-dev.adoc b/docs/modules/ROOT/pages/reference/extensions/telemetry-dev.adoc index 74334fe47e..f176e43e88 100644 --- a/docs/modules/ROOT/pages/reference/extensions/telemetry-dev.adoc +++ b/docs/modules/ROOT/pages/reference/extensions/telemetry-dev.adoc @@ -52,7 +52,7 @@ endif::[] | Configuration property | Type | Default -| [[quarkus.camel.telemetrydev.exclude-patterns]]`link:#quarkus.camel.telemetrydev.exclude-patterns[quarkus.camel.telemetryDev.exclude-patterns]` +a| [[quarkus.camel.telemetrydev.exclude-patterns]]`link:#quarkus.camel.telemetrydev.exclude-patterns[quarkus.camel.telemetryDev.exclude-patterns]` Sets whether to disable tracing for endpoint URIs or Processor ids that match the given comma separated patterns. The pattern can take the following forms: @@ -65,14 +65,14 @@ pattern can take the following forms: | `string` | -| [[quarkus.camel.telemetrydev.trace-processors]]`link:#quarkus.camel.telemetrydev.trace-processors[quarkus.camel.telemetryDev.trace-processors]` +a| [[quarkus.camel.telemetrydev.trace-processors]]`link:#quarkus.camel.telemetrydev.trace-processors[quarkus.camel.telemetryDev.trace-processors]` Sets whether to create new OpenTelemetry spans for each Camel Processor. Use the excludePatterns property to filter out Processors. | `boolean` | `false` -| [[quarkus.camel.telemetrydev.trace-format]]`link:#quarkus.camel.telemetrydev.trace-format[quarkus.camel.telemetryDev.trace-format]` +a| [[quarkus.camel.telemetrydev.trace-format]]`link:#quarkus.camel.telemetrydev.trace-format[quarkus.camel.telemetryDev.trace-format]` The output format for traces | `string` diff --git a/extensions/opentelemetry2/deployment/pom.xml b/extensions/opentelemetry2/deployment/pom.xml new file mode 100644 index 0000000000..7dbbbf5233 --- /dev/null +++ b/extensions/opentelemetry2/deployment/pom.xml @@ -0,0 +1,78 @@ +<?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-opentelemetry2-parent</artifactId> + <version>3.20.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-opentelemetry2-deployment</artifactId> + <name>Camel Quarkus :: Opentelemetry2 :: Deployment</name> + + <dependencies> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-opentelemetry-deployment</artifactId> + <exclusions> + <exclusion> + <groupId>com.google.code.findbugs</groupId> + <artifactId>jsr305</artifactId> + </exclusion> + </exclusions> + </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-opentelemetry2</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5-internal</artifactId> + <scope>test</scope> + </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/opentelemetry2/deployment/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/deployment/Opentelemetry2Processor.java b/extensions/opentelemetry2/deployment/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/deployment/Opentelemetry2Processor.java new file mode 100644 index 0000000000..01e70c3958 --- /dev/null +++ b/extensions/opentelemetry2/deployment/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/deployment/Opentelemetry2Processor.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.quarkus.component.opentelemetry2.deployment; + +import io.quarkus.arc.deployment.AdditionalBeanBuildItem; +import io.quarkus.arc.deployment.UnremovableBeanBuildItem; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.FeatureBuildItem; +import org.apache.camel.quarkus.component.opentelemetry2.OpenTelemetry2TracerProducer; +import org.apache.camel.telemetry.Tracer; + +class Opentelemetry2Processor { + + private static final String FEATURE = "camel-opentelemetry2"; + + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); + } + + @BuildStep + AdditionalBeanBuildItem telemetryDevTracerProducerBean() { + return AdditionalBeanBuildItem.builder() + .setUnremovable() + .addBeanClass(OpenTelemetry2TracerProducer.class) + .build(); + } + + @BuildStep + UnremovableBeanBuildItem camelTracerUnremovableBean() { + return UnremovableBeanBuildItem.beanTypes(Tracer.class); + } +} diff --git a/extensions/telemetry-dev/deployment/src/test/java/TelemetryDevTest.java b/extensions/opentelemetry2/deployment/src/test/java/org/apache/camel/quarkus/component/opentelemetry2/deployment/Opentelemetry2Test.java similarity index 70% copy from extensions/telemetry-dev/deployment/src/test/java/TelemetryDevTest.java copy to extensions/opentelemetry2/deployment/src/test/java/org/apache/camel/quarkus/component/opentelemetry2/deployment/Opentelemetry2Test.java index eddb44788d..5306f0a529 100644 --- a/extensions/telemetry-dev/deployment/src/test/java/TelemetryDevTest.java +++ b/extensions/opentelemetry2/deployment/src/test/java/org/apache/camel/quarkus/component/opentelemetry2/deployment/Opentelemetry2Test.java @@ -14,14 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.quarkus.component.telemetry.dev.deployment; + +package org.apache.camel.quarkus.component.opentelemetry2.deployment; import java.util.Set; import io.quarkus.test.QuarkusUnitTest; import jakarta.inject.Inject; import org.apache.camel.CamelContext; -import org.apache.camel.telemetrydev.TelemetryDevTracer; +import org.apache.camel.opentelemetry2.OpenTelemetryTracer; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.jupiter.api.Test; @@ -31,28 +32,26 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertTrue; -public class TelemetryDevTest { +public class Opentelemetry2Test { private static final String EXCLUDE_PATTERNS = "platform-http:*,platform-http:/prefix/.*"; @RegisterExtension static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() - .overrideConfigKey("quarkus.camel.telemetryDev.trace-format", "tree") - .overrideConfigKey("quarkus.camel.telemetryDev.exclude-patterns", EXCLUDE_PATTERNS) - .overrideConfigKey("quarkus.camel.telemetryDev.trace-processors", "true") + .overrideConfigKey("quarkus.camel.opentelemetry2.exclude-patterns", EXCLUDE_PATTERNS) + .overrideConfigKey("quarkus.camel.opentelemetry2.trace-processors", "true") .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); @Inject CamelContext context; @Test - public void camelTelemetryDevTracerRegistryBeanNotNull() { - Set<TelemetryDevTracer> tracers = context.getRegistry().findByType(TelemetryDevTracer.class); + public void camelOpentelemetry2TracerRegistryBeanNotNull() { + Set<OpenTelemetryTracer> tracers = context.getRegistry().findByType(OpenTelemetryTracer.class); assertEquals(1, tracers.size()); - TelemetryDevTracer tracer = tracers.iterator().next(); - assertInstanceOf(TelemetryDevTracer.class, tracer); - assertEquals("tree", tracer.getTraceFormat()); + OpenTelemetryTracer tracer = tracers.iterator().next(); + assertInstanceOf(OpenTelemetryTracer.class, tracer); assertEquals(EXCLUDE_PATTERNS, tracer.getExcludePatterns()); assertTrue(tracer.isTraceProcessors()); } diff --git a/extensions/opentelemetry2/pom.xml b/extensions/opentelemetry2/pom.xml new file mode 100644 index 0000000000..f8318e9850 --- /dev/null +++ b/extensions/opentelemetry2/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-extensions</artifactId> + <version>3.20.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-opentelemetry2-parent</artifactId> + <name>Camel Quarkus :: Opentelemetry2</name> + <packaging>pom</packaging> + + <modules> + <module>deployment</module> + <module>runtime</module> + </modules> +</project> diff --git a/extensions/opentelemetry2/runtime/pom.xml b/extensions/opentelemetry2/runtime/pom.xml new file mode 100644 index 0000000000..a373dcfa88 --- /dev/null +++ b/extensions/opentelemetry2/runtime/pom.xml @@ -0,0 +1,115 @@ +<?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-opentelemetry2-parent</artifactId> + <version>3.20.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-opentelemetry2</artifactId> + <name>Camel Quarkus :: Opentelemetry2 :: Runtime</name> + <description>Implementation of Camel Opentelemetry based on the Camel Telemetry spec</description> + + <properties> + <camel.quarkus.jvmSince>3.20.0</camel.quarkus.jvmSince> + <camel.quarkus.nativeSince>3.20.0</camel.quarkus.nativeSince> + </properties> + + <dependencies> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-opentelemetry</artifactId> + <exclusions> + <exclusion> + <groupId>com.google.code.findbugs</groupId> + <artifactId>jsr305</artifactId> + </exclusion> + <exclusion> + <groupId>com.google.guava</groupId> + <artifactId>listenablefuture</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-opentelemetry2</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-extension-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/opentelemetry2/runtime/src/main/doc/usage.adoc b/extensions/opentelemetry2/runtime/src/main/doc/usage.adoc new file mode 100644 index 0000000000..97077e0a13 --- /dev/null +++ b/extensions/opentelemetry2/runtime/src/main/doc/usage.adoc @@ -0,0 +1,65 @@ +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. + +NOTE: this extension may eventually replace the `opentelemetry` extension. You're invited to change the older extension usage with this one. + +[source,properties] +---- +# OTLP exporter endpoint +quarkus.otel.exporter.otlp.traces.endpoint=http://localhost:4317 +---- + +Refer to the https://quarkus.io/guides/opentelemetry[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:* +---- + +NOTE: The use of the https://opentelemetry.io/docs/zero-code/java/agent/[OpenTelemetry Agent] *is not needed nor recommended*. +Quarkus Extensions and the libraries they provide, are directly instrumented. +Also, the agent does not work in native mode. + +=== Exporters + +Quarkus OpenTelemetry defaults to the standard OTLP exporter defined in OpenTelemetry. +Additional exporters will be available in the Quarkiverse https://github.com/quarkiverse/quarkus-opentelemetry-exporter/blob/main/README.md[quarkus-opentelemetry-exporter] project. + +=== Tracing CDI bean method execution + +When instrumenting the execution of CDI bean methods from Camel routes, you should annotate such methods with `io.opentelemetry.extension.annotations.WithSpan`. Methods annotated with `@WithSpan` will create a new Span and establish any required relationships with the current Trace context. + +For example, to instrument a CDI bean from a Camel route, first ensure the appropriate methods are annotated with `@WithSpan`. + +[source,java] +---- +@ApplicationScoped +@Named("myBean") +public class MyBean { + @WithSpan + public String greet() { + return "Hello World!"; + } +} +---- + +Next, use the bean in your Camel route. + +IMPORTANT: To ensure that the sequence of recorded spans is correct, you must use the full `to("bean:")` endpoint URI and not the shortened `.bean()` EIP DSL method. + +[source,java] +---- +public class MyRoutes extends RouteBuilder { + @Override + public void configure() throws Exception { + from("direct:executeBean") + .to("bean:myBean?method=greet"); + } +} +---- + +There is more information about CDI instrumentation in the https://quarkus.io/guides/opentelemetry#cdi[Quarkus OpenTelemetry guide]. diff --git a/extensions/opentelemetry2/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/CamelOpenTelemetry2Config.java b/extensions/opentelemetry2/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/CamelOpenTelemetry2Config.java new file mode 100644 index 0000000000..f310af6c42 --- /dev/null +++ b/extensions/opentelemetry2/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/CamelOpenTelemetry2Config.java @@ -0,0 +1,51 @@ +/* + * 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.opentelemetry2; + +import java.util.Optional; + +import io.quarkus.runtime.annotations.ConfigPhase; +import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; + +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +@ConfigMapping(prefix = "quarkus.camel.opentelemetry2") +public interface CamelOpenTelemetry2Config { + /** + * Sets whether to disable tracing for endpoint URIs or Processor ids that match the given comma separated 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/.++*++ + * + * @asciidoclet + */ + Optional<String> excludePatterns(); + + /** + * Sets whether to create new OpenTelemetry spans for each Camel Processor. Use the excludePatterns property to filter + * out Processors. + * + * @asciidoclet + */ + @WithDefault("false") + boolean traceProcessors(); +} diff --git a/extensions/opentelemetry2/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/OpenTelemetry2TracerProducer.java b/extensions/opentelemetry2/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/OpenTelemetry2TracerProducer.java new file mode 100644 index 0000000000..fdc4c67b41 --- /dev/null +++ b/extensions/opentelemetry2/runtime/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/OpenTelemetry2TracerProducer.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.opentelemetry2; + +import io.quarkus.arc.DefaultBean; +import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig; +import jakarta.enterprise.inject.Produces; +import jakarta.inject.Inject; +import jakarta.inject.Singleton; +import org.apache.camel.opentelemetry2.OpenTelemetryTracer; + +@Singleton +public class OpenTelemetry2TracerProducer { + + @Inject + CamelOpenTelemetry2Config config; + + @Inject + OTelRuntimeConfig oTelRuntimeConfig; + + @Produces + @Singleton + @DefaultBean + public OpenTelemetryTracer getOpenTelemetry() { + if (!oTelRuntimeConfig.sdkDisabled()) { + OpenTelemetryTracer openTelemetryTracer = new OpenTelemetryTracer(); + if (config.excludePatterns().isPresent()) { + openTelemetryTracer.setExcludePatterns(config.excludePatterns().get()); + } + + if (config.traceProcessors()) { + openTelemetryTracer.setTraceProcessors(config.traceProcessors()); + } + + return openTelemetryTracer; + } + return null; + } +} diff --git a/extensions/opentelemetry2/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/opentelemetry2/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 0000000000..a0cea5c6c9 --- /dev/null +++ b/extensions/opentelemetry2/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -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. +# + +# 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 Opentelemetry2" +description: "Implementation of Camel Opentelemetry based on the Camel Telemetry spec" +metadata: + icon-url: "https://raw.githubusercontent.com/apache/camel-website/main/antora-ui-camel/src/img/logo-d.svg" + sponsor: "Apache Software Foundation" + guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/opentelemetry2.html" + categories: + - "integration" + status: + - "stable" diff --git a/extensions/pom.xml b/extensions/pom.xml index abc67c9092..18808302dc 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -203,6 +203,7 @@ <module>openapi-java</module> <module>openstack</module> <module>opentelemetry</module> + <module>opentelemetry2</module> <module>optaplanner</module> <module>paho</module> <module>paho-mqtt5</module> diff --git a/extensions/telemetry-dev/deployment/src/test/java/TelemetryDevTest.java b/extensions/telemetry-dev/deployment/src/test/java/org/apache/camel/quarkus/component/telemetry/dev/deployment/TelemetryDevTest.java similarity index 100% rename from extensions/telemetry-dev/deployment/src/test/java/TelemetryDevTest.java rename to extensions/telemetry-dev/deployment/src/test/java/org/apache/camel/quarkus/component/telemetry/dev/deployment/TelemetryDevTest.java diff --git a/integration-tests/opentelemetry2/pom.xml b/integration-tests/opentelemetry2/pom.xml new file mode 100644 index 0000000000..1cc575fb48 --- /dev/null +++ b/integration-tests/opentelemetry2/pom.xml @@ -0,0 +1,176 @@ +<?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-it</artifactId> + <version>3.20.0-SNAPSHOT</version> + <relativePath>../../poms/build-parent-it/pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-integration-test-opentelemetry2</artifactId> + <name>Camel Quarkus :: Integration Tests :: Opentelemetry2</name> + <description>Integration tests for Camel Quarkus Opentelemetry2 extension</description> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-direct</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-timer</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-log</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-opentelemetry2</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> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <profiles> + <profile> + <id>native</id> + <activation> + <property> + <name>native</name> + </property> + </activation> + <properties> + <quarkus.native.enabled>true</quarkus.native.enabled> + </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> + <profile> + <id>virtualDependencies</id> + <activation> + <property> + <name>!noVirtualDependencies</name> + </property> + </activation> + <dependencies> + <!-- 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-direct-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-log-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-opentelemetry2-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-timer-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + </profile> + </profiles> + +</project> diff --git a/integration-tests/opentelemetry2/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/it/OpenTelemetry2Resource.java b/integration-tests/opentelemetry2/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/it/OpenTelemetry2Resource.java new file mode 100644 index 0000000000..8b3dfee289 --- /dev/null +++ b/integration-tests/opentelemetry2/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/it/OpenTelemetry2Resource.java @@ -0,0 +1,41 @@ +/* + * 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.opentelemetry2.it; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import org.apache.camel.ProducerTemplate; + +@Path("/opentelemetry2") +@ApplicationScoped +public class OpenTelemetry2Resource { + + @Inject + ProducerTemplate producerTemplate; + + @Path("/trace") + @GET + @Produces(MediaType.TEXT_PLAIN) + public String traceRoute() { + return producerTemplate.requestBody("direct:start", null, String.class); + } + +} diff --git a/integration-tests/opentelemetry2/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/it/OpenTelemetry2RouteBuilder.java b/integration-tests/opentelemetry2/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/it/OpenTelemetry2RouteBuilder.java new file mode 100644 index 0000000000..7722741cf6 --- /dev/null +++ b/integration-tests/opentelemetry2/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/it/OpenTelemetry2RouteBuilder.java @@ -0,0 +1,29 @@ +/* + * 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.opentelemetry2.it; + +import org.apache.camel.builder.RouteBuilder; + +public class OpenTelemetry2RouteBuilder extends RouteBuilder { + + @Override + public void configure() throws Exception { + from("direct:start") + .setBody().constant("Traced direct:start") + .to("log:info"); + } +} diff --git a/integration-tests/opentelemetry2/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/it/SpanExporterProducer.java b/integration-tests/opentelemetry2/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/it/SpanExporterProducer.java new file mode 100644 index 0000000000..9262412a6e --- /dev/null +++ b/integration-tests/opentelemetry2/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/it/SpanExporterProducer.java @@ -0,0 +1,32 @@ +/* + * 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.opentelemetry2.it; + +import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Produces; +import jakarta.inject.Singleton; + +@ApplicationScoped +public class SpanExporterProducer { + + @Produces + @Singleton + public InMemorySpanExporter createInMemoryExporter() { + return InMemorySpanExporter.create(); + } +} diff --git a/integration-tests/opentelemetry2/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/it/SpanExporterResource.java b/integration-tests/opentelemetry2/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/it/SpanExporterResource.java new file mode 100644 index 0000000000..cf90908882 --- /dev/null +++ b/integration-tests/opentelemetry2/src/main/java/org/apache/camel/quarkus/component/opentelemetry2/it/SpanExporterResource.java @@ -0,0 +1,73 @@ +/* + * 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.opentelemetry2.it; + +import java.util.Map; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter; +import io.opentelemetry.sdk.trace.data.SpanData; +import jakarta.inject.Inject; +import jakarta.json.Json; +import jakarta.json.JsonArray; +import jakarta.json.JsonArrayBuilder; +import jakarta.json.JsonObjectBuilder; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/opentelemetry2/exporter") +public class SpanExporterResource { + + @Inject + InMemorySpanExporter exporter; + + @Path("/spans") + @GET + @Produces(MediaType.APPLICATION_JSON) + public JsonArray getSpans() { + JsonArrayBuilder arrayBuilder = Json.createArrayBuilder(); + + for (SpanData span : exporter.getFinishedSpanItems()) { + if (span.getName().contains("GET /")) { + // Ignore any trace events on this resource + continue; + } + + Map<AttributeKey<?>, Object> attributes = span.getAttributes().asMap(); + JsonObjectBuilder objectBuilder = Json.createObjectBuilder(); + objectBuilder.add("spanId", span.getSpanId()); + objectBuilder.add("traceId", span.getTraceId()); + objectBuilder.add("parentId", span.getParentSpanId()); + objectBuilder.add("kind", span.getKind().name()); + + attributes.forEach((k, v) -> objectBuilder.add(String.valueOf(k), v.toString())); + + arrayBuilder.add(objectBuilder.build()); + } + + return arrayBuilder.build(); + } + + @POST + @Path("/spans/reset") + public void resetSpanExporter() { + exporter.reset(); + } +} diff --git a/integration-tests/opentelemetry2/src/main/resources/application.properties b/integration-tests/opentelemetry2/src/main/resources/application.properties new file mode 100644 index 0000000000..968c0b4d2c --- /dev/null +++ b/integration-tests/opentelemetry2/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.otel.bsp.schedule.delay=1 +quarkus.otel.bsp.export.timeout=5s \ No newline at end of file diff --git a/integration-tests/opentelemetry2/src/test/java/org/apache/camel/quarkus/component/opentelemetry2/it/Opentelemetry2IT.java b/integration-tests/opentelemetry2/src/test/java/org/apache/camel/quarkus/component/opentelemetry2/it/Opentelemetry2IT.java new file mode 100644 index 0000000000..dd5082fbfa --- /dev/null +++ b/integration-tests/opentelemetry2/src/test/java/org/apache/camel/quarkus/component/opentelemetry2/it/Opentelemetry2IT.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.opentelemetry2.it; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class Opentelemetry2IT extends Opentelemetry2Test { + +} diff --git a/integration-tests/opentelemetry2/src/test/java/org/apache/camel/quarkus/component/opentelemetry2/it/Opentelemetry2Test.java b/integration-tests/opentelemetry2/src/test/java/org/apache/camel/quarkus/component/opentelemetry2/it/Opentelemetry2Test.java new file mode 100644 index 0000000000..f1f0ff8287 --- /dev/null +++ b/integration-tests/opentelemetry2/src/test/java/org/apache/camel/quarkus/component/opentelemetry2/it/Opentelemetry2Test.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.opentelemetry2.it; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import org.junit.jupiter.api.Test; + +import static org.awaitility.Awaitility.await; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertEquals; + +@QuarkusTest +class Opentelemetry2Test { + + static List<Map<String, String>> getSpans() { + return RestAssured.given() + .get("/opentelemetry2/exporter/spans") + .then() + .statusCode(200) + .extract() + .body() + .jsonPath() + .get(); + } + + @Test + public void testTracedCamelRoute() throws IOException, InterruptedException { + RestAssured.get("/opentelemetry2/trace") + .then() + .statusCode(200) + .body(equalTo("Traced direct:start")); + + await().atMost(30, TimeUnit.SECONDS).pollDelay(50, TimeUnit.MILLISECONDS).until(() -> getSpans().size() == 3); + List<Map<String, String>> spans = getSpans(); + assertEquals(3, spans.size()); + //Same trace + assertEquals(spans.get(2).get("traceId"), spans.get(1).get("traceId")); + assertEquals(spans.get(2).get("traceId"), spans.get(0).get("traceId")); + // Parent relationship + assertEquals("0000000000000000", spans.get(2).get("parentId")); + assertEquals(spans.get(2).get("spanId"), spans.get(1).get("parentId")); + assertEquals(spans.get(1).get("spanId"), spans.get(0).get("parentId")); + } + +} diff --git a/integration-tests/opentelemetry2/src/test/java/org/apache/camel/quarkus/component/opentelemetry2/it/SpanExporterProducer.java b/integration-tests/opentelemetry2/src/test/java/org/apache/camel/quarkus/component/opentelemetry2/it/SpanExporterProducer.java new file mode 100644 index 0000000000..9262412a6e --- /dev/null +++ b/integration-tests/opentelemetry2/src/test/java/org/apache/camel/quarkus/component/opentelemetry2/it/SpanExporterProducer.java @@ -0,0 +1,32 @@ +/* + * 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.opentelemetry2.it; + +import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Produces; +import jakarta.inject.Singleton; + +@ApplicationScoped +public class SpanExporterProducer { + + @Produces + @Singleton + public InMemorySpanExporter createInMemoryExporter() { + return InMemorySpanExporter.create(); + } +} diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index e0253465ce..068ff2b2eb 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -181,6 +181,7 @@ <module>openapi-java</module> <module>openstack</module> <module>opentelemetry</module> + <module>opentelemetry2</module> <module>optaplanner</module> <module>paho</module> <module>paho-mqtt5</module> diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index 0c9f528e86..28aae206b6 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -2204,6 +2204,11 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-opentelemetry2</artifactId> + <version>${camel.version}</version> + </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-optaplanner</artifactId> @@ -5252,6 +5257,16 @@ <artifactId>camel-quarkus-opentelemetry-deployment</artifactId> <version>${camel-quarkus.version}</version> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-opentelemetry2</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-opentelemetry2-deployment</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-optaplanner</artifactId> diff --git a/poms/bom/src/main/generated/flattened-full-pom.xml b/poms/bom/src/main/generated/flattened-full-pom.xml index 8e1af6a596..02facbcdac 100644 --- a/poms/bom/src/main/generated/flattened-full-pom.xml +++ b/poms/bom/src/main/generated/flattened-full-pom.xml @@ -2140,6 +2140,11 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>org.apache.camel</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <artifactId>camel-opentelemetry2</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <version>4.11.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + </dependency> <dependency> <groupId>org.apache.camel</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <artifactId>camel-optaplanner</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> @@ -5176,6 +5181,16 @@ <artifactId>camel-quarkus-opentelemetry-deployment</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <version>3.20.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <artifactId>camel-quarkus-opentelemetry2</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <version>3.20.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <artifactId>camel-quarkus-opentelemetry2-deployment</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <version>3.20.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <artifactId>camel-quarkus-optaplanner</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> diff --git a/poms/bom/src/main/generated/flattened-reduced-pom.xml b/poms/bom/src/main/generated/flattened-reduced-pom.xml index 4348c0b5af..8daed4e3d9 100644 --- a/poms/bom/src/main/generated/flattened-reduced-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-pom.xml @@ -2130,6 +2130,11 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-opentelemetry2</artifactId> + <version>4.11.0-SNAPSHOT</version> + </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-optaplanner</artifactId> @@ -5166,6 +5171,16 @@ <artifactId>camel-quarkus-opentelemetry-deployment</artifactId> <version>3.20.0-SNAPSHOT</version> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-opentelemetry2</artifactId> + <version>3.20.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-opentelemetry2-deployment</artifactId> + <version>3.20.0-SNAPSHOT</version> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-optaplanner</artifactId> diff --git a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml index 75a7c14324..afc656c1a3 100644 --- a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml @@ -2130,6 +2130,11 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>org.apache.camel</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <artifactId>camel-opentelemetry2</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <version>4.11.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + </dependency> <dependency> <groupId>org.apache.camel</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <artifactId>camel-optaplanner</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> @@ -5166,6 +5171,16 @@ <artifactId>camel-quarkus-opentelemetry-deployment</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <version>3.20.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <artifactId>camel-quarkus-opentelemetry2</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <version>3.20.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <artifactId>camel-quarkus-opentelemetry2-deployment</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + <version>3.20.0-SNAPSHOT</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> <artifactId>camel-quarkus-optaplanner</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} --> diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml index f6fd3c45e1..32c3c0ba51 100644 --- a/tooling/scripts/test-categories.yaml +++ b/tooling/scripts/test-categories.yaml @@ -219,6 +219,7 @@ group-12: - rest - rest-openapi - vertx-websocket + - opentelemetry2 group-13: - fhir - google-bigquery