Skip to content

Commit

Permalink
Ensure that the presence of OpenTelemetry does not break Jib builds
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Jan 13, 2022
1 parent 9366542 commit b6a693c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public class JibProcessor {
private static final String JAVA_17_BASE_IMAGE = "registry.access.redhat.com/ubi8/openjdk-17-runtime:1.10";
private static final String JAVA_11_BASE_IMAGE = "registry.access.redhat.com/ubi8/openjdk-11-runtime:1.10";

private static final String OPENTELEMETRY_CONTEXT_CONTEXT_STORAGE_PROVIDER_SYS_PROP = "io.opentelemetry.context.contextStorageProvider";

@BuildStep
public AvailableContainerImageExtensionBuildItem availability() {
return new AvailableContainerImageExtensionBuildItem(JIB);
Expand Down Expand Up @@ -205,11 +207,20 @@ public void buildFromNative(ContainerImageConfig containerImageConfig, JibConfig
private JibContainer containerize(ContainerImageConfig containerImageConfig,
JibConfig jibConfig, ContainerImageInfoBuildItem containerImage, JibContainerBuilder jibContainerBuilder,
boolean pushRequested) {

Containerizer containerizer = createContainerizer(containerImageConfig, jibConfig, containerImage, pushRequested);
for (String additionalTag : containerImage.getAdditionalTags()) {
containerizer.withAdditionalTag(additionalTag);
}
String previousContextStorageSysProp = null;
try {
// Jib uses the Google HTTP Client under the hood which attempts to record traces via OpenCensus which is wired
// to delegate to OpenTelemetry.
// This can lead to problems with the Quarkus OpenTelemetry extension which expects Vert.x to be running,
// something that is not the case at build time, see https://github.com/quarkusio/quarkus/issues/22864.
previousContextStorageSysProp = System.setProperty(OPENTELEMETRY_CONTEXT_CONTEXT_STORAGE_PROVIDER_SYS_PROP,
"default");

log.info("Starting container image build");
JibContainer container = jibContainerBuilder.containerize(containerizer);
log.infof("%s container image %s (%s)\n",
Expand All @@ -219,6 +230,12 @@ private JibContainer containerize(ContainerImageConfig containerImageConfig,
return container;
} catch (Exception e) {
throw new RuntimeException("Unable to create container image", e);
} finally {
if (previousContextStorageSysProp == null) {
System.clearProperty(OPENTELEMETRY_CONTEXT_CONTEXT_STORAGE_PROVIDER_SYS_PROP);
} else {
System.setProperty(OPENTELEMETRY_CONTEXT_CONTEXT_STORAGE_PROVIDER_SYS_PROP, previousContextStorageSysProp);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-jib</artifactId>
</dependency>

<!-- dependencies added to make sure that OpenTelemetry doesn't mess up building the container images -->
<!-- See https://github.com/quarkusio/quarkus/issues/22864 -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-exporter-otlp</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-grpc-1.6</artifactId>
<version>1.9.2-alpha</version>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand Down

0 comments on commit b6a693c

Please sign in to comment.