Skip to content

Commit

Permalink
Bump OTel to 1.24
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobat committed Mar 21, 2023
1 parent 187ca4b commit d09953a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 14 deletions.
4 changes: 2 additions & 2 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<opentracing-jdbc.version>0.2.4</opentracing-jdbc.version>
<opentracing-kafka.version>0.1.15</opentracing-kafka.version>
<opentracing-mongo.version>0.1.5</opentracing-mongo.version>
<opentelemetry.version>1.23.1</opentelemetry.version>
<opentelemetry-alpha.version>1.23.0-alpha</opentelemetry-alpha.version>
<opentelemetry.version>1.24.0</opentelemetry.version>
<opentelemetry-alpha.version>1.24.0-alpha</opentelemetry-alpha.version>
<opentelemetry-aws.contrib.version>1.23.0-alpha</opentelemetry-aws.contrib.version>
<opentelemetry-aws-xray.contrib.version>1.23.0</opentelemetry-aws-xray.contrib.version>
<jaeger.version>1.8.1</jaeger.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_URL;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_HOST_NAME;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_HOST_PORT;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_PEER_NAME;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_PEER_PORT;
import static io.quarkus.opentelemetry.deployment.common.TestSpanExporter.getSpanByKindAndParentId;
import static java.net.HttpURLConnection.HTTP_OK;
import static java.util.stream.Collectors.toSet;
Expand Down Expand Up @@ -79,6 +81,8 @@ void client() throws Exception {
assertEquals(HTTP_OK, client.getAttributes().get(HTTP_STATUS_CODE));
assertEquals(HttpMethod.GET, client.getAttributes().get(HTTP_METHOD));
assertEquals(uri.toString() + "hello", client.getAttributes().get(HTTP_URL));
assertEquals(uri.getHost(), client.getAttributes().get(NET_PEER_NAME));
assertEquals(uri.getPort(), client.getAttributes().get(NET_PEER_PORT));

SpanData server = getSpanByKindAndParentId(spans, SERVER, client.getSpanId());
assertEquals(SERVER, server.getKind());
Expand Down Expand Up @@ -111,6 +115,8 @@ void path() throws Exception {
assertEquals(HTTP_OK, client.getAttributes().get(HTTP_STATUS_CODE));
assertEquals(HttpMethod.GET, client.getAttributes().get(HTTP_METHOD));
assertEquals(uri.toString() + "hello/naruto", client.getAttributes().get(HTTP_URL));
assertEquals(uri.getHost(), client.getAttributes().get(NET_PEER_NAME));
assertEquals(uri.getPort(), client.getAttributes().get(NET_PEER_PORT));

SpanData server = getSpanByKindAndParentId(spans, SERVER, client.getSpanId());
assertEquals(SERVER, server.getKind());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,11 @@ final class Target_io_opentelemetry_exporter_otlp_internal_grpc_ManagedChannelUt
@Substitute
public static void setClientKeysAndTrustedCertificatesPem(
ManagedChannelBuilder<?> managedChannelBuilder,
byte[] privateKeyPem,
byte[] certificatePem,
byte[] trustedCertificatesPem)
X509TrustManager tmf,
X509KeyManager kmf)
throws SSLException {
requireNonNull(managedChannelBuilder, "managedChannelBuilder");
requireNonNull(trustedCertificatesPem, "trustedCertificatesPem");

X509TrustManager tmf = TlsUtil.trustManager(trustedCertificatesPem);
X509KeyManager kmf = null;
if (privateKeyPem != null && certificatePem != null) {
kmf = TlsUtil.keyManager(privateKeyPem, certificatePem);
}
requireNonNull(tmf, "X509TrustManager");

// gRPC does not abstract TLS configuration so we need to check the implementation and act
// accordingly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.quarkus.arc.Unremovable;
import io.quarkus.opentelemetry.runtime.QuarkusContextStorage;

Expand Down Expand Up @@ -60,6 +62,7 @@ public OpenTelemetryClientFilter() {
@Inject
public OpenTelemetryClientFilter(final OpenTelemetry openTelemetry) {
ClientAttributesExtractor clientAttributesExtractor = new ClientAttributesExtractor();
ClientNetAttributesGetter clientNetAttributesExtractor = new ClientNetAttributesGetter();

InstrumenterBuilder<ClientRequestContext, ClientResponseContext> builder = Instrumenter.builder(
openTelemetry,
Expand All @@ -68,7 +71,8 @@ public OpenTelemetryClientFilter(final OpenTelemetry openTelemetry) {

this.instrumenter = builder
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(clientAttributesExtractor))
.addAttributesExtractor(HttpClientAttributesExtractor.create(clientAttributesExtractor))
.addAttributesExtractor(HttpClientAttributesExtractor.create(
clientAttributesExtractor, clientNetAttributesExtractor))
.buildClientInstrumenter(new ClientRequestContextTextMapSetter());
}

Expand Down Expand Up @@ -178,4 +182,23 @@ public List<String> getResponseHeader(final ClientRequestContext request, final
return response.getHeaders().getOrDefault(name, emptyList());
}
}

private static class ClientNetAttributesGetter
implements NetClientAttributesGetter<ClientRequestContext, ClientResponseContext> {

@Override
public String getTransport(ClientRequestContext clientRequestContext, ClientResponseContext clientResponseContext) {
return SemanticAttributes.NetTransportValues.IP_TCP;
}

@Override
public String getPeerName(ClientRequestContext clientRequestContext) {
return clientRequestContext.getUri().getHost();
}

@Override
public Integer getPeerPort(ClientRequestContext clientRequestContext) {
return clientRequestContext.getUri().getPort();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.vertx.core.Context;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpHeaders;
Expand Down Expand Up @@ -127,6 +129,7 @@ private static Instrumenter<HttpRequest, HttpResponse> getServerInstrumenter(fin
private static Instrumenter<HttpRequest, HttpResponse> getClientInstrumenter(final OpenTelemetry openTelemetry) {
ServerAttributesExtractor serverAttributesExtractor = new ServerAttributesExtractor();
ClientAttributesExtractor clientAttributesExtractor = new ClientAttributesExtractor();
HttpClientNetAttributeGetter httpClientNetAttributeGetter = new HttpClientNetAttributeGetter();

InstrumenterBuilder<HttpRequest, HttpResponse> clientBuilder = Instrumenter.builder(
openTelemetry,
Expand All @@ -135,7 +138,8 @@ private static Instrumenter<HttpRequest, HttpResponse> getClientInstrumenter(fin

return clientBuilder
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(serverAttributesExtractor))
.addAttributesExtractor(HttpClientAttributesExtractor.create(clientAttributesExtractor))
.addAttributesExtractor(HttpClientAttributesExtractor.create(
clientAttributesExtractor, httpClientNetAttributeGetter))
.buildClientInstrumenter(new HttpRequestTextMapSetter());
}

Expand Down Expand Up @@ -295,6 +299,25 @@ public Integer getHostPort(HttpRequest httpRequest) {
}
}

private static class HttpClientNetAttributeGetter implements NetClientAttributesGetter<HttpRequest, HttpResponse> {
@Override
public String getTransport(HttpRequest httpClientRequest, HttpResponse httpClientResponse) {
return SemanticAttributes.NetTransportValues.IP_TCP;
}

@javax.annotation.Nullable
@Override
public String getPeerName(HttpRequest httpRequest) {
return httpRequest.remoteAddress().hostName();
}

@javax.annotation.Nullable
@Override
public Integer getPeerPort(HttpRequest httpRequest) {
return httpRequest.remoteAddress().port();
}
}

private static class HttpRequestTextMapGetter implements TextMapGetter<HttpRequest> {
@Override
public Iterable<String> keys(final HttpRequest carrier) {
Expand Down

0 comments on commit d09953a

Please sign in to comment.