Skip to content

Commit

Permalink
Upgraded OTel to 1.12.0 and Instrumentation to 1.11.1
Browse files Browse the repository at this point in the history
fixes gh-10
  • Loading branch information
marcingrzejszczak committed Mar 11, 2022
1 parent 5625248 commit d537206
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 49 deletions.
6 changes: 3 additions & 3 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def VERSIONS = [
'org.apache.logging.log4j:log4j-core:2.+',
'org.slf4j:slf4j-api:1.7.+',
// otel
'io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:1.10.1-alpha',
'io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:1.11.1-alpha',
// zipkin
'io.zipkin.aws:brave-propagation-aws:0.23.2',
// wavefront
Expand All @@ -29,8 +29,8 @@ def PLATFORM_VERSIONS = [
'io.micrometer:micrometer-bom:2.0.0-SNAPSHOT',
'io.zipkin.brave:brave-bom:5.13.2',
// opentelemetry-instrumentation-api dependency above with this
'io.opentelemetry:opentelemetry-bom:1.10.1',
'io.opentelemetry:opentelemetry-bom-alpha:1.10.1-alpha'
'io.opentelemetry:opentelemetry-bom:1.12.0',
'io.opentelemetry:opentelemetry-bom-alpha:1.12.0-alpha'
]

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,73 +22,73 @@
import io.micrometer.core.instrument.transport.http.HttpClientRequest;
import io.micrometer.core.instrument.transport.http.HttpClientResponse;
import io.micrometer.core.lang.Nullable;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;

/**
* Extracts OpenTelemetry http semantic attributes value for client http spans.
*
* @author Nikita Salnikov-Tarnovski
*/
public class DefaultHttpClientAttributesExtractor
extends HttpClientAttributesExtractor<HttpClientRequest, HttpClientResponse> {
public class DefaultHttpClientAttributesGetter
implements HttpClientAttributesGetter<HttpClientRequest, HttpClientResponse> {

@Nullable
@Override
protected String url(HttpClientRequest httpClientRequest) {
public String url(HttpClientRequest httpClientRequest) {
return httpClientRequest.url();
}

@Nullable
@Override
protected String flavor(HttpClientRequest httpClientRequest, @Nullable HttpClientResponse httpClientResponse) {
public String flavor(HttpClientRequest httpClientRequest, @Nullable HttpClientResponse httpClientResponse) {
return null;
}

@Override
protected String method(HttpClientRequest httpClientRequest) {
public String method(HttpClientRequest httpClientRequest) {
return httpClientRequest.method();
}

@Override
protected List<String> requestHeader(HttpClientRequest httpClientRequest, String name) {
public List<String> requestHeader(HttpClientRequest httpClientRequest, String name) {
String value = httpClientRequest.header(name);
return value == null ? Collections.emptyList() : Collections.singletonList(value);
}

@Nullable
@Override
protected Long requestContentLength(HttpClientRequest httpClientRequest,
public Long requestContentLength(HttpClientRequest httpClientRequest,
@Nullable HttpClientResponse httpClientResponse) {
return null;
}

@Nullable
@Override
protected Long requestContentLengthUncompressed(HttpClientRequest httpClientRequest,
public Long requestContentLengthUncompressed(HttpClientRequest httpClientRequest,
@Nullable HttpClientResponse httpClientResponse) {
return null;
}

@Override
protected Integer statusCode(HttpClientRequest httpClientRequest, HttpClientResponse httpClientResponse) {
public Integer statusCode(HttpClientRequest httpClientRequest, HttpClientResponse httpClientResponse) {
return httpClientResponse.statusCode();
}

@Nullable
@Override
protected Long responseContentLength(HttpClientRequest httpClientRequest, HttpClientResponse httpClientResponse) {
public Long responseContentLength(HttpClientRequest httpClientRequest, HttpClientResponse httpClientResponse) {
return null;
}

@Nullable
@Override
protected Long responseContentLengthUncompressed(HttpClientRequest httpClientRequest,
public Long responseContentLengthUncompressed(HttpClientRequest httpClientRequest,
HttpClientResponse httpClientResponse) {
return null;
}

@Override
protected List<String> responseHeader(HttpClientRequest httpClientRequest, HttpClientResponse httpClientResponse,
public List<String> responseHeader(HttpClientRequest httpClientRequest, HttpClientResponse httpClientResponse,
String name) {
String value = httpClientResponse.header(name);
return value == null ? Collections.emptyList() : Collections.singletonList(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@
import io.micrometer.core.instrument.transport.http.HttpServerRequest;
import io.micrometer.core.instrument.transport.http.HttpServerResponse;
import io.micrometer.core.lang.Nullable;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter;

/**
* Extracts OpenTelemetry http semantic attributes value for server http spans.
*
* @author Nikita Salnikov-Tarnovski
*/
public class DefaultHttpServerAttributesExtractor
extends HttpServerAttributesExtractor<HttpServerRequest, HttpServerResponse> {
implements HttpServerAttributesGetter<HttpServerRequest, HttpServerResponse> {

@Nullable
@Override
protected String flavor(HttpServerRequest httpServerRequest) {
public String flavor(HttpServerRequest httpServerRequest) {
return null;
}

@Nullable
@Override
protected String target(HttpServerRequest httpServerRequest) {
public String target(HttpServerRequest httpServerRequest) {
URI uri = toUri(httpServerRequest);
if (uri == null) {
return null;
Expand All @@ -61,13 +61,13 @@ private String queryPart(URI uri) {

@Nullable
@Override
protected String route(HttpServerRequest httpServerRequest) {
public String route(HttpServerRequest httpServerRequest) {
return httpServerRequest.route();
}

@Nullable
@Override
protected String scheme(HttpServerRequest httpServerRequest) {
public String scheme(HttpServerRequest httpServerRequest) {
String url = httpServerRequest.url();
if (url == null) {
return null;
Expand All @@ -83,57 +83,57 @@ protected String scheme(HttpServerRequest httpServerRequest) {

@Nullable
@Override
protected String serverName(HttpServerRequest httpServerRequest, @Nullable HttpServerResponse httpServerResponse) {
public String serverName(HttpServerRequest httpServerRequest, @Nullable HttpServerResponse httpServerResponse) {
return null;
}

@Nullable
@Override
protected String method(HttpServerRequest httpServerRequest) {
public String method(HttpServerRequest httpServerRequest) {
return httpServerRequest.method();
}

@Override
protected List<String> requestHeader(HttpServerRequest httpServerRequest, String name) {
public List<String> requestHeader(HttpServerRequest httpServerRequest, String name) {
String value = httpServerRequest.header(name);
return value == null ? Collections.emptyList() : Collections.singletonList(value);
}

@Nullable
@Override
protected Long requestContentLength(HttpServerRequest httpServerRequest,
public Long requestContentLength(HttpServerRequest httpServerRequest,
@Nullable HttpServerResponse httpServerResponse) {
return null;
}

@Nullable
@Override
protected Long requestContentLengthUncompressed(HttpServerRequest httpServerRequest,
public Long requestContentLengthUncompressed(HttpServerRequest httpServerRequest,
@Nullable HttpServerResponse httpServerResponse) {
return null;
}

@Nullable
@Override
protected Integer statusCode(HttpServerRequest httpServerRequest, HttpServerResponse httpServerResponse) {
public Integer statusCode(HttpServerRequest httpServerRequest, HttpServerResponse httpServerResponse) {
return httpServerResponse.statusCode();
}

@Nullable
@Override
protected Long responseContentLength(HttpServerRequest httpServerRequest, HttpServerResponse httpServerResponse) {
public Long responseContentLength(HttpServerRequest httpServerRequest, HttpServerResponse httpServerResponse) {
return null;
}

@Nullable
@Override
protected Long responseContentLengthUncompressed(HttpServerRequest httpServerRequest,
public Long responseContentLengthUncompressed(HttpServerRequest httpServerRequest,
HttpServerResponse httpServerResponse) {
return null;
}

@Override
protected List<String> responseHeader(HttpServerRequest httpServerRequest, HttpServerResponse httpServerResponse,
public List<String> responseHeader(HttpServerRequest httpServerRequest, HttpServerResponse httpServerResponse,
String name) {
String value = httpServerResponse.header(name);
return value == null ? Collections.emptyList() : Collections.singletonList(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
import io.micrometer.core.instrument.transport.http.HttpRequest;
import io.micrometer.core.instrument.transport.http.HttpResponse;
import io.micrometer.core.lang.Nullable;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter;

/**
* Extracts OpenTelemetry network semantic attributes value for client http spans.
*
* @author Nikita Salnikov-Tarnovski
*/
class HttpRequestNetClientAttributesExtractor extends NetClientAttributesExtractor<HttpRequest, HttpResponse> {
class HttpRequestNetClientAttributesExtractor implements NetClientAttributesGetter<HttpRequest, HttpResponse> {

@Nullable
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
package io.micrometer.tracing.otel.bridge;

import io.micrometer.core.instrument.transport.http.HttpRequest;
import io.micrometer.core.instrument.transport.http.HttpResponse;
import io.micrometer.core.lang.Nullable;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;

/**
* Extracts OpenTelemetry network semantic attributes value for server http spans.
*
* @author Nikita Salnikov-Tarnovski
*/
class HttpRequestNetServerAttributesExtractor extends NetServerAttributesExtractor<HttpRequest, HttpResponse> {
class HttpRequestNetServerAttributesExtractor implements NetServerAttributesGetter<HttpRequest> {

@Nullable
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.micrometer.core.instrument.transport.http.HttpClientRequest;
import io.micrometer.core.instrument.transport.http.HttpClientResponse;
import io.micrometer.core.instrument.transport.http.HttpRequest;
import io.micrometer.core.lang.Nullable;
import io.micrometer.core.util.internal.logging.InternalLogger;
import io.micrometer.core.util.internal.logging.InternalLoggerFactory;
import io.micrometer.tracing.SamplerFunction;
Expand All @@ -27,14 +28,15 @@
import io.micrometer.tracing.http.HttpClientHandler;
import io.micrometer.tracing.http.HttpRequestParser;
import io.micrometer.tracing.http.HttpResponseParser;
import io.micrometer.core.lang.Nullable;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.ContextKey;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;


/**
Expand All @@ -61,7 +63,7 @@ public class OtelHttpClientHandler implements HttpClientHandler {

public OtelHttpClientHandler(OpenTelemetry openTelemetry, @Nullable HttpRequestParser httpClientRequestParser,
@Nullable HttpResponseParser httpClientResponseParser, SamplerFunction<HttpRequest> samplerFunction,
HttpClientAttributesExtractor<HttpClientRequest, HttpClientResponse> httpAttributesExtractor) {
HttpClientAttributesGetter<HttpClientRequest, HttpClientResponse> httpAttributesExtractor) {
this.httpClientRequestParser = httpClientRequestParser;
this.httpClientResponseParser = httpClientResponseParser;
this.samplerFunction = samplerFunction;
Expand All @@ -70,8 +72,9 @@ public OtelHttpClientHandler(OpenTelemetry openTelemetry, @Nullable HttpRequestP
.<HttpClientRequest, HttpClientResponse>builder(openTelemetry, "io.micrometer.tracing",
HttpSpanNameExtractor.create(httpAttributesExtractor))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesExtractor))
.addAttributesExtractor(new HttpRequestNetClientAttributesExtractor())
.addAttributesExtractor(httpAttributesExtractor).addAttributesExtractor(new PathAttributeExtractor())
.addAttributesExtractor(NetClientAttributesExtractor.create(new HttpRequestNetClientAttributesExtractor()))
.addAttributesExtractor(HttpClientAttributesExtractor.create(httpAttributesExtractor))
.addAttributesExtractor(new PathAttributeExtractor())
.newClientInstrumenter(HttpClientRequest::header);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
import io.opentelemetry.context.propagation.TextMapGetter;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;

/**
* OpenTelemetry implementation of a {@link HttpServerHandler}.
Expand All @@ -60,7 +62,7 @@ public class OtelHttpServerHandler implements HttpServerHandler {

public OtelHttpServerHandler(OpenTelemetry openTelemetry, HttpRequestParser httpServerRequestParser,
HttpResponseParser httpServerResponseParser, Pattern skipPattern,
HttpServerAttributesExtractor<HttpServerRequest, HttpServerResponse> httpAttributesExtractor) {
HttpServerAttributesGetter<HttpServerRequest, HttpServerResponse> httpAttributesExtractor) {
this.httpServerRequestParser = httpServerRequestParser;
this.httpServerResponseParser = httpServerResponseParser;
this.pattern = skipPattern;
Expand All @@ -69,8 +71,9 @@ public OtelHttpServerHandler(OpenTelemetry openTelemetry, HttpRequestParser http
.<HttpServerRequest, HttpServerResponse>builder(openTelemetry, "io.micrometer.tracing",
HttpSpanNameExtractor.create(httpAttributesExtractor))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesExtractor))
.addAttributesExtractor(new HttpRequestNetServerAttributesExtractor())
.addAttributesExtractor(httpAttributesExtractor).addAttributesExtractor(new PathAttributeExtractor())
.addAttributesExtractor(NetServerAttributesExtractor.create(new HttpRequestNetServerAttributesExtractor()))
.addAttributesExtractor(HttpServerAttributesExtractor.create(httpAttributesExtractor))
.addAttributesExtractor(new PathAttributeExtractor())
.newServerInstrumenter(getGetter());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import io.micrometer.tracing.http.HttpClientHandler;
import io.micrometer.tracing.http.HttpServerHandler;
import io.micrometer.tracing.otel.bridge.ArrayListSpanProcessor;
import io.micrometer.tracing.otel.bridge.DefaultHttpClientAttributesExtractor;
import io.micrometer.tracing.otel.bridge.DefaultHttpClientAttributesGetter;
import io.micrometer.tracing.otel.bridge.DefaultHttpServerAttributesExtractor;
import io.micrometer.tracing.otel.bridge.OtelBaggageManager;
import io.micrometer.tracing.otel.bridge.OtelCurrentTraceContext;
Expand Down Expand Up @@ -291,7 +291,7 @@ private static HttpServerHandler httpServerHandler(OpenTelemetrySdk openTelemetr
}

private static HttpClientHandler httpClientHandler(OpenTelemetrySdk openTelemetrySdk) {
return new OtelHttpClientHandler(openTelemetrySdk, null, null, SamplerFunction.alwaysSample(), new DefaultHttpClientAttributesExtractor());
return new OtelHttpClientHandler(openTelemetrySdk, null, null, SamplerFunction.alwaysSample(), new DefaultHttpClientAttributesGetter());
}

private static Consumer<OtelBuildingBlocks> closingFunction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import io.micrometer.tracing.http.HttpClientHandler;
import io.micrometer.tracing.http.HttpServerHandler;
import io.micrometer.tracing.otel.bridge.ArrayListSpanProcessor;
import io.micrometer.tracing.otel.bridge.DefaultHttpClientAttributesExtractor;
import io.micrometer.tracing.otel.bridge.DefaultHttpClientAttributesGetter;
import io.micrometer.tracing.otel.bridge.DefaultHttpServerAttributesExtractor;
import io.micrometer.tracing.otel.bridge.OtelBaggageManager;
import io.micrometer.tracing.otel.bridge.OtelCurrentTraceContext;
Expand Down Expand Up @@ -350,7 +350,7 @@ private static HttpServerHandler httpServerHandler(OpenTelemetrySdk openTelemetr
}

private static HttpClientHandler httpClientHandler(OpenTelemetrySdk openTelemetrySdk) {
return new OtelHttpClientHandler(openTelemetrySdk, null, null, SamplerFunction.alwaysSample(), new DefaultHttpClientAttributesExtractor());
return new OtelHttpClientHandler(openTelemetrySdk, null, null, SamplerFunction.alwaysSample(), new DefaultHttpClientAttributesGetter());
}

private static Consumer<OtelBuildingBlocks> closingFunction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import io.micrometer.tracing.http.HttpClientHandler;
import io.micrometer.tracing.http.HttpServerHandler;
import io.micrometer.tracing.otel.bridge.ArrayListSpanProcessor;
import io.micrometer.tracing.otel.bridge.DefaultHttpClientAttributesExtractor;
import io.micrometer.tracing.otel.bridge.DefaultHttpClientAttributesGetter;
import io.micrometer.tracing.otel.bridge.DefaultHttpServerAttributesExtractor;
import io.micrometer.tracing.otel.bridge.OtelBaggageManager;
import io.micrometer.tracing.otel.bridge.OtelCurrentTraceContext;
Expand Down Expand Up @@ -344,7 +344,7 @@ private static HttpServerHandler httpServerHandler(OpenTelemetrySdk openTelemetr
}

private static HttpClientHandler httpClientHandler(OpenTelemetrySdk openTelemetrySdk) {
return new OtelHttpClientHandler(openTelemetrySdk, null, null, SamplerFunction.alwaysSample(), new DefaultHttpClientAttributesExtractor());
return new OtelHttpClientHandler(openTelemetrySdk, null, null, SamplerFunction.alwaysSample(), new DefaultHttpClientAttributesGetter());
}

private static Consumer<OtelBuildingBlocks> closingFunction() {
Expand Down

0 comments on commit d537206

Please sign in to comment.