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.AttributesBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.HashSet;
import java.util.Set;
@ -46,9 +47,11 @@ final class MetricsView {
// 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
Set<AttributeKey> view = new HashSet<>(alwaysInclude);
view.add(SemanticAttributes.NET_PEER_NAME);
view.add(SemanticAttributes.NET_PEER_PORT);
view.add(SemanticAttributes.NET_TRANSPORT);
if (SemconvStability.emitOldHttpSemconv()) {
view.add(SemanticAttributes.NET_PEER_NAME);
view.add(SemanticAttributes.NET_PEER_PORT);
view.add(SemanticAttributes.NET_TRANSPORT);
}
return view;
}
@ -56,8 +59,10 @@ final class MetricsView {
// 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
Set<AttributeKey> view = new HashSet<>(alwaysInclude);
view.add(SemanticAttributes.NET_HOST_NAME);
view.add(SemanticAttributes.NET_TRANSPORT);
if (SemconvStability.emitOldHttpSemconv()) {
view.add(SemanticAttributes.NET_HOST_NAME);
view.add(SemanticAttributes.NET_TRANSPORT);
}
return view;
}
@ -65,8 +70,10 @@ final class MetricsView {
// 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
Set<AttributeKey> view = new HashSet<>(alwaysInclude);
view.add(SemanticAttributes.NET_SOCK_HOST_ADDR);
view.add(SemanticAttributes.NET_TRANSPORT);
if (SemconvStability.emitOldHttpSemconv()) {
view.add(SemanticAttributes.NET_SOCK_HOST_ADDR);
view.add(SemanticAttributes.NET_TRANSPORT);
}
return view;
}
@ -81,7 +88,8 @@ final class MetricsView {
static Attributes applyServerView(Attributes startAttributes, Attributes endAttributes) {
Set<AttributeKey> fullSet = serverView;
if (!containsAttribute(SemanticAttributes.NET_HOST_NAME, startAttributes, endAttributes)) {
if (SemconvStability.emitOldHttpSemconv()
&& !containsAttribute(SemanticAttributes.NET_HOST_NAME, startAttributes, endAttributes)) {
fullSet = serverFallbackView;
}
return applyView(fullSet, startAttributes, endAttributes);

View File

@ -5,19 +5,15 @@
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.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URI;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CancellationException;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
@ -226,14 +222,6 @@ class ApacheHttpAsyncClientTest {
void configureTest(HttpClientTestOptions.Builder optionsBuilder) {
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) {

View File

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

View File

@ -5,18 +5,14 @@
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.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URI;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
@ -337,14 +333,6 @@ public abstract class AbstractApacheHttpClientTest {
static void configureTest(HttpClientTestOptions.Builder optionsBuilder) {
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) {

View File

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

View File

@ -5,6 +5,7 @@
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.HttpConstants._OTHER;
import static io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.MapUtils.emptyIfNull;
@ -122,7 +123,12 @@ final class ApiGatewayProxyAttributesExtractor
if (response instanceof APIGatewayProxyResponseEvent) {
Integer statusCode = ((APIGatewayProxyResponseEvent) response).getStatusCode();
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()) {
Object responseCode = exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE);
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 io.opentelemetry.api.common.AttributeKey;
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.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
@ -122,13 +123,15 @@ public abstract class AbstractGoogleHttpClientTest extends AbstractHttpClientTes
// can only use supported method
optionsBuilder.disableTestNonStandardHttpMethod();
optionsBuilder.setHttpAttributes(
uri -> {
Set<AttributeKey<?>> attributes =
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME);
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION);
return attributes;
});
if (SemconvStability.emitOldHttpSemconv()) {
optionsBuilder.setHttpAttributes(
uri -> {
Set<AttributeKey<?>> attributes =
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME);
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION);
return attributes;
});
}
}
}

View File

@ -6,6 +6,7 @@
package io.opentelemetry.instrumentation.httpclient;
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.HttpClientResult;
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
optionsBuilder.disableTestWithClientParent();
optionsBuilder.setHttpAttributes(
uri -> {
Set<AttributeKey<?>> attributes =
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
// unopened port or non routable address; or timeout
if ("http://localhost:61/".equals(uri.toString())
|| "https://192.0.2.1/".equals(uri.toString())
|| uri.toString().contains("/read-timeout")) {
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME);
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION);
}
return attributes;
});
if (SemconvStability.emitOldHttpSemconv()) {
optionsBuilder.setHttpAttributes(
uri -> {
Set<AttributeKey<?>> attributes =
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
// unopened port or non routable address; or timeout
if ("http://localhost:61/".equals(uri.toString())
|| "https://192.0.2.1/".equals(uri.toString())
|| uri.toString().contains("/read-timeout")) {
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME);
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION);
}
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.HttpClientResult;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
import io.opentelemetry.instrumentation.testing.junit.http.SemconvStabilityUtil;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.lang.reflect.Method;
import java.net.ConnectException;
@ -174,8 +175,8 @@ class Netty38ClientTest extends AbstractHttpClientTest<Request> {
}
Set<AttributeKey<?>> attributes =
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
attributes.remove(SemanticAttributes.NET_PEER_NAME);
attributes.remove(SemanticAttributes.NET_PEER_PORT);
attributes.remove(SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_NAME));
attributes.remove(SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_PORT));
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.HttpClientResult;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
import io.opentelemetry.instrumentation.testing.junit.http.SemconvStabilityUtil;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.URI;
import java.util.Collections;
@ -121,8 +122,8 @@ public abstract class AbstractNetty41ClientTest
return Collections.emptySet();
}
Set<AttributeKey<?>> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
attributes.remove(SemanticAttributes.NET_PEER_NAME);
attributes.remove(SemanticAttributes.NET_PEER_PORT);
attributes.remove(SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_NAME));
attributes.remove(SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_PORT));
return attributes;
}

View File

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

View File

@ -8,6 +8,7 @@ package io.opentelemetry.instrumentation.spring.web.v3_1;
import static java.util.Collections.singletonList;
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.http.AbstractHttpClientTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension;
@ -99,13 +100,15 @@ public class SpringWebInstrumentationTest extends AbstractHttpClientTest<HttpEnt
optionsBuilder.disableTestCircularRedirects();
optionsBuilder.disableTestReadTimeout();
optionsBuilder.disableTestNonStandardHttpMethod();
optionsBuilder.setHttpAttributes(
uri -> {
Set<AttributeKey<?>> attributes =
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME);
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION);
return attributes;
});
if (SemconvStability.emitOldHttpSemconv()) {
optionsBuilder.setHttpAttributes(
uri -> {
Set<AttributeKey<?>> attributes =
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME);
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 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.HttpClientResult;
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
@ -70,14 +71,16 @@ public abstract class AbstractSpringWebfluxClientInstrumentationTest
// timeouts leak the scope
optionsBuilder.disableTestReadTimeout();
optionsBuilder.setHttpAttributes(
uri -> {
Set<AttributeKey<?>> attributes =
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME);
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION);
return attributes;
});
if (SemconvStability.emitOldHttpSemconv()) {
optionsBuilder.setHttpAttributes(
uri -> {
Set<AttributeKey<?>> attributes =
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME);
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION);
return attributes;
});
}
optionsBuilder.setClientSpanErrorMapper(
(uri, throwable) -> {

View File

@ -22,17 +22,18 @@ import javax.annotation.Nullable;
@AutoValue
public abstract class HttpClientTestOptions {
public static final Set<AttributeKey<?>> DEFAULT_HTTP_ATTRIBUTES =
Collections.unmodifiableSet(
new HashSet<>(
Arrays.asList(
SemanticAttributes.NET_PROTOCOL_NAME,
SemanticAttributes.NET_PROTOCOL_VERSION,
SemanticAttributes.NET_PEER_NAME,
SemanticAttributes.NET_PEER_PORT,
SemanticAttributes.HTTP_URL,
SemanticAttributes.HTTP_METHOD,
SemanticAttributes.USER_AGENT_ORIGINAL)));
SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PROTOCOL_NAME),
SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PROTOCOL_VERSION),
SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_NAME),
SemconvStabilityUtil.getAttributeKey(SemanticAttributes.NET_PEER_PORT),
SemconvStabilityUtil.getAttributeKey(SemanticAttributes.HTTP_URL),
SemconvStabilityUtil.getAttributeKey(SemanticAttributes.HTTP_METHOD),
SemconvStabilityUtil.getAttributeKey(SemanticAttributes.USER_AGENT_ORIGINAL))));
public static final BiFunction<URI, String, String> DEFAULT_EXPECTED_CLIENT_SPAN_NAME_MAPPER =
(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 =
Collections.unmodifiableSet(
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 =
(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.Map;
class SemconvStabilityUtil {
public class SemconvStabilityUtil {
private static final Map<AttributeKey<?>, AttributeKey<?>> oldToNewMap = new HashMap<>();
static {
@ -64,7 +64,7 @@ class SemconvStabilityUtil {
@SuppressWarnings("unchecked")
public static <T> AttributeKey<T> getAttributeKey(AttributeKey<T> oldKey) {
if (SemconvStability.emitStableHttpSemconv()) {
return (AttributeKey<T>) oldToNewMap.getOrDefault(oldKey, oldKey);
return (AttributeKey<T>) oldToNewMap.get(oldKey);
}
return oldKey;
}