Skip to content

Commit

Permalink
OpenTelemetry OTLP/HTTP exporter
Browse files Browse the repository at this point in the history
Adds an extension to provide on OTLP/HTTP exporter as described here https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlphttp and as implemented by the OpenTelemetry SDK. This as an alternative to the standard OTLP/gRPC exporter.

Fixes quarkusio#21535
  • Loading branch information
knutwannheden committed Nov 30, 2021
1 parent d675300 commit 57d39e9
Show file tree
Hide file tree
Showing 15 changed files with 561 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2658,6 +2658,16 @@
<artifactId>quarkus-opentelemetry-exporter-otlp</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-exporter-otlp-http-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-exporter-otlp-http</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Quarkus test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public enum Feature {
OPENTELEMETRY,
OPENTELEMETRY_JAEGER_EXPORTER,
OPENTELEMETRY_OTLP_EXPORTER,
OPENTELEMETRY_OTLP_HTTP_EXPORTER,
PICOCLI,
QUARTZ,
QUTE,
Expand Down
17 changes: 17 additions & 0 deletions docs/src/main/asciidoc/opentelemetry.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ Hit `CTRL+C` to stop the application.
Some use cases will require custom configuration of OpenTelemetry.
These sections will outline what is necessary to properly configure it.

=== Exporter
Quarkus currently has support for the following OpenTelemetry exporters:

* OTLP/gRPC (as shown in the example above) provided by the extension `quarkus-opentelemetry-exporter-otlp`
* OTLP/HTTP provided by the extension `quarkus-opentelemetry-exporter-otlp-http`
* Jaeger provided by the extension `quarkus-opentelemetry-exporter-jaeger`

The configuration options for each of these are listed under <<configuration-reference>>.

=== ID Generator
The OpenTelemetry extension will use by default a random https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#id-generators[ID Generator]
when creating the trace and span identifier.
Expand Down Expand Up @@ -349,4 +358,12 @@ which retrieves the OpenTelemetry `Context` to extract the current span for prop
== OpenTelemetry Configuration Reference

include::{generated-dir}/config/quarkus-opentelemetry.adoc[leveloffset=+1, opts=optional]

=== OpenTelemetry OTLP/gRPC Exporter
include::{generated-dir}/config/quarkus-opentelemetry-exporter-otlp.adoc[leveloffset=+1, opts=optional]

=== OpenTelemetry OTLP/HTTP Exporter
include::{generated-dir}/config/quarkus-opentelemetry-exporter-otlp-http.adoc[leveloffset=+1, opts=optional]

=== OpenTelemetry Jaeger Exporter
include::{generated-dir}/config/quarkus-opentelemetry-exporter-jaeger.adoc[leveloffset=+1, opts=optional]
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-exporter-otlp-http-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>

<artifactId>quarkus-opentelemetry-exporter-otlp-http-deployment</artifactId>
<name>Quarkus - OpenTelemetry Exporter - OTLP/HTTP - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-exporter-otlp-http</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-deployment</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</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>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.quarkus.opentelemetry.exporter.otlp.http.deployment;

import java.util.function.BooleanSupplier;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.opentelemetry.exporter.otlp.http.runtime.OtlpHttpExporterConfig;
import io.quarkus.opentelemetry.exporter.otlp.http.runtime.OtlpHttpExporterProvider;
import io.quarkus.opentelemetry.exporter.otlp.http.runtime.OtlpHttpRecorder;

public class OtlpHttpExporterProcessor {

static class OtlpHttpExporterEnabled implements BooleanSupplier {
OtlpHttpExporterConfig.OtlpHttpExporterBuildConfig otlpHttpExporterConfig;

public boolean getAsBoolean() {
return otlpHttpExporterConfig.enabled;
}
}

@BuildStep(onlyIf = OtlpHttpExporterEnabled.class)
FeatureBuildItem feature() {
return new FeatureBuildItem(Feature.OPENTELEMETRY_OTLP_HTTP_EXPORTER);
}

@BuildStep(onlyIf = OtlpHttpExporterEnabled.class)
AdditionalBeanBuildItem createBatchSpanProcessor() {
return AdditionalBeanBuildItem.builder()
.addBeanClass(OtlpHttpExporterProvider.class)
.setUnremovable().build();
}

@BuildStep(onlyIf = OtlpHttpExporterEnabled.class)
@Record(ExecutionTime.RUNTIME_INIT)
void installBatchSpanProcessorForOtlpHttp(OtlpHttpRecorder recorder,
LaunchModeBuildItem launchModeBuildItem,
OtlpHttpExporterConfig.OtlpHttpExporterRuntimeConfig runtimeConfig) {
recorder.installBatchSpanProcessorForOtlpHttp(runtimeConfig, launchModeBuildItem.getLaunchMode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.quarkus.opentelemetry.exporter.otlp.http.deployment;

import javax.inject.Inject;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.opentelemetry.api.OpenTelemetry;
import io.quarkus.test.QuarkusUnitTest;

public class OtlpHttpExporterBadEndpointTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withEmptyApplication()
.overrideConfigKey("quarkus.opentelemetry.tracer.exporter.otlp-http.endpoint", "httz://nada:zero")
.setExpectedException(IllegalStateException.class);

@Inject
OpenTelemetry openTelemetry;

@Test
void failStart() {
Assertions.fail("Test should not be run as deployment should fail");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.quarkus.opentelemetry.exporter.otlp.http.deployment;

import javax.enterprise.inject.Instance;
import javax.inject.Inject;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.opentelemetry.api.OpenTelemetry;
import io.quarkus.opentelemetry.exporter.otlp.http.runtime.LateBoundBatchSpanProcessor;
import io.quarkus.test.QuarkusUnitTest;

public class OtlpHttpExporterDisabledTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withEmptyApplication()
.overrideConfigKey("quarkus.opentelemetry.tracer.exporter.otlp-http.enabled", "false");

@Inject
OpenTelemetry openTelemetry;

@Inject
Instance<LateBoundBatchSpanProcessor> lateBoundBatchSpanProcessorInstance;

@Test
void testOpenTelemetryButNoBatchSpanProcessor() {
Assertions.assertNotNull(openTelemetry);
Assertions.assertFalse(lateBoundBatchSpanProcessorInstance.isResolvable());
}
}
20 changes: 20 additions & 0 deletions extensions/opentelemetry/opentelemetry-exporter-otlp-http/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-parent-aggregator</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-opentelemetry-exporter-otlp-http-parent</artifactId>
<name>Quarkus - OpenTelemetry Exporter - OTLP/HTTP</name>
<packaging>pom</packaging>
<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-exporter-otlp-http-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>

<artifactId>quarkus-opentelemetry-exporter-otlp-http</artifactId>
<name>Quarkus - OpenTelemetry Exporter - OTLP/HTTP - Runtime</name>
<description>Enable OTLP/HTTP Exporter for OpenTelemetry</description>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry</artifactId>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp-http-trace</artifactId>
<exclusions>
<exclusion>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp-common</artifactId>
<exclusions>
<exclusion>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>svm</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit 57d39e9

Please sign in to comment.