Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump OTel 1.39. and instrumentation to 2.5.0 #41521

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,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.32.0</opentelemetry.version>
<opentelemetry-alpha.version>1.32.0-alpha</opentelemetry-alpha.version>
<opentelemetry-semconv.version>1.21.0-alpha</opentelemetry-semconv.version> <!-- keep in sync with opentelemetry-java-instrumentation in the alpha bom-->
<opentelemetry.version>1.39.0</opentelemetry.version>
<opentelemetry-alpha.version>2.5.0-alpha</opentelemetry-alpha.version>
<opentelemetry-semconv.version>1.25.0-alpha</opentelemetry-semconv.version>
<quarkus-http.version>5.3.0</quarkus-http.version>
<micrometer.version>1.12.5</micrometer.version><!-- keep in sync with hdrhistogram -->
<hdrhistogram.version>2.1.12</hdrhistogram.version><!-- keep in sync with micrometer -->
Expand Down Expand Up @@ -62,7 +62,7 @@
<smallrye-reactive-streams-operators.version>1.0.13</smallrye-reactive-streams-operators.version>
<smallrye-reactive-types-converter.version>3.0.1</smallrye-reactive-types-converter.version>
<smallrye-mutiny-vertx-binding.version>3.13.2</smallrye-mutiny-vertx-binding.version>
<smallrye-reactive-messaging.version>4.22.0</smallrye-reactive-messaging.version>
<smallrye-reactive-messaging.version>4.23.0</smallrye-reactive-messaging.version>
<smallrye-stork.version>2.6.0</smallrye-stork.version>
<jakarta.activation.version>2.1.3</jakarta.activation.version>
<jakarta.annotation-api.version>3.0.0</jakarta.annotation-api.version>
Expand Down Expand Up @@ -393,7 +393,7 @@
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-bom-alpha</artifactId>
<version>${opentelemetry-alpha.version}</version>
<version>${opentelemetry.version}-alpha</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
32 changes: 0 additions & 32 deletions extensions/opentelemetry/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,38 +152,6 @@
</extensions>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<!-- Default test with legacy http semantic conventions plus and
execution with the new ones. We can have 1 execution again, after otel instrumentaion 2.x
Run tests: mvn surefire:test@arquillian -Dtest=MyTest -Dmaven.surefire.debug -->
<execution>
<id>new-http-semconv</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<quarkus.otel.semconv-stability.opt-in>http</quarkus.otel.semconv-stability.opt-in>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>http-dup-semconv</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<quarkus.otel.semconv-stability.opt-in>http/dup</quarkus.otel.semconv-stability.opt-in>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;

Expand All @@ -17,7 +16,6 @@
import org.eclipse.microprofile.config.ConfigValue;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassType;
import org.jboss.jandex.DotName;
import org.jboss.jandex.MethodInfo;
Expand All @@ -44,7 +42,6 @@
import io.quarkus.arc.deployment.InterceptorBindingRegistrarBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.arc.deployment.ValidationPhaseBuildItem.ValidationErrorBuildItem;
import io.quarkus.arc.processor.AnnotationsTransformer;
import io.quarkus.arc.processor.InterceptorBindingRegistrar;
import io.quarkus.arc.processor.Transformation;
import io.quarkus.datasource.common.runtime.DataSourceUtil;
Expand Down Expand Up @@ -81,8 +78,6 @@
@BuildSteps(onlyIf = OpenTelemetryEnabled.class)
public class OpenTelemetryProcessor {

private static final DotName LEGACY_WITH_SPAN = DotName.createSimple(
io.opentelemetry.extension.annotations.WithSpan.class.getName());
private static final DotName WITH_SPAN = DotName.createSimple(WithSpan.class.getName());
private static final DotName ADD_SPAN_ATTRIBUTES = DotName.createSimple(AddingSpanAttributes.class.getName());
private static final Predicate<AnnotationInstance> isAddSpanAttribute = new Predicate<>() {
Expand All @@ -95,8 +90,6 @@ public boolean test(AnnotationInstance annotationInstance) {
private static final DotName WITH_SPAN_INTERCEPTOR = DotName.createSimple(WithSpanInterceptor.class.getName());
private static final DotName ADD_SPAN_ATTRIBUTES_INTERCEPTOR = DotName
.createSimple(AddingSpanAttributesInterceptor.class.getName());
private static final String QUARKUS_OTEL_SEMCONV_STABILITY_OPT_IN = "quarkus.otel.semconv-stability.opt-in";
private static final String OTEL_SEMCONV_STABILITY_OPT_IN = "otel.semconv-stability.opt-in";

@BuildStep
AdditionalBeanBuildItem ensureProducerIsRetained() {
Expand All @@ -114,15 +107,6 @@ AdditionalBeanBuildItem ensureProducerIsRetained() {
@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
SyntheticBeanBuildItem openTelemetryBean(OpenTelemetryRecorder recorder, OTelRuntimeConfig oTelRuntimeConfig) {

final String semconvStability = ConfigProvider.getConfig()
.getConfigValue(QUARKUS_OTEL_SEMCONV_STABILITY_OPT_IN)
.getValue();
if (semconvStability != null && !semconvStability.isEmpty()) {
// yes, they ignore config supplier on this.
System.setProperty(OTEL_SEMCONV_STABILITY_OPT_IN, semconvStability);
}

return SyntheticBeanBuildItem.configure(OpenTelemetry.class)
.defaultBean()
.setRuntimeInit()
Expand Down Expand Up @@ -229,35 +213,6 @@ public List<InterceptorBinding> getAdditionalBindings() {
@BuildStep
void transformWithSpan(BuildProducer<AnnotationsTransformerBuildItem> annotationsTransformer) {

// Transform deprecated annotation into new one
annotationsTransformer.produce(new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {
@Override
public boolean appliesTo(AnnotationTarget.Kind kind) {
return kind == AnnotationTarget.Kind.METHOD;
}

@Override
public void transform(TransformationContext context) {
final AnnotationTarget target = context.getTarget();

List<AnnotationInstance> legacyWithSpans = context.getAnnotations().stream()
.filter(annotationInstance -> annotationInstance.name().equals(LEGACY_WITH_SPAN))
.collect(toList());

for (AnnotationInstance legacyAnnotation : legacyWithSpans) {
AnnotationValue value = Optional.ofNullable(legacyAnnotation.value("value"))
.orElse(AnnotationValue.createStringValue("value", ""));
AnnotationValue kind = Optional.ofNullable(legacyAnnotation.value("kind"))
.orElse(AnnotationValue.createEnumValue("kind", SPAN_KIND, SpanKind.INTERNAL.name()));
AnnotationInstance annotation = AnnotationInstance.create(
WITH_SPAN,
target,
List.of(value, kind));
context.transform().add(annotation).done();
}
}
}));

annotationsTransformer.produce(new AnnotationsTransformerBuildItem(transformationContext -> {
AnnotationTarget target = transformationContext.getTarget();
Transformation transform = transformationContext.transform();
Expand Down Expand Up @@ -306,10 +261,7 @@ void setupVertx(InstrumentationRecorder recorder, BeanContainerBuildItem beanCon
boolean redisClientAvailable = capabilities.isPresent(Capability.REDIS_CLIENT);
recorder.setupVertxTracer(beanContainerBuildItem.getValue(),
sqlClientAvailable,
redisClientAvailable,
ConfigProvider.getConfig()
.getConfigValue(QUARKUS_OTEL_SEMCONV_STABILITY_OPT_IN)
.getValue());
redisClientAvailable);
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.metrics.InstrumentType;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
Expand All @@ -35,9 +34,6 @@
@ApplicationScoped
public class InMemoryMetricExporter implements MetricExporter {

private static final List<String> LEGACY_KEY_COMPONENTS = List.of(SemanticAttributes.HTTP_METHOD.getKey(),
SemanticAttributes.HTTP_ROUTE.getKey(),
SemanticAttributes.HTTP_STATUS_CODE.getKey());
private static final List<String> KEY_COMPONENTS = List.of(SemanticAttributes.HTTP_REQUEST_METHOD.getKey(),
SemanticAttributes.HTTP_ROUTE.getKey(),
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE.getKey());
Expand Down Expand Up @@ -77,13 +73,7 @@ public static Map<String, PointData> getMostRecentPointsMap(List<MetricData> fin
.collect(toMap(
pointData -> pointData.getAttributes().asMap().entrySet().stream()
//valid attributes for the resulting map key
.filter(entry -> {
if (SemconvStability.emitOldHttpSemconv()) {
return LEGACY_KEY_COMPONENTS.contains(entry.getKey().getKey());
} else {
return KEY_COMPONENTS.contains(entry.getKey().getKey());
}
})
.filter(entry -> KEY_COMPONENTS.contains(entry.getKey().getKey()))
// ensure order
.sorted(Comparator.comparing(o -> o.getKey().getKey()))
// build key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,137 +2,39 @@

import static io.opentelemetry.api.common.AttributeType.LONG;
import static io.opentelemetry.api.common.AttributeType.STRING;
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_TARGET;
import static io.opentelemetry.semconv.SemanticAttributes.URL_PATH;
import static io.opentelemetry.semconv.SemanticAttributes.URL_QUERY;
import static io.quarkus.opentelemetry.runtime.config.runtime.SemconvStabilityType.HTTP;
import static io.opentelemetry.semconv.UrlAttributes.URL_PATH;
import static io.opentelemetry.semconv.UrlAttributes.URL_QUERY;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.HashMap;
import java.util.Map;

import org.jboss.logging.Logger;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.quarkus.opentelemetry.runtime.OpenTelemetryUtil;
import io.quarkus.opentelemetry.runtime.config.runtime.SemconvStabilityType;

public class SemconvResolver {

public static final SemconvStabilityType SEMCONV_STABILITY_TYPE;
private static final Map<String, String> conventionsMapper = new HashMap<>();
private static final Logger log = Logger.getLogger(SemconvResolver.class);

static {
SEMCONV_STABILITY_TYPE = OpenTelemetryUtil.getSemconvStabilityOptin(
System.getProperty("quarkus.otel.semconv-stability.opt-in", "stable"));

log.info("Using semantic convention stability type: " + SEMCONV_STABILITY_TYPE);

conventionsMapper.put("http.method", "http.request.method");
conventionsMapper.put("http.status_code", "http.response.status_code");
conventionsMapper.put("http.request_content_length", "http.request.body.size");
conventionsMapper.put("http.response_content_length", "http.request.body.size");
conventionsMapper.put("net.protocol.name", "network.protocol.name");
conventionsMapper.put("net.protocol.version", "network.protocol.version");
// net.sock.family removed
conventionsMapper.put("net.sock.peer.addr", "network.peer.address");
conventionsMapper.put("net.sock.peer.port", "network.peer.port");
// net.sock.peer.name removed
// New: http.request.method_original
// New: error.type
conventionsMapper.put("http.url", "url.full");
conventionsMapper.put("http.resend_count", "http.request.resend_count");
conventionsMapper.put("net.peer.name", "server.address");
conventionsMapper.put("net.peer.port", "server.port");
// http.target split into url.path and url.query
conventionsMapper.put("http.scheme", "url.scheme");
conventionsMapper.put("http.client_ip", "client.address");
conventionsMapper.put("net.host.name", "server.address");
conventionsMapper.put("net.host.port", "server.port");

}

SemconvResolver() {
// empty
}

public static void assertTarget(final SpanData server, final String path, final String query) {
switch (SEMCONV_STABILITY_TYPE) {
case HTTP:
assertEquals(path, server.getAttributes().get(URL_PATH));
assertEquals(query, server.getAttributes().get(URL_QUERY));
break;
case HTTP_DUP:
assertEquals(path, server.getAttributes().get(URL_PATH));
assertEquals(query, server.getAttributes().get(URL_QUERY));
assertEquals("" + path + (query == null ? "" : "?" + query), server.getAttributes().get(HTTP_TARGET));
break;
case HTTP_OLD:
assertEquals("" + path + (query == null ? "" : "?" + query), server.getAttributes().get(HTTP_TARGET));
break;
default:
throw new IllegalArgumentException("Unsupported semantic convention stability type: " + SEMCONV_STABILITY_TYPE);
}
assertEquals(path, server.getAttributes().get(URL_PATH));
assertEquals(query, server.getAttributes().get(URL_QUERY));
}

public static <T> void assertSemanticAttribute(final SpanData spanData, final T expected,
final AttributeKey<T> attribute) {
switch (SEMCONV_STABILITY_TYPE) {
case HTTP:
assertEquals(expected, getNewAttribute(spanData, attribute));
break;
case HTTP_DUP:
assertEquals(expected, getNewAttribute(spanData, attribute)); // assert new semantic convention
assertEquals(expected, spanData.getAttributes().get(attribute)); // assert old semantic convention
break;
case HTTP_OLD:
assertEquals(expected, spanData.getAttributes().get(attribute)); // assert old semantic convention
break;
default:
throw new IllegalArgumentException("Unsupported semantic convention stability type: " + SEMCONV_STABILITY_TYPE);
}
}

public static <T> void assertNotNullSemanticAttribute(final SpanData spanData,
final AttributeKey<T> attribute) {
switch (SemconvResolver.SEMCONV_STABILITY_TYPE) {
case HTTP:
assertNotNull(getNewAttribute(spanData, attribute));
break;
case HTTP_DUP:
assertNotNull(getNewAttribute(spanData, attribute)); // assert new semantic convention
assertNotNull(spanData.getAttributes().get(attribute)); // assert old semantic convention
break;
case HTTP_OLD:
assertNotNull(spanData.getAttributes().get(attribute)); // assert old semantic convention
break;
default:
throw new IllegalArgumentException(
"Unsupported semantic convention stability type: " + SemconvResolver.SEMCONV_STABILITY_TYPE);
}
final AttributeKey<T> attributeKey) {
assertEquals(expected, getAttribute(spanData, attributeKey));
}

@SuppressWarnings("unchecked")
private static <T> T getNewAttribute(final SpanData data, final AttributeKey<T> legacyAttributeKey) {
if (legacyAttributeKey.getType().equals(LONG)) {
return (T) data.getAttributes().get(resolveLong((AttributeKey<Long>) legacyAttributeKey));
} else if (legacyAttributeKey.getType().equals(STRING)) {
return (T) data.getAttributes().get(resolveString((AttributeKey<String>) legacyAttributeKey));
private static <T> T getAttribute(final SpanData data, final AttributeKey<T> attributeKey) {
if (attributeKey.getType().equals(LONG)) {
return (T) data.getAttributes().get(attributeKey);
} else if (attributeKey.getType().equals(STRING)) {
return (T) data.getAttributes().get(attributeKey);
} else {
throw new IllegalArgumentException(
"Unsupported attribute: " + legacyAttributeKey.getKey() +
" with type: " + legacyAttributeKey.getKey().getClass());
"Unsupported attribute: " + attributeKey.getKey() +
" with type: " + attributeKey.getKey().getClass());
}
}

private static AttributeKey<String> resolveString(final AttributeKey<String> legacyKey) {
return AttributeKey.stringKey(conventionsMapper.get(legacyKey.getKey()));
}

private static AttributeKey<Long> resolveLong(final AttributeKey<Long> legacyKey) {
return AttributeKey.longKey(conventionsMapper.get(legacyKey.getKey()));
}
}
Loading
Loading