Skip to content

Commit

Permalink
opentelemetry-http: upgrade optel version to 1.33.x
Browse files Browse the repository at this point in the history
Motivation:

We're experiencing some degree of incompatibility with otel. This is
happening because we're using otels alpha API's for the semconv package
and they have walked on us.

Modifications:

Upgrade the dependency version.
  • Loading branch information
bryce-anderson committed Jan 8, 2025
1 parent 68055fa commit 8129228
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 51 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ jacksonVersion=2.16.2

openTracingVersion=0.33.0
zipkinReporterVersion=2.17.2
opentelemetryVersion=1.28.0
opentelemetryInstrumentationVersion=1.28.0-alpha
opentelemetryVersion=1.41.0
opentelemetryInstrumentationVersion=1.33.6-alpha

# gRPC
protobufGradlePluginVersion=0.9.4
Expand Down
6 changes: 3 additions & 3 deletions servicetalk-opentelemetry-asynccontext/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.google.code.findbugs:jsr305:3.0.2=compileClasspath,runtimeClasspath
io.opentelemetry:opentelemetry-api:1.28.0=compileClasspath,runtimeClasspath
io.opentelemetry:opentelemetry-bom:1.28.0=compileClasspath,runtimeClasspath
io.opentelemetry:opentelemetry-context:1.28.0=compileClasspath,runtimeClasspath
io.opentelemetry:opentelemetry-api:1.41.0=compileClasspath,runtimeClasspath
io.opentelemetry:opentelemetry-bom:1.41.0=compileClasspath,runtimeClasspath
io.opentelemetry:opentelemetry-context:1.41.0=compileClasspath,runtimeClasspath
org.jctools:jctools-core:4.0.3=runtimeClasspath
org.slf4j:slf4j-api:1.7.36=compileClasspath,runtimeClasspath
empty=annotationProcessor,spotbugsPlugins,testAnnotationProcessor
20 changes: 10 additions & 10 deletions servicetalk-opentelemetry-http/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.google.code.findbugs:jsr305:3.0.2=compileClasspath,runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:1.28.0-alpha=compileClasspath,runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:1.28.0=compileClasspath,runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:1.28.0-alpha=compileClasspath,runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:1.28.0=compileClasspath,runtimeClasspath
io.opentelemetry:opentelemetry-api:1.28.0=compileClasspath,runtimeClasspath
io.opentelemetry:opentelemetry-bom-alpha:1.28.0-alpha=compileClasspath,runtimeClasspath
io.opentelemetry:opentelemetry-bom:1.28.0=compileClasspath,runtimeClasspath
io.opentelemetry:opentelemetry-context:1.28.0=compileClasspath,runtimeClasspath
io.opentelemetry:opentelemetry-extension-incubator:1.28.0-alpha=runtimeClasspath
io.opentelemetry:opentelemetry-semconv:1.28.0-alpha=compileClasspath,runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:1.33.6-alpha=compileClasspath,runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:1.33.6=compileClasspath,runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:1.33.6-alpha=compileClasspath,runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:1.33.6=compileClasspath,runtimeClasspath
io.opentelemetry.semconv:opentelemetry-semconv:1.23.1-alpha=compileClasspath,runtimeClasspath
io.opentelemetry:opentelemetry-api-incubator:1.41.0-alpha=runtimeClasspath
io.opentelemetry:opentelemetry-api:1.41.0=compileClasspath,runtimeClasspath
io.opentelemetry:opentelemetry-bom-alpha:1.41.0-alpha=compileClasspath,runtimeClasspath
io.opentelemetry:opentelemetry-bom:1.41.0=compileClasspath,runtimeClasspath
io.opentelemetry:opentelemetry-context:1.41.0=compileClasspath,runtimeClasspath
org.jctools:jctools-core:4.0.3=runtimeClasspath
org.slf4j:slf4j-api:1.7.36=runtimeClasspath
empty=annotationProcessor,spotbugsPlugins,testAnnotationProcessor
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;

import java.util.function.UnaryOperator;

import static io.opentelemetry.semconv.SemanticAttributes.PEER_SERVICE;

/**
* An HTTP filter that supports <a href="https://opentelemetry.io/docs/instrumentation/java/">open telemetry</a>.
* <p>
Expand Down Expand Up @@ -120,25 +121,28 @@ public OpenTelemetryHttpRequestFilter() {
final OpenTelemetryOptions opentelemetryOptions) {
super(openTelemetry);
SpanNameExtractor<HttpRequestMetaData> serverSpanNameExtractor =
HttpSpanNameExtractor.create(ServiceTalkHttpAttributesGetter.INSTANCE);
HttpSpanNameExtractor.create(ServiceTalkHttpAttributesGetter.SERVER_INSTANCE);
InstrumenterBuilder<HttpRequestMetaData, HttpResponseMetaData> clientInstrumenterBuilder =
Instrumenter.builder(openTelemetry, INSTRUMENTATION_SCOPE_NAME, serverSpanNameExtractor);
clientInstrumenterBuilder.setSpanStatusExtractor(ServicetalkSpanStatusExtractor.INSTANCE);

clientInstrumenterBuilder
.addAttributesExtractor(HttpClientAttributesExtractor
.builder(ServiceTalkHttpAttributesGetter.INSTANCE, ServiceTalkNetAttributesGetter.INSTANCE)
.addAttributesExtractor(
HttpClientAttributesExtractor
.builder(ServiceTalkHttpAttributesGetter.CLIENT_INSTANCE,
ServiceTalkNetAttributesGetter.CLIENT_INSTANCE)
.setCapturedRequestHeaders(opentelemetryOptions.capturedRequestHeaders())
.setCapturedResponseHeaders(opentelemetryOptions.capturedResponseHeaders())
.build())
.addAttributesExtractor(NetClientAttributesExtractor.create(ServiceTalkNetAttributesGetter.INSTANCE));
.addAttributesExtractor(NetClientAttributesExtractor.create(
ServiceTalkNetAttributesGetter.CLIENT_INSTANCE));
if (opentelemetryOptions.enableMetrics()) {
clientInstrumenterBuilder.addOperationMetrics(HttpClientMetrics.get());
}
componentName = componentName.trim();
if (!componentName.isEmpty()) {
clientInstrumenterBuilder.addAttributesExtractor(
AttributesExtractor.constant(SemanticAttributes.PEER_SERVICE, componentName));
AttributesExtractor.constant(PEER_SERVICE, componentName));
}
instrumenter =
clientInstrumenterBuilder.buildClientInstrumenter(RequestHeadersPropagatorSetter.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,20 @@ public OpenTelemetryHttpServerFilter(final OpenTelemetryOptions opentelemetryOpt
OpenTelemetryHttpServerFilter(final OpenTelemetry openTelemetry, final OpenTelemetryOptions opentelemetryOptions) {
super(openTelemetry);
SpanNameExtractor<HttpRequestMetaData> serverSpanNameExtractor =
HttpSpanNameExtractor.create(ServiceTalkHttpAttributesGetter.INSTANCE);
HttpSpanNameExtractor.create(ServiceTalkHttpAttributesGetter.SERVER_INSTANCE);
InstrumenterBuilder<HttpRequestMetaData, HttpResponseMetaData> serverInstrumenterBuilder =
Instrumenter.builder(openTelemetry, INSTRUMENTATION_SCOPE_NAME, serverSpanNameExtractor);
serverInstrumenterBuilder.setSpanStatusExtractor(ServicetalkSpanStatusExtractor.INSTANCE);

serverInstrumenterBuilder
.addAttributesExtractor(HttpServerAttributesExtractor
.builder(ServiceTalkHttpAttributesGetter.INSTANCE, ServiceTalkNetAttributesGetter.INSTANCE)
.builder(ServiceTalkHttpAttributesGetter.SERVER_INSTANCE,
ServiceTalkNetAttributesGetter.SERVER_INSTANCE)
.setCapturedRequestHeaders(opentelemetryOptions.capturedRequestHeaders())
.setCapturedResponseHeaders(opentelemetryOptions.capturedResponseHeaders())
.build())
.addAttributesExtractor(NetServerAttributesExtractor.create(ServiceTalkNetAttributesGetter.INSTANCE));
.addAttributesExtractor(NetServerAttributesExtractor.create(
ServiceTalkNetAttributesGetter.SERVER_INSTANCE));
if (opentelemetryOptions.enableMetrics()) {
serverInstrumenterBuilder.addOperationMetrics(HttpServerMetrics.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,38 @@
import static java.util.Collections.singletonList;
import static java.util.Collections.unmodifiableList;

final class ServiceTalkHttpAttributesGetter implements
HttpClientAttributesGetter<HttpRequestMetaData, HttpResponseMetaData>,
HttpServerAttributesGetter<HttpRequestMetaData, HttpResponseMetaData> {
abstract class ServiceTalkHttpAttributesGetter {

static final ServiceTalkHttpAttributesGetter INSTANCE = new ServiceTalkHttpAttributesGetter();
static final HttpClientAttributesGetter<HttpRequestMetaData, HttpResponseMetaData> CLIENT_INSTANCE =
new ClientGetter();

static final HttpServerAttributesGetter<HttpRequestMetaData, HttpResponseMetaData> SERVER_INSTANCE =
new ServerGetter();

private ServiceTalkHttpAttributesGetter() {
}

@Override
public String getHttpRequestMethod(final HttpRequestMetaData httpRequestMetaData) {
return httpRequestMetaData.method().name();
}

@Override
public List<String> getHttpRequestHeader(final HttpRequestMetaData httpRequestMetaData, final String name) {
return getHeaderValues(httpRequestMetaData.headers(), name);
}

@Override
public Integer getHttpResponseStatusCode(final HttpRequestMetaData httpRequestMetaData,
final HttpResponseMetaData httpResponseMetaData,
@Nullable final Throwable error) {
return httpResponseMetaData.status().code();
}

@Override
public List<String> getHttpResponseHeader(final HttpRequestMetaData httpRequestMetaData,
final HttpResponseMetaData httpResponseMetaData,
final String name) {
return getHeaderValues(httpResponseMetaData.headers(), name);
}

@Nullable
@Override
public String getUrlFull(final HttpRequestMetaData request) {
HostAndPort effectiveHostAndPort = request.effectiveHostAndPort();
if (effectiveHostAndPort == null) {
Expand All @@ -78,18 +75,16 @@ public String getUrlFull(final HttpRequestMetaData request) {
return requestScheme + "://" + hostAndPort + '/' + request.requestTarget();
}

@Override
public String getUrlScheme(final HttpRequestMetaData httpRequestMetaData) {
final String scheme = httpRequestMetaData.scheme();
return scheme == null ? "http" : scheme;
}

@Override
public String getUrlPath(final HttpRequestMetaData httpRequestMetaData) {
return httpRequestMetaData.path();
}

@Override
@Nullable
public String getUrlQuery(final HttpRequestMetaData httpRequestMetaData) {
return httpRequestMetaData.query();
}
Expand All @@ -111,4 +106,23 @@ private static List<String> getHeaderValues(final HttpHeaders headers, final Str
}
return unmodifiableList(result);
}

private static final class ClientGetter extends ServiceTalkHttpAttributesGetter
implements HttpClientAttributesGetter<HttpRequestMetaData, HttpResponseMetaData> {
@Nullable
@Override
public String getServerAddress(HttpRequestMetaData metaData) {
return null;
}

@Nullable
@Override
public Integer getServerPort(HttpRequestMetaData metaData) {
return null;
}
}

private static final class ServerGetter extends ServiceTalkHttpAttributesGetter
implements HttpServerAttributesGetter<HttpRequestMetaData, HttpResponseMetaData> {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,21 @@

import javax.annotation.Nullable;

final class ServiceTalkNetAttributesGetter implements
NetClientAttributesGetter<HttpRequestMetaData, HttpResponseMetaData>,
NetServerAttributesGetter<HttpRequestMetaData, HttpResponseMetaData> {
abstract class ServiceTalkNetAttributesGetter {

static final ServiceTalkNetAttributesGetter INSTANCE = new ServiceTalkNetAttributesGetter();
static final NetClientAttributesGetter<HttpRequestMetaData, HttpResponseMetaData> CLIENT_INSTANCE =
new ClientGetter();
static final NetServerAttributesGetter<HttpRequestMetaData, HttpResponseMetaData> SERVER_INSTANCE =
new ServerGetter();

private ServiceTalkNetAttributesGetter() {
}

@Override
public String getNetworkProtocolName(final HttpRequestMetaData request,
@Nullable final HttpResponseMetaData response) {
return "http";
}

@Override
public String getNetworkProtocolVersion(final HttpRequestMetaData request,
@Nullable final HttpResponseMetaData response) {
if (response == null) {
Expand All @@ -49,24 +48,23 @@ public String getNetworkProtocolVersion(final HttpRequestMetaData request,
return response.version().fullVersion();
}

@Override
@Nullable
public String getServerAddress(final HttpRequestMetaData request) {
final HostAndPort effectiveHostAndPort = request.effectiveHostAndPort();
return effectiveHostAndPort != null ? effectiveHostAndPort.hostName() : null;
}

@Nullable
@Override
public Integer getServerPort(final HttpRequestMetaData request) {
final HostAndPort effectiveHostAndPort = request.effectiveHostAndPort();
return effectiveHostAndPort != null ? effectiveHostAndPort.port() : null;
}

@Nullable
@Override
public String getNetworkType(final HttpRequestMetaData requestMetaData,
@Nullable final HttpResponseMetaData metaData) {
return NetServerAttributesGetter.super.getNetworkType(requestMetaData, metaData);
private static final class ClientGetter extends ServiceTalkNetAttributesGetter implements
NetClientAttributesGetter<HttpRequestMetaData, HttpResponseMetaData> {
}

private static final class ServerGetter extends ServiceTalkNetAttributesGetter implements
NetServerAttributesGetter<HttpRequestMetaData, HttpResponseMetaData> {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.opentelemetry.semconv.SemanticAttributes;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import io.opentelemetry.context.propagation.TextMapSetter;
import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.opentelemetry.semconv.SemanticAttributes;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down

0 comments on commit 8129228

Please sign in to comment.