Make some adjustments to OpenTelemetry usage and default configuration (#1932)

* Make some adjustments to OpenTelemetry usage and default configuration

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Remove additional empty line

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Remove extra test - no assertions in it providing value

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* remove extra dependency

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* use dev, not default

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>
pull/1940/head
Antoine Toulme 4 years ago committed by GitHub
parent 0187bed075
commit 1c86ecbc97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java
  2. 4
      acceptance-tests/tests/build.gradle
  3. 58
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/OpenTelemetryAcceptanceTest.java
  4. 4
      docker/graalvm/Dockerfile
  5. 4
      docker/openjdk-11/Dockerfile
  6. 4
      docker/openjdk-latest/Dockerfile
  7. 15
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpService.java
  8. 5
      gradle/versions.gradle

@ -297,7 +297,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable
} }
public Optional<Integer> getJsonRpcSocketPort() { public Optional<Integer> getJsonRpcSocketPort() {
if (isWebSocketsRpcEnabled()) { if (isJsonRpcEnabled()) {
return Optional.of(Integer.valueOf(portsProperties.getProperty("json-rpc"))); return Optional.of(Integer.valueOf(portsProperties.getProperty("json-rpc")));
} else { } else {
return Optional.empty(); return Optional.empty();

@ -41,6 +41,10 @@ dependencies {
testImplementation 'io.opentelemetry:opentelemetry-sdk' testImplementation 'io.opentelemetry:opentelemetry-sdk'
testImplementation 'io.opentelemetry:opentelemetry-sdk-trace' testImplementation 'io.opentelemetry:opentelemetry-sdk-trace'
testImplementation 'io.opentelemetry:opentelemetry-exporter-otlp' testImplementation 'io.opentelemetry:opentelemetry-exporter-otlp'
testImplementation 'io.opentracing.contrib:opentracing-okhttp3'
testImplementation 'io.opentracing:opentracing-api'
testImplementation 'io.opentracing:opentracing-util'
testImplementation 'io.jaegertracing:jaeger-client'
testImplementation 'junit:junit' testImplementation 'junit:junit'
testImplementation 'net.consensys:orion' testImplementation 'net.consensys:orion'
testImplementation 'org.apache.commons:commons-compress' testImplementation 'org.apache.commons:commons-compress'

@ -28,10 +28,12 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.google.common.io.Closer; import com.google.common.io.Closer;
import com.google.protobuf.ByteString;
import io.grpc.Server; import io.grpc.Server;
import io.grpc.Status; import io.grpc.Status;
import io.grpc.netty.NettyServerBuilder; import io.grpc.netty.NettyServerBuilder;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;
import io.jaegertracing.Configuration;
import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest; import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest;
import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceResponse; import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceResponse;
import io.opentelemetry.proto.collector.metrics.v1.MetricsServiceGrpc; import io.opentelemetry.proto.collector.metrics.v1.MetricsServiceGrpc;
@ -40,6 +42,15 @@ import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceResponse;
import io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc; import io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc;
import io.opentelemetry.proto.metrics.v1.ResourceMetrics; import io.opentelemetry.proto.metrics.v1.ResourceMetrics;
import io.opentelemetry.proto.trace.v1.ResourceSpans; import io.opentelemetry.proto.trace.v1.ResourceSpans;
import io.opentelemetry.proto.trace.v1.Span;
import io.opentracing.Tracer;
import io.opentracing.contrib.okhttp3.TracingCallFactory;
import okhttp3.Call;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -166,6 +177,53 @@ public class OpenTelemetryAcceptanceTest extends AcceptanceTestBase {
net.netVersion().verify(metricsNode); net.netVersion().verify(metricsNode);
List<ResourceSpans> spans = fakeTracesCollector.getReceivedSpans(); List<ResourceSpans> spans = fakeTracesCollector.getReceivedSpans();
assertThat(spans.isEmpty()).isFalse(); assertThat(spans.isEmpty()).isFalse();
Span internalSpan = spans.get(0).getInstrumentationLibrarySpans(0).getSpans(0);
assertThat(internalSpan.getKind()).isEqualTo(Span.SpanKind.SPAN_KIND_INTERNAL);
ByteString parent = internalSpan.getParentSpanId();
assertThat(parent.isEmpty()).isFalse();
Span serverSpan = spans.get(0).getInstrumentationLibrarySpans(0).getSpans(1);
assertThat(serverSpan.getKind()).isEqualTo(Span.SpanKind.SPAN_KIND_SERVER);
ByteString rootSpanId = serverSpan.getParentSpanId();
assertThat(rootSpanId.isEmpty()).isTrue();
});
}
@Test
public void traceReportingWithTraceId() {
WaitUtils.waitFor(
30,
() -> {
// call the json RPC endpoint to generate a trace - with trace metadata of our own
OkHttpClient okClient = new OkHttpClient();
Configuration config =
new Configuration("okhttp")
.withSampler(
Configuration.SamplerConfiguration.fromEnv().withType("const").withParam(1));
Tracer tracer = config.getTracer();
Call.Factory client = new TracingCallFactory(okClient, tracer);
Request request =
new Request.Builder()
.url("http://localhost:" + metricsNode.getJsonRpcSocketPort().get())
.post(
RequestBody.create(
"{\"jsonrpc\":\"2.0\",\"method\":\"net_version\",\"params\":[],\"id\":255}",
MediaType.get("application/json")))
.build();
Response response = client.newCall(request).execute();
assertThat(response.code()).isEqualTo(200);
List<ResourceSpans> spans = new ArrayList<>(fakeTracesCollector.getReceivedSpans());
fakeTracesCollector.getReceivedSpans().clear();
assertThat(spans.isEmpty()).isFalse();
Span internalSpan = spans.get(0).getInstrumentationLibrarySpans(0).getSpans(0);
assertThat(internalSpan.getKind()).isEqualTo(Span.SpanKind.SPAN_KIND_INTERNAL);
ByteString parent = internalSpan.getParentSpanId();
assertThat(parent.isEmpty()).isFalse();
Span serverSpan = spans.get(0).getInstrumentationLibrarySpans(0).getSpans(1);
assertThat(serverSpan.getKind()).isEqualTo(Span.SpanKind.SPAN_KIND_SERVER);
ByteString rootSpanId = serverSpan.getParentSpanId();
assertThat(rootSpanId.isEmpty()).isFalse();
}); });
} }
} }

@ -1,5 +1,6 @@
FROM ghcr.io/graalvm/graalvm-ce:ol7-java11-21.0.0 FROM ghcr.io/graalvm/graalvm-ce:ol7-java11-21.0.0
ARG VERSION="dev"
RUN adduser --home /opt/besu besu && \ RUN adduser --home /opt/besu besu && \
chown besu:besu /opt/besu chown besu:besu /opt/besu
@ -22,7 +23,7 @@ ENV BESU_RPC_WS_HOST 0.0.0.0
ENV BESU_GRAPHQL_HTTP_HOST 0.0.0.0 ENV BESU_GRAPHQL_HTTP_HOST 0.0.0.0
ENV BESU_PID_PATH "/tmp/pid" ENV BESU_PID_PATH "/tmp/pid"
ENV OTEL_RESOURCE_ATTRIBUTES="service.name=besu-$VERSION" ENV OTEL_RESOURCE_ATTRIBUTES="service.name=besu,service.version=$VERSION"
ENV PATH="/opt/besu/bin:${PATH}" ENV PATH="/opt/besu/bin:${PATH}"
ENTRYPOINT ["besu"] ENTRYPOINT ["besu"]
@ -31,7 +32,6 @@ HEALTHCHECK --start-period=5s --interval=5s --timeout=1s --retries=10 CMD bash -
# Build-time metadata as defined at http://label-schema.org # Build-time metadata as defined at http://label-schema.org
ARG BUILD_DATE ARG BUILD_DATE
ARG VCS_REF ARG VCS_REF
ARG VERSION
LABEL org.label-schema.build-date=$BUILD_DATE \ LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="Besu" \ org.label-schema.name="Besu" \
org.label-schema.description="Enterprise Ethereum client" \ org.label-schema.description="Enterprise Ethereum client" \

@ -1,5 +1,6 @@
FROM openjdk:11.0.7-jre-slim-buster FROM openjdk:11.0.7-jre-slim-buster
ARG VERSION="dev"
RUN adduser --disabled-password --gecos "" --home /opt/besu besu && \ RUN adduser --disabled-password --gecos "" --home /opt/besu besu && \
chown besu:besu /opt/besu chown besu:besu /opt/besu
@ -22,7 +23,7 @@ ENV BESU_RPC_WS_HOST 0.0.0.0
ENV BESU_GRAPHQL_HTTP_HOST 0.0.0.0 ENV BESU_GRAPHQL_HTTP_HOST 0.0.0.0
ENV BESU_PID_PATH "/tmp/pid" ENV BESU_PID_PATH "/tmp/pid"
ENV OTEL_RESOURCE_ATTRIBUTES="service.name=besu-$VERSION" ENV OTEL_RESOURCE_ATTRIBUTES="service.name=besu,service.version=$VERSION"
ENV PATH="/opt/besu/bin:${PATH}" ENV PATH="/opt/besu/bin:${PATH}"
ENTRYPOINT ["besu"] ENTRYPOINT ["besu"]
@ -31,7 +32,6 @@ HEALTHCHECK --start-period=5s --interval=5s --timeout=1s --retries=10 CMD bash -
# Build-time metadata as defined at http://label-schema.org # Build-time metadata as defined at http://label-schema.org
ARG BUILD_DATE ARG BUILD_DATE
ARG VCS_REF ARG VCS_REF
ARG VERSION
LABEL org.label-schema.build-date=$BUILD_DATE \ LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="Besu" \ org.label-schema.name="Besu" \
org.label-schema.description="Enterprise Ethereum client" \ org.label-schema.description="Enterprise Ethereum client" \

@ -1,5 +1,6 @@
FROM openjdk:slim-buster FROM openjdk:slim-buster
ARG VERSION="dev"
RUN adduser --disabled-password --gecos "" --home /opt/besu besu && \ RUN adduser --disabled-password --gecos "" --home /opt/besu besu && \
chown besu:besu /opt/besu chown besu:besu /opt/besu
@ -22,7 +23,7 @@ ENV BESU_RPC_WS_HOST 0.0.0.0
ENV BESU_GRAPHQL_HTTP_HOST 0.0.0.0 ENV BESU_GRAPHQL_HTTP_HOST 0.0.0.0
ENV BESU_PID_PATH "/tmp/pid" ENV BESU_PID_PATH "/tmp/pid"
ENV OTEL_RESOURCE_ATTRIBUTES="service.name=besu-$VERSION" ENV OTEL_RESOURCE_ATTRIBUTES="service.name=besu,service.version=$VERSION"
ENV PATH="/opt/besu/bin:${PATH}" ENV PATH="/opt/besu/bin:${PATH}"
ENTRYPOINT ["besu"] ENTRYPOINT ["besu"]
@ -31,7 +32,6 @@ HEALTHCHECK --start-period=5s --interval=5s --timeout=1s --retries=10 CMD bash -
# Build-time metadata as defined at http://label-schema.org # Build-time metadata as defined at http://label-schema.org
ARG BUILD_DATE ARG BUILD_DATE
ARG VCS_REF ARG VCS_REF
ARG VERSION
LABEL org.label-schema.build-date=$BUILD_DATE \ LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="Besu" \ org.label-schema.name="Besu" \
org.label-schema.description="Enterprise Ethereum client" \ org.label-schema.description="Enterprise Ethereum client" \

@ -67,12 +67,15 @@ import com.google.common.base.Splitter;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpResponseStatus;
import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator;
import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.StatusCode; import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context; import io.opentelemetry.context.Context;
import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.extension.trace.propagation.B3Propagator; import io.opentelemetry.extension.trace.propagation.B3Propagator;
import io.opentelemetry.extension.trace.propagation.JaegerPropagator;
import io.opentelemetry.extension.trace.propagation.TraceMultiPropagator;
import io.vertx.core.CompositeFuture; import io.vertx.core.CompositeFuture;
import io.vertx.core.Future; import io.vertx.core.Future;
import io.vertx.core.Handler; import io.vertx.core.Handler;
@ -108,6 +111,12 @@ public class JsonRpcHttpService {
private static final JsonRpcResponse NO_RESPONSE = new JsonRpcNoResponse(); private static final JsonRpcResponse NO_RESPONSE = new JsonRpcNoResponse();
private static final String EMPTY_RESPONSE = ""; private static final String EMPTY_RESPONSE = "";
private static final TextMapPropagator traceFormats =
TraceMultiPropagator.create(
JaegerPropagator.getInstance(),
B3Propagator.getInstance(),
W3CBaggagePropagator.getInstance());
private static final TextMapPropagator.Getter<HttpServerRequest> requestAttributesGetter = private static final TextMapPropagator.Getter<HttpServerRequest> requestAttributesGetter =
new TextMapPropagator.Getter<>() { new TextMapPropagator.Getter<>() {
@Override @Override
@ -313,17 +322,15 @@ public class JsonRpcHttpService {
final SocketAddress address = routingContext.request().connection().remoteAddress(); final SocketAddress address = routingContext.request().connection().remoteAddress();
Context parent = Context parent =
B3Propagator.getInstance() traceFormats.extract(Context.current(), routingContext.request(), requestAttributesGetter);
.extract(Context.current(), routingContext.request(), requestAttributesGetter);
final Span serverSpan = final Span serverSpan =
tracer tracer
.spanBuilder(address.host() + ":" + address.port()) .spanBuilder(address.host() + ":" + address.port())
.setParent(parent) .setParent(parent)
.setSpanKind(Span.Kind.SERVER) .setSpanKind(Span.Kind.SERVER)
.startSpan(); .startSpan();
routingContext.put(SPAN_CONTEXT, Context.root().with(serverSpan)); routingContext.put(SPAN_CONTEXT, Context.current().with(serverSpan));
routingContext.addBodyEndHandler(event -> serverSpan.end());
routingContext.addEndHandler( routingContext.addEndHandler(
event -> { event -> {
if (event.failed()) { if (event.failed()) {

@ -65,6 +65,11 @@ dependencyManagement {
dependency 'io.opentelemetry:opentelemetry-sdk-trace:0.13.1' dependency 'io.opentelemetry:opentelemetry-sdk-trace:0.13.1'
dependency 'io.opentelemetry:opentelemetry-sdk:0.13.1' dependency 'io.opentelemetry:opentelemetry-sdk:0.13.1'
dependency 'io.opentracing.contrib:opentracing-okhttp3:3.0.0'
dependency 'io.opentracing:opentracing-api:0.33.0'
dependency 'io.opentracing:opentracing-util:0.33.0'
dependency 'io.jaegertracing:jaeger-client:1.5.0'
dependency 'io.pkts:pkts-core:3.0.7' dependency 'io.pkts:pkts-core:3.0.7'
dependency 'io.prometheus:simpleclient:0.9.0' dependency 'io.prometheus:simpleclient:0.9.0'

Loading…
Cancel
Save