-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenTelemetry Jaeger Substitutions - Remove shaded netty references
(cherry picked from commit d1a0c6e)
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...e/src/main/java/io/quarkus/opentelemetry/exporter/jaeger/runtime/JaegerSubstitutions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.quarkus.opentelemetry.exporter.jaeger.runtime; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import javax.net.ssl.SSLException; | ||
import javax.net.ssl.X509TrustManager; | ||
|
||
import com.oracle.svm.core.annotate.Substitute; | ||
import com.oracle.svm.core.annotate.TargetClass; | ||
|
||
import io.grpc.ManagedChannelBuilder; | ||
import io.grpc.netty.GrpcSslContexts; | ||
import io.grpc.netty.NettyChannelBuilder; | ||
import io.opentelemetry.exporter.otlp.internal.grpc.ManagedChannelUtil; | ||
|
||
/** | ||
* Replace the {@link ManagedChannelUtil#setTrustedCertificatesPem(ManagedChannelBuilder, byte[])} method in native | ||
* because the method implementation tries to look for grpc-netty-shaded dependencies, which we don't support. | ||
* | ||
* Check: | ||
* https://github.com/open-telemetry/opentelemetry-java/blob/v1.9.1/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/otlp/internal/grpc/ManagedChannelUtil.java#L56-L89 | ||
*/ | ||
final class JaegerSubstitutions { | ||
@TargetClass(ManagedChannelUtil.class) | ||
static final class Target_ManagedChannelUtil { | ||
@Substitute | ||
public static void setTrustedCertificatesPem( | ||
ManagedChannelBuilder<?> managedChannelBuilder, byte[] trustedCertificatesPem) | ||
throws SSLException { | ||
requireNonNull(managedChannelBuilder, "managedChannelBuilder"); | ||
requireNonNull(trustedCertificatesPem, "trustedCertificatesPem"); | ||
|
||
X509TrustManager tm = io.opentelemetry.exporter.otlp.internal.TlsUtil.trustManager(trustedCertificatesPem); | ||
|
||
// gRPC does not abstract TLS configuration so we need to check the implementation and act | ||
// accordingly. | ||
if (managedChannelBuilder.getClass().getName().equals("io.grpc.netty.NettyChannelBuilder")) { | ||
NettyChannelBuilder nettyBuilder = (NettyChannelBuilder) managedChannelBuilder; | ||
nettyBuilder.sslContext(GrpcSslContexts.forClient().trustManager(tm).build()); | ||
} else { | ||
throw new SSLException( | ||
"TLS certificate configuration not supported for unrecognized ManagedChannelBuilder " | ||
+ managedChannelBuilder.getClass().getName()); | ||
} | ||
} | ||
} | ||
} |