|
1 | 1 | package io.quarkus.jdbc.mysql.runtime.graal.com.mysql.cj.jdbc; |
2 | 2 |
|
3 | 3 | import java.sql.SQLException; |
| 4 | +import java.util.function.BiConsumer; |
| 5 | +import java.util.function.BooleanSupplier; |
4 | 6 |
|
| 7 | +import com.mysql.cj.Messages; |
5 | 8 | import com.mysql.cj.exceptions.ExceptionFactory; |
| 9 | +import com.mysql.cj.telemetry.TelemetryHandler; |
| 10 | +import com.mysql.cj.telemetry.TelemetrySpan; |
| 11 | +import com.mysql.cj.telemetry.TelemetrySpanName; |
6 | 12 | import com.oracle.svm.core.annotate.Substitute; |
7 | 13 | import com.oracle.svm.core.annotate.TargetClass; |
8 | 14 |
|
@@ -67,5 +73,48 @@ public static void registerJmx() throws SQLException { |
67 | 73 |
|
68 | 74 | } |
69 | 75 |
|
| 76 | +@TargetClass(className = "com.mysql.cj.otel.OpenTelemetryHandler", onlyWith = OpenTelemetryUnavailable.class) |
| 77 | +final class OpenTelemetryHandler implements TelemetryHandler { |
| 78 | + |
| 79 | + @Substitute |
| 80 | + public OpenTelemetryHandler() { |
| 81 | + throw ExceptionFactory.createException(Messages.getString("Connection.OtelApiNotFound")); |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + @Substitute |
| 86 | + public TelemetrySpan startSpan(TelemetrySpanName telemetrySpanName, Object... objects) { |
| 87 | + return null; |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + @Substitute |
| 92 | + public void addLinkTarget(TelemetrySpan span) { |
| 93 | + } |
| 94 | + |
| 95 | + @Override |
| 96 | + @Substitute |
| 97 | + public void removeLinkTarget(TelemetrySpan span) { |
| 98 | + } |
| 99 | + |
| 100 | + @Override |
| 101 | + @Substitute |
| 102 | + public void propagateContext(BiConsumer<String, String> traceparentConsumer) { |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +final class OpenTelemetryUnavailable implements BooleanSupplier { |
| 107 | + |
| 108 | + @Override |
| 109 | + public boolean getAsBoolean() { |
| 110 | + try { |
| 111 | + Class.forName("io.opentelemetry.api.GlobalOpenTelemetry"); |
| 112 | + return false; |
| 113 | + } catch (ClassNotFoundException e) { |
| 114 | + return true; |
| 115 | + } |
| 116 | + } |
| 117 | +} |
| 118 | + |
70 | 119 | class MySQLJDBCSubstitutions { |
71 | 120 | } |
0 commit comments