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 OpenTelemetryProtoConverter #50

Merged
merged 5 commits into from
Feb 20, 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
26 changes: 11 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ dependencies {
"org.springframework.boot:spring-boot-starter-security",

"org.yaml:snakeyaml:${snakeYamlVersion}",
// Has to be included, but is transitive to spring
"com.fasterxml.jackson.dataformat:jackson-dataformat-yaml",

// pin Prometheus client to 0.6.0 to prevent auto prefixing counter metrics with "_total"
// see: https://github.com/prometheus/client_java/issues/640, https://github.com/prometheus/client_java/pull/653
Expand All @@ -137,18 +139,16 @@ dependencies {
"io.opencensus:opencensus-impl:${openCensusVersion}",
"io.opencensus:opencensus-exporter-stats-prometheus:${openCensusVersion}",

//"io.grpc:grpc-context:1.58.0",
"io.grpc:grpc-context:${grpcVersion}",

platform("io.opentelemetry:opentelemetry-bom-alpha:${openTelemetryAlphaVersion}"),
"io.opentelemetry:opentelemetry-semconv",
platform("io.opentelemetry:opentelemetry-bom:${openTelemetryVersion}"),
"io.opentelemetry:opentelemetry-exporter-otlp",
"io.opentelemetry:opentelemetry-exporter-jaeger",
"io.opentelemetry:opentelemetry-exporter-jaeger-thrift",
"io.opentelemetry:opentelemetry-sdk",
"io.opentelemetry:opentelemetry-proto:${openTelemetryProtoVersion}",

"com.fasterxml.jackson.dataformat:jackson-dataformat-yaml",
"io.opentelemetry:opentelemetry-exporter-otlp:${openTelemetryVersion}",
"io.opentelemetry:opentelemetry-semconv:${openTelemetrySemConvVersion}",
"io.opentelemetry:opentelemetry-exporter-jaeger:${openTelemetryJaegerVersion}",
"io.opentelemetry:opentelemetry-exporter-jaeger-thrift:${openTelemetryJaegerVersion}",
"io.opentelemetry:opentelemetry-sdk:${openTelemetryVersion}",
"io.opentelemetry.proto:opentelemetry-proto:${openTelemetryProtoVersion}",

"com.google.protobuf:protobuf-java:${protobufVersion}",
"com.google.protobuf:protobuf-java-util:${protobufVersion}",
Expand All @@ -157,7 +157,7 @@ dependencies {

"com.maxmind.geoip2:geoip2:${geoip2Version}",
"commons-net:commons-net:${commonsNetVersion}",
"org.apache.commons:commons-lang3",
"org.apache.commons:commons-lang3:${commonsLang3Version}",
"org.apache.commons:commons-math3:${commonsMath3Version}",
"commons-io:commons-io:${commonsIoVersion}",

Expand All @@ -176,11 +176,7 @@ dependencies {
testImplementation(
"org.springframework.boot:spring-boot-starter-test",
"io.opencensus:opencensus-impl:${openCensusVersion}",
"org.apache.httpcomponents:httpclient:4.5.14",
"org.mockito:mockito-core",
"org.junit.jupiter:junit-jupiter-api",
"org.awaitility:awaitility",
"org.mockito:mockito-junit-jupiter",
"org.apache.httpcomponents:httpclient:${httpClientVersion}",

// ServerExtension
"com.linecorp.armeria:armeria-junit5:${armeriaVersion}",
Expand Down
51 changes: 31 additions & 20 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,42 +1,53 @@
# The boomerang version to ship with the EUM server
boomerangVersion=1.737.0
# The open-telemetry-boomerang version to ship with the EUM server
boomerangOpenTelemetryPluginVersion=0.25.0-8
# The OpenTelemetry-Boomerang version to ship with the EUM server
boomerangOpenTelemetryPluginVersion=0.48.0-2

# Upgrade to Spring 3.* and Java 17
springBootVersion=3.1.4
# CVE-2022-1471 was resolved with SnakeYAML 2.0
snakeYamlVersion=2.0
springBootVersion=3.2.2
snakeYamlVersion=2.2

# Ensure to adapt the netty version (inspectit-ocelot-core/build.gradle) when changing the OpenCensus version
openCensusVersion=0.31.1
grpcVersion=1.61.1

# pin Prometheus client to 0.6.0 to prevent auto prefixing counter metrics with "_total"
# see: https://github.com/prometheus/client_java/issues/640, https://github.com/prometheus/client_java/pull/653
prometheusClientVersion = 0.6.0
openTelemetryVersion=1.27.0
openTelemetryAlphaVersion=1.27.0-alpha
openTelemetryProtoVersion=1.7.1-alpha
protobufVersion=3.22.5
guavaVersion=32.1.2-jre
geoip2Version=4.0.1
commonsNetVersion=3.9.0
# Keep the OpenTelemetry versions consistent
openTelemetryVersion=1.30.0
openTelemetryAlphaVersion=1.30.0-alpha
openTelemetryProtoVersion=1.1.0-alpha
openTelemetrySemConvVersion=1.30.1-alpha
openTelemetryJaegerVersion=1.34.1

protobufVersion=3.25.3
guavaVersion=33.0.0-jre
geoip2Version=4.2.0

httpClientVersion=4.5.14
commonsNetVersion=3.10.0
commonsMath3Version=3.6.1
commonsIoVersion=2.11.0
commonsLang3Version=3.14.0
commonsIoVersion=2.14.0

# If indluxdb-java is updated, check new version of the transitive dependency okio-jvm
# If there is a higher new version, remove the dependency override of okio-jvm
influxdbJavaVersion=2.23
influxdbJavaVersion=2.24
okioJvmVersion=3.5.0

opencensusInfluxdbExporterVersion=1.2
armeriaVersion=1.23.1
testContainersVersion=1.18.3
armeriaVersion=1.27.1
testContainersVersion=1.19.5

### gradle plugin versions
### Check for newer version at https://plugins.gradle.org/
# io.spring.dependency-management
springDependencyManangementVersion=1.1.3
springDependencyManangementVersion=1.1.4
# org.owasp.dependencycheck
owaspDependencyCheckVersion=8.4.0
owaspDependencyCheckVersion=8.4.3
# org.cyclonedx.bom
cyclonedxBomVersion=1.7.4
cyclonedxBomVersion=1.8.2
# com.palantir.docker
palantirDockerVersion=0.35.0
versionsPlugin=0.48.0
versionsPlugin=0.51.0
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import com.google.common.collect.ImmutableMap;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest;
import io.opentelemetry.proto.common.v1.InstrumentationLibrary;
import io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans;
import io.opentelemetry.proto.common.v1.InstrumentationScope;
import io.opentelemetry.proto.trace.v1.ResourceSpans;
import io.opentelemetry.proto.trace.v1.ScopeSpans;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.OcelotSpanUtils;
Expand Down Expand Up @@ -49,23 +49,26 @@ public Collection<SpanData> convert(ExportTraceServiceRequest data) {

Map<String, String> customSpanAttributes = getCustomSpanAttributes();

resourceSpans.getInstrumentationLibrarySpansList()
resourceSpans.getScopeSpansList()
.stream()
.flatMap(librarySpans -> toSpanData(librarySpans, resource, customSpanAttributes))
.flatMap(scopeSpans -> toSpanData(scopeSpans, resource, customSpanAttributes))
.forEach(result::add);
}

return result;
}

/**
* @return Converts an {@link InstrumentationLibrarySpans} instance to a stream of individual {@link SpanData} instances.
* @return Converts an {@link ScopeSpans} instance to a stream of individual {@link SpanData} instances.
*/
private Stream<SpanData> toSpanData(InstrumentationLibrarySpans librarySpans, Resource resource, Map<String, String> customSpanAttributes) {
InstrumentationLibrary library = librarySpans.getInstrumentationLibrary();
InstrumentationScopeInfo instrumentationScopeInfo = InstrumentationScopeInfo.builder(library.getName()).setVersion(library.getVersion()).build();

return librarySpans.getSpansList()
private Stream<SpanData> toSpanData(ScopeSpans scopeSpans, Resource resource, Map<String, String> customSpanAttributes) {
InstrumentationScope scope = scopeSpans.getScope();
InstrumentationScopeInfo instrumentationScopeInfo = InstrumentationScopeInfo
.builder(scope.getName())
.setVersion(scope.getVersion())
.build();

return scopeSpans.getSpansList()
.stream()
.map(protoSpan -> OcelotSpanUtils.createSpanData(protoSpan, resource, instrumentationScopeInfo, customSpanAttributes))
.filter(Objects::nonNull);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package rocks.inspectit.oce.eum.server.exporters;

import io.prometheus.client.CollectorRegistry;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -92,11 +89,10 @@ protected void postSpan(String traceId) throws Exception {
*
* @param traceId the trace id
*
* @return
* @return String of a dummy span with provided trace id
*/
private String getSpanString(String traceId) {
String now = System.currentTimeMillis() + "000001";
return "{\"resourceSpans\":[{\"resource\":{\"attributes\":[{\"key\":\"service.name\",\"value\":{\"stringValue\":\"" + SERVICE_NAME + "\"}},{\"key\":\"telemetry.sdk.language\",\"value\":{\"stringValue\":\"webjs\"}},{\"key\":\"telemetry.sdk.name\",\"value\":{\"stringValue\":\"opentelemetry\"}},{\"key\":\"telemetry.sdk.version\",\"value\":{\"stringValue\":\"0.18.2\"}}],\"droppedAttributesCount\":0},\"instrumentationLibrarySpans\":[{\"spans\":[{\"traceId\":\"" + traceId + "\",\"spanId\":\"fc3d735ad8dd7399\",\"name\":\"HTTP GET\",\"kind\":3,\"startTimeUnixNano\":" + now + ",\"endTimeUnixNano\":" + now + ",\"attributes\":[{\"key\":\"http.method\",\"value\":{\"stringValue\":\"GET\"}},{\"key\":\"http.url\",\"value\":{\"stringValue\":\"http://localhost:1337?command=undefined\"}},{\"key\":\"http.response_content_length\",\"value\":{\"intValue\":665}},{\"key\":\"http.status_code\",\"value\":{\"intValue\":200}},{\"key\":\"http.status_text\",\"value\":{\"stringValue\":\"OK\"}},{\"key\":\"http.host\",\"value\":{\"stringValue\":\"localhost:1337\"}},{\"key\":\"http.scheme\",\"value\":{\"stringValue\":\"http\"}},{\"key\":\"http.user_agent\",\"value\":{\"stringValue\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36\"}}],\"droppedAttributesCount\":0,\"events\":[{\"timeUnixNano\":1619187815416888600,\"name\":\"open\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815417378600,\"name\":\"send\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815418218800,\"name\":\"fetchStart\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815420648700,\"name\":\"domainLookupStart\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815420648700,\"name\":\"domainLookupEnd\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815420648700,\"name\":\"connectStart\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619170468572063700,\"name\":\"secureConnectionStart\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815723468800,\"name\":\"connectEnd\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815723523600,\"name\":\"requestStart\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815732868600,\"name\":\"responseStart\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815734768600,\"name\":\"responseEnd\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815735928600,\"name\":\"loaded\",\"attributes\":[],\"droppedAttributesCount\":0}],\"droppedEventsCount\":0,\"status\":{\"code\":0},\"links\":[],\"droppedLinksCount\":0}],\"instrumentationLibrary\":{\"name\":\"@opentelemetry/instrumentation-xml-http-request\",\"version\":\"0.18.2\"}}]}]}";
return "{\"resourceSpans\":[{\"resource\":{\"attributes\":[{\"key\":\"service.name\",\"value\":{\"stringValue\":\"" + SERVICE_NAME + "\"}},{\"key\":\"telemetry.sdk.language\",\"value\":{\"stringValue\":\"webjs\"}},{\"key\":\"telemetry.sdk.name\",\"value\":{\"stringValue\":\"opentelemetry\"}},{\"key\":\"telemetry.sdk.version\",\"value\":{\"stringValue\":\"0.18.2\"}}],\"droppedAttributesCount\":0},\"scopeSpans\":[{\"spans\":[{\"traceId\":\"" + traceId + "\",\"spanId\":\"fc3d735ad8dd7399\",\"name\":\"HTTP GET\",\"kind\":3,\"startTimeUnixNano\":" + now + ",\"endTimeUnixNano\":" + now + ",\"attributes\":[{\"key\":\"http.method\",\"value\":{\"stringValue\":\"GET\"}},{\"key\":\"http.url\",\"value\":{\"stringValue\":\"http://localhost:1337?command=undefined\"}},{\"key\":\"http.response_content_length\",\"value\":{\"intValue\":665}},{\"key\":\"http.status_code\",\"value\":{\"intValue\":200}},{\"key\":\"http.status_text\",\"value\":{\"stringValue\":\"OK\"}},{\"key\":\"http.host\",\"value\":{\"stringValue\":\"localhost:1337\"}},{\"key\":\"http.scheme\",\"value\":{\"stringValue\":\"http\"}},{\"key\":\"http.user_agent\",\"value\":{\"stringValue\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36\"}}],\"droppedAttributesCount\":0,\"events\":[{\"timeUnixNano\":1619187815416888600,\"name\":\"open\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815417378600,\"name\":\"send\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815418218800,\"name\":\"fetchStart\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815420648700,\"name\":\"domainLookupStart\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815420648700,\"name\":\"domainLookupEnd\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815420648700,\"name\":\"connectStart\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619170468572063700,\"name\":\"secureConnectionStart\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815723468800,\"name\":\"connectEnd\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815723523600,\"name\":\"requestStart\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815732868600,\"name\":\"responseStart\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815734768600,\"name\":\"responseEnd\",\"attributes\":[],\"droppedAttributesCount\":0},{\"timeUnixNano\":1619187815735928600,\"name\":\"loaded\",\"attributes\":[],\"droppedAttributesCount\":0}],\"droppedEventsCount\":0,\"status\":{\"code\":0},\"links\":[],\"droppedLinksCount\":0}],\"scope\":{\"name\":\"@opentelemetry/instrumentation-xml-http-request\",\"version\":\"0.18.2\"}}]}]}";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceResponse;
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest;
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceResponse;
import io.opentelemetry.proto.trace.v1.ScopeSpans;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -170,9 +171,9 @@ protected void awaitSpansExported(String expectedTraceId) {
Stream<List<io.opentelemetry.proto.trace.v1.Span>> spansLis = grpcServer.traceRequests.stream()
.flatMap(tr -> tr.getResourceSpansList()
.stream()
.flatMap(rs -> rs.getInstrumentationLibrarySpansList()
.flatMap(rs -> rs.getScopeSpansList()
.stream()
.map(ils -> ils.getSpansList())));
.map(ScopeSpans::getSpansList)));

assertThat(spansLis.anyMatch(s -> s.stream()
.anyMatch(span -> TraceId.fromBytes(span.getTraceId().toByteArray())
Expand Down Expand Up @@ -207,7 +208,7 @@ protected void awaitMetricsExported(String metricName, double value, ViewDefinit
.stream()
.anyMatch(rm ->
// check for the given metrics
rm.getInstrumentationLibraryMetrics(0)
rm.getScopeMetrics(0)
.getMetricsList()
.stream()
.filter(metric -> metric.getName().equalsIgnoreCase(metricName))
Expand Down Expand Up @@ -236,7 +237,7 @@ protected void assertMetric(double value, boolean expected, ViewDefinitionSettin
assertThat(grpcServer.metricRequests.stream()
.anyMatch(mReq -> mReq.getResourceMetricsList()
.stream()
.anyMatch(rm -> rm.getInstrumentationLibraryMetricsList()
.anyMatch(rm -> rm.getScopeMetricsList()
.stream()
.anyMatch(iml -> iml.getMetricsList()
.stream()
Expand Down
Loading
Loading