Update semconv to 1.21.0, PART 2 - HTTP (#9372)

This commit is contained in:
Trask Stalnaker 2023-09-07 08:25:23 -07:00 committed by GitHub
parent c50ae6eb29
commit cc4e1bf1ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 139 additions and 122 deletions

View File

@ -9,6 +9,7 @@ import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -46,9 +47,11 @@ final class MetricsView {
// the list of rpc client metrics attributes is from // the list of rpc client metrics attributes is from
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/rpc.md#attributes // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/rpc.md#attributes
Set<AttributeKey> view = new HashSet<>(alwaysInclude); Set<AttributeKey> view = new HashSet<>(alwaysInclude);
view.add(SemanticAttributes.NET_PEER_NAME); if (SemconvStability.emitOldHttpSemconv()) {
view.add(SemanticAttributes.NET_PEER_PORT); view.add(SemanticAttributes.NET_PEER_NAME);
view.add(SemanticAttributes.NET_TRANSPORT); view.add(SemanticAttributes.NET_PEER_PORT);
view.add(SemanticAttributes.NET_TRANSPORT);
}
return view; return view;
} }
@ -56,8 +59,10 @@ final class MetricsView {
// the list of rpc server metrics attributes is from // the list of rpc server metrics attributes is from
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/rpc.md#attributes // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/rpc.md#attributes
Set<AttributeKey> view = new HashSet<>(alwaysInclude); Set<AttributeKey> view = new HashSet<>(alwaysInclude);
view.add(SemanticAttributes.NET_HOST_NAME); if (SemconvStability.emitOldHttpSemconv()) {
view.add(SemanticAttributes.NET_TRANSPORT); view.add(SemanticAttributes.NET_HOST_NAME);
view.add(SemanticAttributes.NET_TRANSPORT);
}
return view; return view;
} }
@ -65,8 +70,10 @@ final class MetricsView {
// the list of rpc server metrics attributes is from // the list of rpc server metrics attributes is from
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/rpc.md#attributes // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/rpc.md#attributes
Set<AttributeKey> view = new HashSet<>(alwaysInclude); Set<AttributeKey> view = new HashSet<>(alwaysInclude);
view.add(SemanticAttributes.NET_SOCK_HOST_ADDR); if (SemconvStability.emitOldHttpSemconv()) {
view.add(SemanticAttributes.NET_TRANSPORT); view.add(SemanticAttributes.NET_SOCK_HOST_ADDR);
view.add(SemanticAttributes.NET_TRANSPORT);
}
return view; return view;
} }
@ -81,7 +88,8 @@ final class MetricsView {
static Attributes applyServerView(Attributes startAttributes, Attributes endAttributes) { static Attributes applyServerView(Attributes startAttributes, Attributes endAttributes) {
Set<AttributeKey> fullSet = serverView; Set<AttributeKey> fullSet = serverView;
if (!containsAttribute(SemanticAttributes.NET_HOST_NAME, startAttributes, endAttributes)) { if (SemconvStability.emitOldHttpSemconv()
&& !containsAttribute(SemanticAttributes.NET_HOST_NAME, startAttributes, endAttributes)) {
fullSet = serverFallbackView; fullSet = serverFallbackView;
} }
return applyView(fullSet, startAttributes, endAttributes); return applyView(fullSet, startAttributes, endAttributes);

View File

@ -5,19 +5,15 @@
package io.opentelemetry.javaagent.instrumentation.apachehttpasyncclient; package io.opentelemetry.javaagent.instrumentation.apachehttpasyncclient;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.net.URI; import java.net.URI;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
@ -226,14 +222,6 @@ class ApacheHttpAsyncClientTest {
void configureTest(HttpClientTestOptions.Builder optionsBuilder) { void configureTest(HttpClientTestOptions.Builder optionsBuilder) {
optionsBuilder.setUserAgent("httpasyncclient"); optionsBuilder.setUserAgent("httpasyncclient");
optionsBuilder.setHttpAttributes(
endpoint -> {
Set<AttributeKey<?>> attributes =
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
attributes.add(SemanticAttributes.HTTP_SCHEME);
attributes.add(SemanticAttributes.HTTP_TARGET);
return attributes;
});
} }
static String fullPathFromUri(URI uri) { static String fullPathFromUri(URI uri) {

View File

@ -5,13 +5,11 @@
package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v4_0; package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v4_0;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.HttpRequest; import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
@ -26,11 +24,6 @@ abstract class AbstractApacheHttpClientTest<T extends HttpRequest>
@Override @Override
protected void configure(HttpClientTestOptions.Builder optionsBuilder) { protected void configure(HttpClientTestOptions.Builder optionsBuilder) {
optionsBuilder.setUserAgent(USER_AGENT); optionsBuilder.setUserAgent(USER_AGENT);
optionsBuilder.setHttpAttributes(AbstractApacheHttpClientTest::getHttpAttributes);
}
private static Set<AttributeKey<?>> getHttpAttributes(URI endpoint) {
return HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES;
} }
@Override @Override

View File

@ -5,18 +5,14 @@
package io.opentelemetry.instrumentation.apachehttpclient.v4_3; package io.opentelemetry.instrumentation.apachehttpclient.v4_3;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.net.URI; import java.net.URI;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.HttpRequest; import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
@ -337,14 +333,6 @@ public abstract class AbstractApacheHttpClientTest {
static void configureTest(HttpClientTestOptions.Builder optionsBuilder) { static void configureTest(HttpClientTestOptions.Builder optionsBuilder) {
optionsBuilder.setUserAgent("apachehttpclient"); optionsBuilder.setUserAgent("apachehttpclient");
optionsBuilder.setHttpAttributes(
endpoint -> {
Set<AttributeKey<?>> attributes =
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
attributes.add(SemanticAttributes.HTTP_SCHEME);
attributes.add(SemanticAttributes.HTTP_TARGET);
return attributes;
});
} }
static String fullPathFromUri(URI uri) { static String fullPathFromUri(URI uri) {

View File

@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v5_0; package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v5_0;
import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
@ -36,14 +37,16 @@ abstract class AbstractApacheHttpClientTest<T extends HttpRequest>
protected Set<AttributeKey<?>> getHttpAttributes(URI uri) { protected Set<AttributeKey<?>> getHttpAttributes(URI uri) {
Set<AttributeKey<?>> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); Set<AttributeKey<?>> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
// unopened port or non routable address; or timeout if (SemconvStability.emitOldHttpSemconv()) {
// circular redirects don't report protocol information as well // unopened port or non routable address; or timeout
if ("http://localhost:61/".equals(uri.toString()) // circular redirects don't report protocol information as well
|| "https://192.0.2.1/".equals(uri.toString()) if ("http://localhost:61/".equals(uri.toString())
|| uri.toString().contains("/read-timeout") || "https://192.0.2.1/".equals(uri.toString())
|| uri.toString().contains("/circular-redirect")) { || uri.toString().contains("/read-timeout")
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); || uri.toString().contains("/circular-redirect")) {
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME);
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION);
}
} }
return attributes; return attributes;
} }

View File

@ -13,6 +13,7 @@ import com.ning.http.client.RequestBuilder;
import com.ning.http.client.Response; import com.ning.http.client.Response;
import com.ning.http.client.uri.Uri; import com.ning.http.client.uri.Uri;
import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
@ -88,13 +89,15 @@ class AsyncHttpClientTest extends AbstractHttpClientTest<Request> {
if (!Boolean.getBoolean("testLatestDeps")) { if (!Boolean.getBoolean("testLatestDeps")) {
optionsBuilder.disableTestReadTimeout(); optionsBuilder.disableTestReadTimeout();
} }
optionsBuilder.setHttpAttributes( if (SemconvStability.emitOldHttpSemconv()) {
endpoint -> { optionsBuilder.setHttpAttributes(
Set<AttributeKey<?>> attributes = endpoint -> {
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); Set<AttributeKey<?>> attributes =
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME);
return attributes; attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION);
}); return attributes;
});
}
} }
} }

View File

@ -5,6 +5,7 @@
package io.opentelemetry.instrumentation.awslambdaevents.v2_2.internal; package io.opentelemetry.instrumentation.awslambdaevents.v2_2.internal;
import static io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes.HTTP_RESPONSE_STATUS_CODE;
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet; import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
import static io.opentelemetry.instrumentation.api.internal.HttpConstants._OTHER; import static io.opentelemetry.instrumentation.api.internal.HttpConstants._OTHER;
import static io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.MapUtils.emptyIfNull; import static io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.MapUtils.emptyIfNull;
@ -122,7 +123,12 @@ final class ApiGatewayProxyAttributesExtractor
if (response instanceof APIGatewayProxyResponseEvent) { if (response instanceof APIGatewayProxyResponseEvent) {
Integer statusCode = ((APIGatewayProxyResponseEvent) response).getStatusCode(); Integer statusCode = ((APIGatewayProxyResponseEvent) response).getStatusCode();
if (statusCode != null) { if (statusCode != null) {
attributes.put(HTTP_STATUS_CODE, statusCode); if (SemconvStability.emitStableHttpSemconv()) {
attributes.put(HTTP_RESPONSE_STATUS_CODE, statusCode);
}
if (SemconvStability.emitOldHttpSemconv()) {
attributes.put(HTTP_STATUS_CODE, statusCode);
}
} }
} }
} }

View File

@ -182,7 +182,12 @@ class HttpSpanDecorator extends BaseSpanDecorator {
if (exchange.hasOut()) { if (exchange.hasOut()) {
Object responseCode = exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE); Object responseCode = exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE);
if (responseCode instanceof Integer) { if (responseCode instanceof Integer) {
attributes.put(SemanticAttributes.HTTP_STATUS_CODE, (Integer) responseCode); if (SemconvStability.emitStableHttpSemconv()) {
attributes.put(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, (Integer) responseCode);
}
if (SemconvStability.emitOldHttpSemconv()) {
attributes.put(SemanticAttributes.HTTP_STATUS_CODE, (Integer) responseCode);
}
} }
} }
} }

View File

@ -17,6 +17,7 @@ import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.util.ClassInfo; import com.google.api.client.util.ClassInfo;
import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
@ -122,13 +123,15 @@ public abstract class AbstractGoogleHttpClientTest extends AbstractHttpClientTes
// can only use supported method // can only use supported method
optionsBuilder.disableTestNonStandardHttpMethod(); optionsBuilder.disableTestNonStandardHttpMethod();
optionsBuilder.setHttpAttributes( if (SemconvStability.emitOldHttpSemconv()) {
uri -> { optionsBuilder.setHttpAttributes(
Set<AttributeKey<?>> attributes = uri -> {
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); Set<AttributeKey<?>> attributes =
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME);
return attributes; attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION);
}); return attributes;
});
}
} }
} }

View File

@ -6,6 +6,7 @@
package io.opentelemetry.instrumentation.httpclient; package io.opentelemetry.instrumentation.httpclient;
import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
@ -83,18 +84,20 @@ public abstract class AbstractJavaHttpClientTest extends AbstractHttpClientTest<
// which is not what the test expects // which is not what the test expects
optionsBuilder.disableTestWithClientParent(); optionsBuilder.disableTestWithClientParent();
optionsBuilder.setHttpAttributes( if (SemconvStability.emitOldHttpSemconv()) {
uri -> { optionsBuilder.setHttpAttributes(
Set<AttributeKey<?>> attributes = uri -> {
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); Set<AttributeKey<?>> attributes =
// unopened port or non routable address; or timeout new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
if ("http://localhost:61/".equals(uri.toString()) // unopened port or non routable address; or timeout
|| "https://192.0.2.1/".equals(uri.toString()) if ("http://localhost:61/".equals(uri.toString())
|| uri.toString().contains("/read-timeout")) { || "https://192.0.2.1/".equals(uri.toString())
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); || uri.toString().contains("/read-timeout")) {
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME);
} attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION);
return attributes; }
}); return attributes;
});
}
} }
} }

View File

@ -21,6 +21,7 @@ import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTes
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
import io.opentelemetry.instrumentation.testing.junit.http.SemconvStabilityUtil;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.ConnectException; import java.net.ConnectException;
@ -174,8 +175,8 @@ class Netty38ClientTest extends AbstractHttpClientTest<Request> {
} }
Set<AttributeKey<?>> attributes = Set<AttributeKey<?>> attributes =
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
attributes.remove(SemanticAttributes.NET_PEER_NAME); attributes.remove(SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_NAME));
attributes.remove(SemanticAttributes.NET_PEER_PORT); attributes.remove(SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_PORT));
return attributes; return attributes;
}); });
} }

View File

@ -19,6 +19,7 @@ import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
import io.opentelemetry.instrumentation.testing.junit.http.SemconvStabilityUtil;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.URI; import java.net.URI;
import java.util.Collections; import java.util.Collections;
@ -121,8 +122,8 @@ public abstract class AbstractNetty41ClientTest
return Collections.emptySet(); return Collections.emptySet();
} }
Set<AttributeKey<?>> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); Set<AttributeKey<?>> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
attributes.remove(SemanticAttributes.NET_PEER_NAME); attributes.remove(SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_NAME));
attributes.remove(SemanticAttributes.NET_PEER_PORT); attributes.remove(SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_PORT));
return attributes; return attributes;
} }

View File

@ -13,6 +13,7 @@ import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response; import com.squareup.okhttp.Response;
import com.squareup.okhttp.internal.http.HttpMethod; import com.squareup.okhttp.internal.http.HttpMethod;
import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
@ -100,13 +101,15 @@ public class OkHttp2Test extends AbstractHttpClientTest<Request> {
Set<AttributeKey<?>> attributes = Set<AttributeKey<?>> attributes =
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
// protocol is extracted from the response, and those URLs cause exceptions (= null if (SemconvStability.emitOldHttpSemconv()) {
// response) // protocol is extracted from the response, and those URLs cause exceptions (= null
if ("http://localhost:61/".equals(uri.toString()) // response)
|| "https://192.0.2.1/".equals(uri.toString()) if ("http://localhost:61/".equals(uri.toString())
|| resolveAddress("/read-timeout").toString().equals(uri.toString())) { || "https://192.0.2.1/".equals(uri.toString())
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); || resolveAddress("/read-timeout").toString().equals(uri.toString())) {
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME);
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION);
}
} }
return attributes; return attributes;

View File

@ -10,6 +10,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
@ -125,13 +126,15 @@ public abstract class AbstractOkHttp3Test extends AbstractHttpClientTest<Request
// verification on this attribute // verification on this attribute
attributes.remove(SemanticAttributes.USER_AGENT_ORIGINAL); attributes.remove(SemanticAttributes.USER_AGENT_ORIGINAL);
// protocol is extracted from the response, and those URLs cause exceptions (= null if (SemconvStability.emitOldHttpSemconv()) {
// response) // protocol is extracted from the response, and those URLs cause exceptions (= null
if ("http://localhost:61/".equals(uri.toString()) // response)
|| "https://192.0.2.1/".equals(uri.toString()) if ("http://localhost:61/".equals(uri.toString())
|| resolveAddress("/read-timeout").toString().equals(uri.toString())) { || "https://192.0.2.1/".equals(uri.toString())
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); || resolveAddress("/read-timeout").toString().equals(uri.toString())) {
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME);
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION);
}
} }
return attributes; return attributes;

View File

@ -8,6 +8,7 @@ package io.opentelemetry.instrumentation.spring.web.v3_1;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
@ -99,13 +100,15 @@ public class SpringWebInstrumentationTest extends AbstractHttpClientTest<HttpEnt
optionsBuilder.disableTestCircularRedirects(); optionsBuilder.disableTestCircularRedirects();
optionsBuilder.disableTestReadTimeout(); optionsBuilder.disableTestReadTimeout();
optionsBuilder.disableTestNonStandardHttpMethod(); optionsBuilder.disableTestNonStandardHttpMethod();
optionsBuilder.setHttpAttributes( if (SemconvStability.emitOldHttpSemconv()) {
uri -> { optionsBuilder.setHttpAttributes(
Set<AttributeKey<?>> attributes = uri -> {
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); Set<AttributeKey<?>> attributes =
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME);
return attributes; attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION);
}); return attributes;
});
}
} }
} }

View File

@ -8,6 +8,7 @@ package io.opentelemetry.instrumentation.spring.webflux.client;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
@ -70,14 +71,16 @@ public abstract class AbstractSpringWebfluxClientInstrumentationTest
// timeouts leak the scope // timeouts leak the scope
optionsBuilder.disableTestReadTimeout(); optionsBuilder.disableTestReadTimeout();
optionsBuilder.setHttpAttributes( if (SemconvStability.emitOldHttpSemconv()) {
uri -> { optionsBuilder.setHttpAttributes(
Set<AttributeKey<?>> attributes = uri -> {
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); Set<AttributeKey<?>> attributes =
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME); new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION); attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME);
return attributes; attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION);
}); return attributes;
});
}
optionsBuilder.setClientSpanErrorMapper( optionsBuilder.setClientSpanErrorMapper(
(uri, throwable) -> { (uri, throwable) -> {

View File

@ -22,17 +22,18 @@ import javax.annotation.Nullable;
@AutoValue @AutoValue
public abstract class HttpClientTestOptions { public abstract class HttpClientTestOptions {
public static final Set<AttributeKey<?>> DEFAULT_HTTP_ATTRIBUTES = public static final Set<AttributeKey<?>> DEFAULT_HTTP_ATTRIBUTES =
Collections.unmodifiableSet( Collections.unmodifiableSet(
new HashSet<>( new HashSet<>(
Arrays.asList( Arrays.asList(
SemanticAttributes.NET_PROTOCOL_NAME, SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PROTOCOL_NAME),
SemanticAttributes.NET_PROTOCOL_VERSION, SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PROTOCOL_VERSION),
SemanticAttributes.NET_PEER_NAME, SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_NAME),
SemanticAttributes.NET_PEER_PORT, SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_PORT),
SemanticAttributes.HTTP_URL, SemconvStabilityUtil.getAttributeKey(SemanticAttributes.HTTP_URL),
SemanticAttributes.HTTP_METHOD, SemconvStabilityUtil.getAttributeKey(SemanticAttributes.HTTP_METHOD),
SemanticAttributes.USER_AGENT_ORIGINAL))); SemconvStabilityUtil.getAttributeKey(SemanticAttributes.USER_AGENT_ORIGINAL))));
public static final BiFunction<URI, String, String> DEFAULT_EXPECTED_CLIENT_SPAN_NAME_MAPPER = public static final BiFunction<URI, String, String> DEFAULT_EXPECTED_CLIENT_SPAN_NAME_MAPPER =
(uri, method) -> HttpConstants._OTHER.equals(method) ? "TEST" : method; (uri, method) -> HttpConstants._OTHER.equals(method) ? "TEST" : method;

View File

@ -24,7 +24,9 @@ public final class HttpServerTestOptions {
public static final Set<AttributeKey<?>> DEFAULT_HTTP_ATTRIBUTES = public static final Set<AttributeKey<?>> DEFAULT_HTTP_ATTRIBUTES =
Collections.unmodifiableSet( Collections.unmodifiableSet(
new HashSet<>( new HashSet<>(
Arrays.asList(SemanticAttributes.HTTP_ROUTE, SemanticAttributes.NET_PEER_PORT))); Arrays.asList(
SemanticAttributes.HTTP_ROUTE,
SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_PORT))));
public static final SpanNameMapper DEFAULT_EXPECTED_SERVER_SPAN_NAME_MAPPER = public static final SpanNameMapper DEFAULT_EXPECTED_SERVER_SPAN_NAME_MAPPER =
(uri, method, route) -> route == null ? method : method + " " + route; (uri, method, route) -> route == null ? method : method + " " + route;

View File

@ -14,7 +14,7 @@ import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
class SemconvStabilityUtil { public class SemconvStabilityUtil {
private static final Map<AttributeKey<?>, AttributeKey<?>> oldToNewMap = new HashMap<>(); private static final Map<AttributeKey<?>, AttributeKey<?>> oldToNewMap = new HashMap<>();
static { static {
@ -64,7 +64,7 @@ class SemconvStabilityUtil {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> AttributeKey<T> getAttributeKey(AttributeKey<T> oldKey) { public static <T> AttributeKey<T> getAttributeKey(AttributeKey<T> oldKey) {
if (SemconvStability.emitStableHttpSemconv()) { if (SemconvStability.emitStableHttpSemconv()) {
return (AttributeKey<T>) oldToNewMap.getOrDefault(oldKey, oldKey); return (AttributeKey<T>) oldToNewMap.get(oldKey);
} }
return oldKey; return oldKey;
} }