Skip to content

Commit

Permalink
Merge pull request quarkusio#43752 from brunobat/bump-otel-1-42
Browse files Browse the repository at this point in the history
Bump OpenTelemetry sdk to 1.42.1
  • Loading branch information
brunobat authored Oct 11, 2024
2 parents 5eedb7c + e559cbd commit 8f50794
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 65 deletions.
6 changes: 3 additions & 3 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
<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.39.0</opentelemetry.version>
<opentelemetry-alpha.version>2.5.0-alpha</opentelemetry-alpha.version>
<opentelemetry-semconv.version>1.26.0-alpha</opentelemetry-semconv.version>
<opentelemetry.version>1.42.1</opentelemetry.version>
<opentelemetry-alpha.version>2.8.0-alpha</opentelemetry-alpha.version>
<opentelemetry-semconv.version>1.27.0-alpha</opentelemetry-semconv.version>
<quarkus-http.version>5.3.3</quarkus-http.version>
<micrometer.version>1.13.5</micrometer.version><!-- keep in sync with hdrhistogram -->
<hdrhistogram.version>2.2.2</hdrhistogram.version><!-- keep in sync with micrometer -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.quarkus.opentelemetry.deployment.common.exporter;

import static io.opentelemetry.semconv.HttpAttributes.HTTP_REQUEST_METHOD;
import static io.opentelemetry.semconv.HttpAttributes.HTTP_RESPONSE_STATUS_CODE;
import static io.opentelemetry.semconv.HttpAttributes.HTTP_ROUTE;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toMap;
Expand Down Expand Up @@ -27,16 +30,15 @@
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.data.PointData;
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import io.opentelemetry.semconv.SemanticAttributes;
import io.quarkus.arc.Unremovable;

@Unremovable
@ApplicationScoped
public class InMemoryMetricExporter implements MetricExporter {

private static final List<String> KEY_COMPONENTS = List.of(SemanticAttributes.HTTP_REQUEST_METHOD.getKey(),
SemanticAttributes.HTTP_ROUTE.getKey(),
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE.getKey());
private static final List<String> KEY_COMPONENTS = List.of(HTTP_REQUEST_METHOD.getKey(),
HTTP_ROUTE.getKey(),
HTTP_RESPONSE_STATUS_CODE.getKey());

private final Queue<MetricData> finishedMetricItems = new ConcurrentLinkedQueue<>();
private final AggregationTemporality aggregationTemporality = AggregationTemporality.CUMULATIVE;
Expand Down Expand Up @@ -89,15 +91,15 @@ public static Map<String, PointData> getMostRecentPointsMap(List<MetricData> fin
*/
private static boolean notExporterPointData(PointData pointData) {
return pointData.getAttributes().asMap().entrySet().stream()
.noneMatch(entry -> entry.getKey().getKey().equals(SemanticAttributes.HTTP_ROUTE.getKey()) &&
.noneMatch(entry -> entry.getKey().getKey().equals(HTTP_ROUTE.getKey()) &&
entry.getValue().toString().contains("/export"));
}

private static boolean isPathFound(String path, Attributes attributes) {
if (path == null) {
return true;// any match
}
Object value = attributes.asMap().get(AttributeKey.stringKey(SemanticAttributes.HTTP_ROUTE.getKey()));
Object value = attributes.asMap().get(AttributeKey.stringKey(HTTP_ROUTE.getKey()));
if (value == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import static io.opentelemetry.api.trace.SpanKind.CLIENT;
import static io.opentelemetry.api.trace.SpanKind.INTERNAL;
import static io.opentelemetry.api.trace.SpanKind.SERVER;
import static io.opentelemetry.semconv.SemanticAttributes.RPC_GRPC_STATUS_CODE;
import static io.opentelemetry.semconv.SemanticAttributes.RPC_METHOD;
import static io.opentelemetry.semconv.SemanticAttributes.RPC_SERVICE;
import static io.opentelemetry.semconv.SemanticAttributes.RPC_SYSTEM;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_GRPC_STATUS_CODE;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_METHOD;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SERVICE;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SYSTEM;
import static io.quarkus.opentelemetry.deployment.common.exporter.TestSpanExporter.getSpanByKindAndParentId;
import static io.quarkus.opentelemetry.runtime.config.build.OTelBuildConfig.INSTRUMENTATION_NAME;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static io.opentelemetry.api.trace.SpanKind.INTERNAL;
import static io.opentelemetry.api.trace.SpanKind.SERVER;
import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_FUNCTION;
import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_NAMESPACE;
import static io.quarkus.opentelemetry.deployment.common.TestUtil.assertStringAttribute;
import static io.quarkus.opentelemetry.deployment.common.exporter.TestSpanExporter.getSpanByKindAndParentId;
import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -24,7 +26,6 @@

import io.opentelemetry.instrumentation.annotations.WithSpan;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.semconv.SemanticAttributes;
import io.quarkus.opentelemetry.deployment.common.TestUtil;
import io.quarkus.opentelemetry.deployment.common.exporter.TestSpanExporter;
import io.quarkus.opentelemetry.deployment.common.exporter.TestSpanExporterProvider;
Expand Down Expand Up @@ -64,9 +65,9 @@ void telemetry() {
final SpanData server = getSpanByKindAndParentId(spans, SERVER, "0000000000000000");
assertEquals("GET /hello", server.getName());
// verify that OpenTelemetryServerFilter took place
assertStringAttribute(server, SemanticAttributes.CODE_NAMESPACE,
assertStringAttribute(server, CODE_NAMESPACE,
"io.quarkus.opentelemetry.deployment.traces.OpenTelemetryHttpCDITest$HelloResource");
assertStringAttribute(server, SemanticAttributes.CODE_FUNCTION, "hello");
assertStringAttribute(server, CODE_FUNCTION, "hello");

final SpanData internalFromBean = getSpanByKindAndParentId(spans, INTERNAL, server.getSpanId());
assertEquals("HelloBean.hello", internalFromBean.getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.opentelemetry.deployment.traces;

import static io.opentelemetry.api.trace.SpanKind.SERVER;
import static io.opentelemetry.semconv.HttpAttributes.HTTP_ROUTE;
import static io.quarkus.opentelemetry.deployment.common.TestUtil.assertStringAttribute;
import static io.quarkus.opentelemetry.deployment.common.exporter.TestSpanExporter.getSpanByKindAndParentId;
import static org.hamcrest.Matchers.is;
Expand All @@ -18,7 +19,6 @@
import org.junit.jupiter.api.extension.RegisterExtension;

import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.semconv.SemanticAttributes;
import io.quarkus.opentelemetry.deployment.common.TestUtil;
import io.quarkus.opentelemetry.deployment.common.exporter.TestSpanExporter;
import io.quarkus.opentelemetry.deployment.common.exporter.TestSpanExporterProvider;
Expand Down Expand Up @@ -57,7 +57,7 @@ void root() {

final SpanData server = getSpanByKindAndParentId(spans, SERVER, "0000000000000000");
assertEquals("GET /", server.getName());
assertStringAttribute(server, SemanticAttributes.HTTP_ROUTE, "/");
assertStringAttribute(server, HTTP_ROUTE, "/");
}

@Test
Expand All @@ -71,7 +71,7 @@ void nonRoot() {

final SpanData server = getSpanByKindAndParentId(spans, SERVER, "0000000000000000");
assertEquals("GET /hello", server.getName());
assertStringAttribute(server, SemanticAttributes.HTTP_ROUTE, "/hello");
assertStringAttribute(server, HTTP_ROUTE, "/hello");
}

@ApplicationScoped
Expand Down
4 changes: 4 additions & 0 deletions extensions/opentelemetry/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
<groupId>io.opentelemetry.semconv</groupId>
<artifactId>opentelemetry-semconv</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry.semconv</groupId>
<artifactId>opentelemetry-semconv-incubating</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api-incubator</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.concurrent.CompletionStage;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
Expand Down Expand Up @@ -84,7 +83,7 @@ public VertxGrpcSender(
}

@Override
public void send(Marshaler request, Runnable onSuccess, BiConsumer onError) {
public void send(Marshaler request, Consumer onSuccess, Consumer onError) {
if (isShutdown.get()) {
return;
}
Expand Down Expand Up @@ -164,13 +163,13 @@ public void accept(GrpcClientRequest<Buffer, Buffer> request) {
}, onFailureCallback);
}

private void failOnClientRequest(String type, Throwable t, BiConsumer onError) {
private void failOnClientRequest(String type, Throwable t, Consumer<Throwable> onError) {
String message = "Failed to export "
+ type
+ "s. The request could not be executed. Full error message: "
+ (t.getMessage() == null ? t.getClass().getName() : t.getMessage());
logger.log(Level.WARNING, message);
onError.accept(GrpcResponse.create(2 /* UNKNOWN */, message), t);
onError.accept(t);
}

private static final class ClientRequestOnSuccessHandler implements Handler<GrpcClientRequest<Buffer, Buffer>> {
Expand All @@ -184,8 +183,8 @@ private static final class ClientRequestOnSuccessHandler implements Handler<Grpc
private final AtomicBoolean loggedUnimplemented;
private final ThrottlingLogger logger;
private final String type;
private final Runnable onSuccess;
private final BiConsumer<GrpcResponse, Throwable> onError;
private final Consumer<GrpcResponse> onSuccess;
private final Consumer<Throwable> onError;
private final String grpcEndpointPath;

private final int attemptNumber;
Expand All @@ -199,8 +198,8 @@ public ClientRequestOnSuccessHandler(GrpcClient client,
AtomicBoolean loggedUnimplemented,
ThrottlingLogger logger,
String type,
Runnable onSuccess,
BiConsumer<GrpcResponse, Throwable> onError,
Consumer<GrpcResponse> onSuccess,
Consumer<Throwable> onError,
int attemptNumber,
String grpcEndpointPath,
Supplier<Boolean> isShutdown) {
Expand Down Expand Up @@ -273,7 +272,7 @@ public void handle(GrpcError error) {
public void handle(Void ignored) {
GrpcStatus status = getStatus(response);
if (status == GrpcStatus.OK) {
onSuccess.run();
onSuccess.accept(GrpcResponse.create(status.code, status.toString()));
} else {
handleError(status, response);
}
Expand All @@ -284,9 +283,7 @@ public void handle(Void ignored) {
private void handleError(GrpcStatus status, GrpcClientResponse<Buffer, Buffer> response) {
String statusMessage = getStatusMessage(response);
logAppropriateWarning(status, statusMessage);
onError.accept(
GrpcResponse.create(2 /* UNKNOWN */, statusMessage),
new IllegalStateException(statusMessage));
onError.accept(new IllegalStateException(statusMessage));
}

private void logAppropriateWarning(GrpcStatus status,
Expand Down Expand Up @@ -415,18 +412,18 @@ public void accept(Throwable throwable) {
+ "s. Unable to serialize payload. Full error message: "
+ (e.getMessage() == null ? e.getClass().getName() : e.getMessage());
logger.log(Level.WARNING, message);
onError.accept(GrpcResponse.create(2 /* UNKNOWN */, message), e);
onError.accept(e);
}
}

private void failOnClientRequest(Throwable t, BiConsumer<GrpcResponse, Throwable> onError, int attemptNumber) {
private void failOnClientRequest(Throwable t, Consumer<Throwable> onError, int attemptNumber) {
final String message = "Failed to export "
+ type
+ "s. The request could not be executed after " + attemptNumber
+ " attempts. Full error message: "
+ (t != null ? t.getMessage() : "");
logger.log(Level.WARNING, message);
onError.accept(GrpcResponse.create(2 /* UNKNOWN */, message), t);
onError.accept(t);
}

public ClientRequestOnSuccessHandler newAttempt() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.quarkus.opentelemetry.runtime.tracing;

import static io.opentelemetry.semconv.UrlAttributes.URL_PATH;
import static io.opentelemetry.semconv.UrlAttributes.URL_QUERY;

import java.util.List;

import io.opentelemetry.api.common.Attributes;
Expand All @@ -8,7 +11,6 @@
import io.opentelemetry.sdk.trace.data.LinkData;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import io.opentelemetry.sdk.trace.samplers.SamplingResult;
import io.opentelemetry.semconv.SemanticAttributes;

public class DropTargetsSampler implements Sampler {
private final Sampler sampler;
Expand All @@ -26,8 +28,8 @@ public SamplingResult shouldSample(Context parentContext, String traceId, String

if (spanKind.equals(SpanKind.SERVER)) {
// HTTP_TARGET was split into url.path and url.query
String path = attributes.get(SemanticAttributes.URL_PATH);
String query = attributes.get(SemanticAttributes.URL_QUERY);
String path = attributes.get(URL_PATH);
String query = attributes.get(URL_QUERY);
String target = path + (query == null ? "" : "?" + query);

if (shouldDrop(target)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package io.quarkus.opentelemetry.runtime.tracing;

import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_VERSION;
import static io.opentelemetry.semconv.incubating.WebengineIncubatingAttributes.WEBENGINE_NAME;
import static io.opentelemetry.semconv.incubating.WebengineIncubatingAttributes.WEBENGINE_VERSION;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.ResourceAttributes;
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.runtime.annotations.StaticInit;

Expand All @@ -28,10 +32,10 @@ public DelayedAttributes get() {
result.setAttributesDelegate(Resource.getDefault()
.merge(Resource.create(
Attributes.of(
ResourceAttributes.SERVICE_NAME, serviceName,
ResourceAttributes.SERVICE_VERSION, serviceVersion,
ResourceAttributes.WEBENGINE_NAME, "Quarkus",
ResourceAttributes.WEBENGINE_VERSION, quarkusVersion)))
SERVICE_NAME, serviceName,
SERVICE_VERSION, serviceVersion,
WEBENGINE_NAME, "Quarkus",
WEBENGINE_VERSION, quarkusVersion)))
.getAttributes());
return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.quarkus.opentelemetry.runtime.tracing;

import static io.opentelemetry.semconv.ResourceAttributes.HOST_NAME;
import static io.opentelemetry.semconv.ResourceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.incubating.HostIncubatingAttributes.HOST_NAME;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.quarkus.opentelemetry.runtime.tracing.intrumentation.grpc;

import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_GRPC_STATUS_CODE;

import io.grpc.Status;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.semconv.SemanticAttributes;

class GrpcStatusCodeExtractor implements AttributesExtractor<GrpcRequest, Status> {
@Override
Expand All @@ -24,7 +25,7 @@ public void onEnd(
final Throwable error) {

if (status != null) {
attributes.put(SemanticAttributes.RPC_GRPC_STATUS_CODE, status.getCode().value());
attributes.put(RPC_GRPC_STATUS_CODE, status.getCode().value());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.quarkus.opentelemetry.runtime.tracing.intrumentation.resteasy;

import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_FUNCTION;
import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_NAMESPACE;

import java.io.IOException;

import jakarta.ws.rs.container.ContainerRequestContext;
Expand All @@ -10,7 +13,6 @@

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan;
import io.opentelemetry.semconv.SemanticAttributes;

/**
* Handles RESTEasy Classic
Expand All @@ -25,7 +27,7 @@ public class OpenTelemetryClassicServerFilter implements ContainerRequestFilter
public void filter(ContainerRequestContext requestContext) throws IOException {
Span localRootSpan = LocalRootSpan.current();

localRootSpan.setAttribute(SemanticAttributes.CODE_NAMESPACE, resourceInfo.getResourceClass().getName());
localRootSpan.setAttribute(SemanticAttributes.CODE_FUNCTION, resourceInfo.getResourceMethod().getName());
localRootSpan.setAttribute(CODE_NAMESPACE, resourceInfo.getResourceClass().getName());
localRootSpan.setAttribute(CODE_FUNCTION, resourceInfo.getResourceMethod().getName());
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.quarkus.opentelemetry.runtime.tracing.intrumentation.resteasy;

import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_FUNCTION;
import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_NAMESPACE;

import java.io.IOException;

import org.jboss.resteasy.reactive.server.ServerRequestFilter;
import org.jboss.resteasy.reactive.server.SimpleResourceInfo;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan;
import io.opentelemetry.semconv.SemanticAttributes;

/**
* Handles RESTEasy Reactive (via Vert.x)
Expand All @@ -18,7 +20,7 @@ public class OpenTelemetryReactiveServerFilter {
public void filter(SimpleResourceInfo resourceInfo) throws IOException {
Span localRootSpan = LocalRootSpan.current();

localRootSpan.setAttribute(SemanticAttributes.CODE_NAMESPACE, resourceInfo.getResourceClass().getName());
localRootSpan.setAttribute(SemanticAttributes.CODE_FUNCTION, resourceInfo.getMethodName());
localRootSpan.setAttribute(CODE_NAMESPACE, resourceInfo.getResourceClass().getName());
localRootSpan.setAttribute(CODE_FUNCTION, resourceInfo.getMethodName());
}
}
Loading

0 comments on commit 8f50794

Please sign in to comment.