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

Update dependency io.opentelemetry:opentelemetry-proto to v0.17.1 #2576

Closed
Closed
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
2 changes: 0 additions & 2 deletions logging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

<javaModuleName>org.mule.test.integration.logging</javaModuleName>
<formatterConfigPath>../formatter.xml</formatterConfigPath>
<openTelemetryProtoVersion>0.3.0</openTelemetryProtoVersion>
</properties>

<build>
Expand Down Expand Up @@ -187,7 +186,6 @@
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-proto</artifactId>
<version>${openTelemetryProtoVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,26 @@
import static org.mule.runtime.core.api.util.StringUtils.isEmpty;
import static org.mule.runtime.core.api.util.StringUtils.toHexString;

import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;

import static io.opentelemetry.api.trace.propagation.internal.W3CTraceContextEncoding.decodeTraceState;
import static io.opentelemetry.proto.trace.v1.Status.StatusCode.STATUS_CODE_OK;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import org.mule.runtime.tracer.api.sniffer.CapturedEventData;
import org.mule.runtime.tracer.api.sniffer.CapturedExportedSpan;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest;
import io.opentelemetry.proto.common.v1.AttributeKeyValue;
import io.opentelemetry.proto.common.v1.KeyValue;
import io.opentelemetry.proto.trace.v1.ResourceSpans;
import io.opentelemetry.proto.trace.v1.Span;
import io.opentelemetry.proto.trace.v1.Status;

/**
* Utils for the open telemetry protobuf.
Expand All @@ -41,19 +42,22 @@ public class OpenTelemetryProtobufSpanUtils {
public static List<? extends CapturedExportedSpan> getSpans(ExportTraceServiceRequest exportTraceServiceRequest) {
return exportTraceServiceRequest.getResourceSpansList().stream()
.flatMap(resourceSpans -> processResourceSpans(resourceSpans).stream())
.collect(Collectors.toList());
.collect(toList());
}

private static List<SpanDataWrapper> processResourceSpans(ResourceSpans resourceSpans) {
List<Span> spans = new ArrayList<>();
// TODO: verify a better way to parse the attributes.
String serviceName =
resourceSpans.getResource().getAttributes(0).getUnknownFields().toByteString().toStringUtf8().substring(4);
String serviceName = resourceSpans.getResource().getAttributesList()
.stream()
.filter(kv -> kv.getKey().equals("service.name"))
.findAny()
.get()
.getValue().getStringValue();

resourceSpans.getInstrumentationLibrarySpansList()
.forEach(instrumentationLibrarySpans -> spans.addAll(instrumentationLibrarySpans.getSpansList()));

return spans.stream().map(span -> new SpanDataWrapper(serviceName, span)).collect(Collectors.toList());
return spans.stream().map(span -> new SpanDataWrapper(serviceName, span)).collect(toList());
}

/**
Expand All @@ -69,7 +73,6 @@ private static List<SpanDataWrapper> processResourceSpans(ResourceSpans resource
* @param request the export request for traces.
*/
public static void verifyResourceAndScopeGrouping(ExportTraceServiceRequest request) {

assertThat("The number of expected resources for the export request is not 1. In the mule runtime there is only one resource per app",
request.getResourceSpansCount(), equalTo(1));
assertThat("The number of expected instrumentation scopes for the export request is not 1. In the mule runtime there is only one scope, which corresponds to the instrumentation code/library for open telemetry export module.",
Expand Down Expand Up @@ -114,10 +117,9 @@ public String getTraceId() {

@Override
public Map<String, String> getAttributes() {
// TODO: verify a better way to parse the attributes in optel protobuf.
return openTelemetryProtobufSpan.getAttributesList().stream()
.collect(toMap(AttributeKeyValue::getKey,
attributeKeyValue -> attributeKeyValue.getUnknownFields().toByteString().toStringUtf8().substring(4)));
.collect(toMap(KeyValue::getKey,
attributeKeyValue -> attributeKeyValue.getValue().getStringValue()));
}

@Override
Expand All @@ -137,16 +139,12 @@ public String getSpanKindName() {

@Override
public boolean hasErrorStatus() {
return !openTelemetryProtobufSpan.getStatus().getCode().equals(Status.StatusCode.Ok);
return !openTelemetryProtobufSpan.getStatus().getCode().equals(STATUS_CODE_OK);
}

@Override
public String getStatusAsString() {
return openTelemetryProtobufSpan.getStatus().getCode().toString().toUpperCase();
}

public String getLocation() {
return getAttributes().get("location");
return StatusCode.values()[openTelemetryProtobufSpan.getStatus().getCodeValue()].name();
}

@Override
Expand Down
3 changes: 0 additions & 3 deletions tracing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
<javaModuleName>org.mule.test.integration.tracing</javaModuleName>
<skipExportTests>false</skipExportTests>
<formatterConfigPath>../formatter.xml</formatterConfigPath>

<openTelemetryProtoVersion>0.3.0</openTelemetryProtoVersion>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -299,7 +297,6 @@
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-proto</artifactId>
<version>${openTelemetryProtoVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import static java.lang.System.setProperty;
import static java.util.Arrays.asList;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.aMapWithSize;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.AnyOf.anyOf;
import static org.junit.Assert.assertThat;

import org.mule.runtime.core.privileged.profiling.PrivilegedProfilingService;
import org.mule.runtime.tracer.api.sniffer.CapturedExportedSpan;
Expand All @@ -46,14 +46,16 @@

import javax.inject.Inject;

import io.qameta.allure.Feature;
import io.qameta.allure.Story;
import junit.framework.AssertionFailedError;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runners.Parameterized;

import io.qameta.allure.Feature;
import io.qameta.allure.Story;

import junit.framework.AssertionFailedError;

@Feature(PROFILING)
@Story(DEFAULT_CORE_EVENT_TRACER)
@RunnerDelegateTo(Parameterized.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import static org.mule.runtime.core.api.util.StringUtils.toHexString;

import static java.util.Collections.emptyMap;

import static io.opentelemetry.api.trace.propagation.internal.W3CTraceContextEncoding.decodeTraceState;

import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;

import static io.opentelemetry.api.trace.propagation.internal.W3CTraceContextEncoding.decodeTraceState;
import static io.opentelemetry.proto.trace.v1.Status.StatusCode.STATUS_CODE_OK;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import org.mule.runtime.tracer.api.sniffer.CapturedEventData;
import org.mule.runtime.tracer.api.sniffer.CapturedExportedSpan;
Expand All @@ -25,13 +25,12 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest;
import io.opentelemetry.proto.common.v1.AttributeKeyValue;
import io.opentelemetry.proto.common.v1.KeyValue;
import io.opentelemetry.proto.trace.v1.ResourceSpans;
import io.opentelemetry.proto.trace.v1.Span;
import io.opentelemetry.proto.trace.v1.Status;

/**
* Utils for the open telemetry protobuf.
Expand All @@ -45,19 +44,22 @@ public class OpenTelemetryProtobufSpanUtils {
public static List<? extends CapturedExportedSpan> getSpans(ExportTraceServiceRequest exportTraceServiceRequest) {
return exportTraceServiceRequest.getResourceSpansList().stream()
.flatMap(resourceSpans -> processResourceSpans(resourceSpans).stream())
.collect(Collectors.toList());
.collect(toList());
}

private static List<SpanDataWrapper> processResourceSpans(ResourceSpans resourceSpans) {
List<Span> spans = new ArrayList<>();
// TODO: verify a better way to parse the attributes.
String serviceName =
resourceSpans.getResource().getAttributes(0).getUnknownFields().toByteString().toStringUtf8().substring(4);
String serviceName = resourceSpans.getResource().getAttributesList()
.stream()
.filter(kv -> kv.getKey().equals("service.name"))
.findAny()
.get()
.getValue().getStringValue();

resourceSpans.getInstrumentationLibrarySpansList()
.forEach(instrumentationLibrarySpans -> spans.addAll(instrumentationLibrarySpans.getSpansList()));

return spans.stream().map(span -> new SpanDataWrapper(serviceName, span)).collect(Collectors.toList());
return spans.stream().map(span -> new SpanDataWrapper(serviceName, span)).collect(toList());
}

/**
Expand All @@ -73,7 +75,6 @@ private static List<SpanDataWrapper> processResourceSpans(ResourceSpans resource
* @param request the export request for traces.
*/
public static void verifyResourceAndScopeGrouping(ExportTraceServiceRequest request) {

assertThat("The number of expected resources for the export request is not 1. In the mule runtime there is only one resource per app",
request.getResourceSpansCount(), equalTo(1));
assertThat("The number of expected instrumentation scopes for the export request is not 1. In the mule runtime there is only one scope, which corresponds to the instrumentation code/library for open telemetry export module.",
Expand Down Expand Up @@ -118,16 +119,15 @@ public String getTraceId() {

@Override
public Map<String, String> getAttributes() {
// TODO: verify a better way to parse the attributes in optel protobuf.
return openTelemetryProtobufSpan.getAttributesList().stream()
.collect(toMap(AttributeKeyValue::getKey,
attributeKeyValue -> attributeKeyValue.getUnknownFields().toByteString().toStringUtf8().substring(4)));
.collect(toMap(KeyValue::getKey,
attributeKeyValue -> attributeKeyValue.getValue().getStringValue()));
}

@Override
public List<CapturedEventData> getEvents() {
return openTelemetryProtobufSpan.getEventsList().stream().map(OpenTelemetryCapturedProtoEventData::new)
.collect(Collectors.toList());
.collect(toList());
}

@Override
Expand All @@ -142,16 +142,12 @@ public String getSpanKindName() {

@Override
public boolean hasErrorStatus() {
return !openTelemetryProtobufSpan.getStatus().getCode().equals(Status.StatusCode.Ok);
return !openTelemetryProtobufSpan.getStatus().getCode().equals(STATUS_CODE_OK);
}

@Override
public String getStatusAsString() {
return openTelemetryProtobufSpan.getStatus().getCode().toString().toUpperCase();
}

public String getLocation() {
return getAttributes().get("location");
return StatusCode.values()[openTelemetryProtobufSpan.getStatus().getCodeValue()].name();
}

@Override
Expand Down Expand Up @@ -191,7 +187,8 @@ private static class OpenTelemetryCapturedProtoEventData implements CapturedEven
public OpenTelemetryCapturedProtoEventData(Span.Event protoEvent) {
this.name = protoEvent.getName();
protoEvent.getAttributesList()
.forEach(attributeKeyValue -> attributes.put(attributeKeyValue.getKey(), attributeKeyValue.getStringValue()));
.forEach(attributeKeyValue -> attributes.put(attributeKeyValue.getKey(),
attributeKeyValue.getValue().getStringValue()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
package org.mule.test.components.tracing;

import static org.mule.runtime.api.util.MuleSystemProperties.ADD_MULE_SPECIFIC_TRACING_INFORMATION_IN_TRACE_STATE_PROPERTY;
import static org.mule.runtime.api.util.MuleSystemProperties.TRACING_LEVEL_CONFIGURATION_PATH;
import static org.mule.runtime.http.api.HttpConstants.Method.GET;
import static org.mule.runtime.tracer.customization.api.InternalSpanNames.GET_CONNECTION_SPAN_NAME;
import static org.mule.runtime.tracer.customization.api.InternalSpanNames.OPERATION_EXECUTION_SPAN_NAME;
import static org.mule.runtime.tracer.exporter.config.api.OpenTelemetrySpanExporterConfigurationProperties.MULE_OPEN_TELEMETRY_EXPORTER_ENDPOINT;
import static org.mule.runtime.tracer.exporter.config.api.OpenTelemetrySpanExporterConfigurationProperties.MULE_OPEN_TELEMETRY_EXPORTER_TYPE;
import static org.mule.runtime.api.util.MuleSystemProperties.TRACING_LEVEL_CONFIGURATION_PATH;
import static org.mule.runtime.tracing.level.api.config.TracingLevel.DEBUG;
import static org.mule.runtime.tracing.level.api.config.TracingLevel.MONITORING;
import static org.mule.runtime.tracing.level.api.config.TracingLevel.OVERVIEW;
Expand All @@ -21,25 +21,20 @@
import static org.mule.test.components.tracing.OpenTelemetryProtobufSpanUtils.getSpans;

import static java.lang.String.format;
import static java.lang.System.clearProperty;
import static java.lang.System.setProperty;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;

import static com.linecorp.armeria.common.HttpResponse.of;
import static com.linecorp.armeria.common.HttpStatus.OK;
import static io.opentelemetry.api.trace.Span.getInvalid;
import static io.opentelemetry.api.trace.SpanKind.INTERNAL;
import static io.opentelemetry.api.trace.StatusCode.UNSET;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;


import static java.lang.System.clearProperty;
import static java.lang.System.setProperty;
import static java.util.Arrays.asList;

import static com.linecorp.armeria.common.HttpResponse.from;
import static com.linecorp.armeria.common.HttpStatus.OK;

import io.qameta.allure.Feature;
import io.qameta.allure.Story;
import org.mule.runtime.api.util.MultiMap;
import org.mule.runtime.http.api.HttpService;
import org.mule.runtime.http.api.client.HttpRequestOptions;
Expand Down Expand Up @@ -69,6 +64,9 @@
import com.linecorp.armeria.server.ServerBuilder;
import com.linecorp.armeria.server.ServiceRequestContext;
import com.linecorp.armeria.testing.junit4.server.ServerRule;

import org.jetbrains.annotations.NotNull;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
Expand All @@ -77,13 +75,16 @@
import io.opentelemetry.context.propagation.TextMapSetter;
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import org.jetbrains.annotations.NotNull;

import org.junit.After;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runners.Parameterized;

import io.qameta.allure.Feature;
import io.qameta.allure.Story;

@RunnerDelegateTo(Parameterized.class)
@Feature(PROFILING)
@Story(DEFAULT_CORE_EVENT_TRACER)
Expand Down Expand Up @@ -377,9 +378,9 @@ protected void configure(ServerBuilder sb) {

@Override
protected @NotNull HttpResponse doPost(@NotNull ServiceRequestContext ctx, @NotNull HttpRequest req) {
return HttpResponse.from(req.aggregate().handle((aReq, cause) -> {
return HttpResponse.of(req.aggregate().handle((aReq, cause) -> {
CompletableFuture<HttpResponse> responseFuture = new CompletableFuture<>();
HttpResponse res = from(responseFuture);
HttpResponse res = of(responseFuture);
try {
capturedExportedSpans.addAll(getSpans(ExportTraceServiceRequest
.parseFrom(new ByteArrayInputStream(aReq.content().array()))));
Expand Down
Loading