Enable stable HTTP semconv by default (#9925)
This commit is contained in:
parent
62fcec31ab
commit
280c1ea4c1
|
|
@ -23,41 +23,6 @@ dependencies {
|
|||
testImplementation("io.opentelemetry:opentelemetry-sdk-testing")
|
||||
}
|
||||
|
||||
testing {
|
||||
suites {
|
||||
val testStableHttpSemconv by registering(JvmTestSuite::class) {
|
||||
dependencies {
|
||||
implementation(project())
|
||||
implementation(project(":testing-common"))
|
||||
implementation("io.opentelemetry:opentelemetry-sdk")
|
||||
implementation("io.opentelemetry:opentelemetry-sdk-testing")
|
||||
}
|
||||
targets {
|
||||
all {
|
||||
testTask.configure {
|
||||
jvmArgs("-Dotel.semconv-stability.opt-in=http")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val testBothHttpSemconv by registering(JvmTestSuite::class) {
|
||||
dependencies {
|
||||
implementation(project())
|
||||
implementation(project(":testing-common"))
|
||||
implementation("io.opentelemetry:opentelemetry-sdk")
|
||||
implementation("io.opentelemetry:opentelemetry-sdk-testing")
|
||||
}
|
||||
targets {
|
||||
all {
|
||||
testTask.configure {
|
||||
jvmArgs("-Dotel.semconv-stability.opt-in=http/dup")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
// exclude auto-generated code
|
||||
named<Checkstyle>("checkstyleMain") {
|
||||
|
|
@ -74,8 +39,4 @@ tasks {
|
|||
sourcesJar {
|
||||
dependsOn("generateJflex")
|
||||
}
|
||||
|
||||
check {
|
||||
dependsOn(testing.suites)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ package io.opentelemetry.instrumentation.api.instrumenter.http;
|
|||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
|
||||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
|
|
@ -18,21 +18,21 @@ import io.opentelemetry.api.common.AttributesBuilder;
|
|||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.net.ConnectException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.ToIntFunction;
|
||||
import java.util.stream.Stream;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.ArgumentsProvider;
|
||||
import org.junit.jupiter.params.provider.ArgumentsSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
class HttpClientAttributesExtractorTest {
|
||||
|
||||
static class TestHttpClientAttributesGetter
|
||||
|
|
@ -57,7 +57,8 @@ class HttpClientAttributesExtractorTest {
|
|||
@Override
|
||||
public Integer getHttpResponseStatusCode(
|
||||
Map<String, String> request, Map<String, String> response, @Nullable Throwable error) {
|
||||
return Integer.parseInt(response.get("statusCode"));
|
||||
String value = response.get("statusCode");
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -85,14 +86,29 @@ class HttpClientAttributesExtractorTest {
|
|||
@Override
|
||||
public String getNetworkProtocolName(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("protocolName");
|
||||
return request.get("networkProtocolName");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolVersion(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("protocolVersion");
|
||||
return request.get("networkProtocolVersion");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkPeerAddress(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("networkPeerAddress");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getNetworkPeerPort(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
String value = request.get("networkPeerPort");
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
@ -104,8 +120,17 @@ class HttpClientAttributesExtractorTest {
|
|||
@Nullable
|
||||
@Override
|
||||
public Integer getServerPort(Map<String, String> request) {
|
||||
String statusCode = request.get("serverPort");
|
||||
return statusCode == null ? null : Integer.parseInt(statusCode);
|
||||
String value = request.get("serverPort");
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getErrorType(
|
||||
Map<String, String> request,
|
||||
@Nullable Map<String, String> respobse,
|
||||
@Nullable Throwable error) {
|
||||
return request.get("errorType");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -117,10 +142,12 @@ class HttpClientAttributesExtractorTest {
|
|||
request.put("header.content-length", "10");
|
||||
request.put("header.user-agent", "okhttp 3.x");
|
||||
request.put("header.custom-request-header", "123,456");
|
||||
request.put("networkTransport", "tcp");
|
||||
request.put("networkTransport", "udp");
|
||||
request.put("networkType", "ipv4");
|
||||
request.put("protocolName", "http");
|
||||
request.put("protocolVersion", "1.1");
|
||||
request.put("networkProtocolName", "http");
|
||||
request.put("networkProtocolVersion", "1.1");
|
||||
request.put("networkPeerAddress", "4.3.2.1");
|
||||
request.put("networkPeerPort", "456");
|
||||
request.put("serverAddress", "github.com");
|
||||
request.put("serverPort", "80");
|
||||
|
||||
|
|
@ -142,137 +169,256 @@ class HttpClientAttributesExtractorTest {
|
|||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.HTTP_METHOD, "POST"),
|
||||
entry(SemanticAttributes.HTTP_URL, "http://github.com"),
|
||||
entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||
entry(SemanticAttributes.URL_FULL, "http://github.com"),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.request.header.custom_request_header"),
|
||||
AttributeKey.stringArrayKey("http.request.header.custom-request-header"),
|
||||
asList("123", "456")),
|
||||
entry(SemanticAttributes.NET_PEER_NAME, "github.com"),
|
||||
entry(SemanticAttributes.NET_PEER_PORT, 80L),
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "github.com"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 80L),
|
||||
entry(HttpAttributes.HTTP_REQUEST_RESEND_COUNT, 2L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L),
|
||||
entry(SemanticAttributes.HTTP_STATUS_CODE, 202L),
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 20L),
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.response.header.custom_response_header"),
|
||||
AttributeKey.stringArrayKey("http.response.header.custom-response-header"),
|
||||
asList("654", "321")),
|
||||
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"));
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "4.3.2.1"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_PORT, 456L));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ArgumentsSource(StripUrlArgumentSource.class)
|
||||
void stripBasicAuthTest(String url, String expectedResult) {
|
||||
@ArgumentsSource(ValidRequestMethodsProvider.class)
|
||||
void shouldExtractKnownMethods(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("urlFull", url);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
|
||||
assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.HTTP_URL, expectedResult));
|
||||
}
|
||||
|
||||
static final class StripUrlArgumentSource implements ArgumentsProvider {
|
||||
|
||||
@Override
|
||||
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
|
||||
return Stream.of(
|
||||
arguments("https://user1:secret@github.com", "https://REDACTED:REDACTED@github.com"),
|
||||
arguments(
|
||||
"https://user1:secret@github.com/path/",
|
||||
"https://REDACTED:REDACTED@github.com/path/"),
|
||||
arguments(
|
||||
"https://user1:secret@github.com#test.html",
|
||||
"https://REDACTED:REDACTED@github.com#test.html"),
|
||||
arguments(
|
||||
"https://user1:secret@github.com?foo=b@r",
|
||||
"https://REDACTED:REDACTED@github.com?foo=b@r"),
|
||||
arguments(
|
||||
"https://user1:secret@github.com/p@th?foo=b@r",
|
||||
"https://REDACTED:REDACTED@github.com/p@th?foo=b@r"),
|
||||
arguments("https://github.com/p@th?foo=b@r", "https://github.com/p@th?foo=b@r"),
|
||||
arguments("https://github.com#t@st.html", "https://github.com#t@st.html"),
|
||||
arguments("user1:secret@github.com", "user1:secret@github.com"),
|
||||
arguments("https://github.com@", "https://github.com@"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidStatusCode() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "0");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
assertThat(attributes.build()).isEmpty();
|
||||
|
||||
extractor.onEnd(attributes, Context.root(), request, response, null);
|
||||
assertThat(attributes.build()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void extractNetPeerNameAndPortFromHostHeader() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("header.host", "thehost:777");
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_PEER_NAME, "thehost"),
|
||||
entry(SemanticAttributes.NET_PEER_PORT, 777L));
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod)
|
||||
.doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void extractNetHostAndPortFromNetAttributesGetter() {
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"get", "Get"})
|
||||
void shouldTreatMethodsAsCaseSensitive(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("header.host", "notthehost:77777"); // this should have lower precedence
|
||||
request.put("serverAddress", "thehost");
|
||||
request.put("serverPort", "777");
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_PEER_NAME, "thehost"),
|
||||
entry(SemanticAttributes.NET_PEER_PORT, 777L));
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
void zeroResends() {
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"PURGE", "not a method really"})
|
||||
void shouldUseOtherForUnknownMethods(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
ToIntFunction<Context> resendCountFromContext = context -> 0;
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"only", "custom", "methods", "allowed"})
|
||||
void shouldExtractKnownMethods_override(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter())
|
||||
.setResendCountIncrementer(resendCountFromContext)
|
||||
.setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed")))
|
||||
.build();
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, null, null);
|
||||
assertThat(attributes.build()).isEmpty();
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod)
|
||||
.doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ArgumentsSource(ValidRequestMethodsProvider.class)
|
||||
void shouldUseOtherForUnknownMethods_override(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter())
|
||||
.setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed")))
|
||||
.build();
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractErrorType_httpStatusCode() {
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "400");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), emptyMap());
|
||||
extractor.onEnd(attributes, Context.root(), emptyMap(), response, null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 400)
|
||||
.containsEntry(HttpAttributes.ERROR_TYPE, "400");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractErrorType_getter() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("statusCode", "0");
|
||||
request.put("errorType", "custom error type");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), emptyMap());
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, "custom error type");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractErrorType_exceptionClassName() {
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), emptyMap());
|
||||
extractor.onEnd(attributes, Context.root(), emptyMap(), emptyMap(), new ConnectException());
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(HttpAttributes.ERROR_TYPE, "java.net.ConnectException");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractErrorType_other() {
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), emptyMap());
|
||||
extractor.onEnd(attributes, Context.root(), emptyMap(), emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, HttpConstants._OTHER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractServerAddressAndPortFromHostHeader() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("header.host", "github.com:123");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "github.com"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 123L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractPeerAddressEvenIfItDuplicatesServerAddress() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("networkPeerAddress", "1.2.3.4");
|
||||
request.put("networkPeerPort", "456");
|
||||
request.put("serverAddress", "1.2.3.4");
|
||||
request.put("serverPort", "123");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "1.2.3.4"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 123L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L),
|
||||
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_PORT, 456L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractProtocolNameDifferentFromHttp() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("networkProtocolName", "spdy");
|
||||
request.put("networkProtocolVersion", "3.1");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build()).isEmpty();
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "spdy"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "3.1"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import io.opentelemetry.api.trace.TraceFlags;
|
|||
import io.opentelemetry.api.trace.TraceState;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.OperationListener;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
|
||||
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
|
|
@ -24,7 +26,6 @@ import org.junit.jupiter.api.Test;
|
|||
class HttpClientExperimentalMetricsTest {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
void collectsMetrics() {
|
||||
InMemoryMetricReader metricReader = InMemoryMetricReader.create();
|
||||
SdkMeterProvider meterProvider =
|
||||
|
|
@ -35,24 +36,24 @@ class HttpClientExperimentalMetricsTest {
|
|||
|
||||
Attributes requestAttributes =
|
||||
Attributes.builder()
|
||||
.put("http.method", "GET")
|
||||
.put("http.url", "https://localhost:1234/")
|
||||
.put("http.target", "/")
|
||||
.put("http.scheme", "https")
|
||||
.put("net.peer.name", "localhost")
|
||||
.put("net.peer.port", 1234)
|
||||
.put("http.request_content_length", 100)
|
||||
.put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET")
|
||||
.put(SemanticAttributes.URL_FULL, "https://localhost:1234/")
|
||||
.put(SemanticAttributes.URL_PATH, "/")
|
||||
.put(SemanticAttributes.URL_QUERY, "q=a")
|
||||
.put(SemanticAttributes.SERVER_ADDRESS, "localhost")
|
||||
.put(SemanticAttributes.SERVER_PORT, 1234)
|
||||
.build();
|
||||
|
||||
Attributes responseAttributes =
|
||||
Attributes.builder()
|
||||
.put("http.status_code", 200)
|
||||
.put("http.response_content_length", 200)
|
||||
.put(SemanticAttributes.NET_PROTOCOL_NAME, "http")
|
||||
.put(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0")
|
||||
.put("net.sock.peer.addr", "1.2.3.4")
|
||||
.put("net.sock.peer.name", "somehost20")
|
||||
.put("net.sock.peer.port", 8080)
|
||||
.put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)
|
||||
.put(HttpAttributes.ERROR_TYPE, "400")
|
||||
.put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100)
|
||||
.put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200)
|
||||
.put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http")
|
||||
.put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0")
|
||||
.put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4")
|
||||
.put(NetworkAttributes.NETWORK_PEER_PORT, 8080)
|
||||
.build();
|
||||
|
||||
Context parent =
|
||||
|
|
@ -81,6 +82,7 @@ class HttpClientExperimentalMetricsTest {
|
|||
assertThat(metric)
|
||||
.hasName("http.client.request.size")
|
||||
.hasUnit("By")
|
||||
.hasDescription("Size of HTTP client request bodies.")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
|
|
@ -88,14 +90,16 @@ class HttpClientExperimentalMetricsTest {
|
|||
point
|
||||
.hasSum(100 /* bytes */)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, 1234),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4"))
|
||||
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
|
||||
equalTo(HttpAttributes.ERROR_TYPE, "400"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, 1234))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
|
|
@ -105,6 +109,7 @@ class HttpClientExperimentalMetricsTest {
|
|||
assertThat(metric)
|
||||
.hasName("http.client.response.size")
|
||||
.hasUnit("By")
|
||||
.hasDescription("Size of HTTP client response bodies.")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
|
|
@ -112,14 +117,16 @@ class HttpClientExperimentalMetricsTest {
|
|||
point
|
||||
.hasSum(200 /* bytes */)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, 1234),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4"))
|
||||
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
|
||||
equalTo(HttpAttributes.ERROR_TYPE, "400"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, 1234))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@ import io.opentelemetry.api.trace.TraceFlags;
|
|||
import io.opentelemetry.api.trace.TraceState;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.OperationListener;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
|
||||
import io.opentelemetry.sdk.metrics.internal.aggregator.ExplicitBucketHistogramUtils;
|
||||
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -24,13 +25,10 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
class HttpClientMetricsTest {
|
||||
|
||||
static final double[] DEFAULT_BUCKETS =
|
||||
ExplicitBucketHistogramUtils.DEFAULT_HISTOGRAM_BUCKET_BOUNDARIES.stream()
|
||||
.mapToDouble(d -> d)
|
||||
.toArray();
|
||||
static final double[] DURATION_BUCKETS =
|
||||
HttpMetricsUtil.DURATION_SECONDS_BUCKETS.stream().mapToDouble(d -> d).toArray();
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
void collectsMetrics() {
|
||||
InMemoryMetricReader metricReader = InMemoryMetricReader.create();
|
||||
SdkMeterProvider meterProvider =
|
||||
|
|
@ -40,24 +38,24 @@ class HttpClientMetricsTest {
|
|||
|
||||
Attributes requestAttributes =
|
||||
Attributes.builder()
|
||||
.put("http.method", "GET")
|
||||
.put("http.url", "https://localhost:1234/")
|
||||
.put("http.target", "/")
|
||||
.put("http.scheme", "https")
|
||||
.put("net.peer.name", "localhost")
|
||||
.put("net.peer.port", 1234)
|
||||
.put("http.request_content_length", 100)
|
||||
.put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET")
|
||||
.put(SemanticAttributes.URL_FULL, "https://localhost:1234/")
|
||||
.put(SemanticAttributes.URL_PATH, "/")
|
||||
.put(SemanticAttributes.URL_QUERY, "q=a")
|
||||
.put(SemanticAttributes.SERVER_ADDRESS, "localhost")
|
||||
.put(SemanticAttributes.SERVER_PORT, 1234)
|
||||
.build();
|
||||
|
||||
Attributes responseAttributes =
|
||||
Attributes.builder()
|
||||
.put("http.status_code", 200)
|
||||
.put("http.response_content_length", 200)
|
||||
.put(SemanticAttributes.NET_PROTOCOL_NAME, "http")
|
||||
.put(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0")
|
||||
.put("net.sock.peer.addr", "1.2.3.4")
|
||||
.put("net.sock.peer.name", "somehost20")
|
||||
.put("net.sock.peer.port", 8080)
|
||||
.put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)
|
||||
.put(HttpAttributes.ERROR_TYPE, "400")
|
||||
.put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100)
|
||||
.put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200)
|
||||
.put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http")
|
||||
.put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0")
|
||||
.put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4")
|
||||
.put(NetworkAttributes.NETWORK_PEER_PORT, 8080)
|
||||
.build();
|
||||
|
||||
Context parent =
|
||||
|
|
@ -84,29 +82,32 @@ class HttpClientMetricsTest {
|
|||
.satisfiesExactlyInAnyOrder(
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.client.duration")
|
||||
.hasUnit("ms")
|
||||
.hasName("http.client.request.duration")
|
||||
.hasUnit("s")
|
||||
.hasDescription("Duration of HTTP client requests.")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasSum(150 /* millis */)
|
||||
.hasSum(0.15 /* seconds */)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, 1234),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4"))
|
||||
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
|
||||
equalTo(HttpAttributes.ERROR_TYPE, "400"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, 1234))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
|
||||
.hasSpanId("090a0b0c0d0e0f00"))
|
||||
.hasBucketBoundaries(DEFAULT_BUCKETS))));
|
||||
.hasBucketBoundaries(DURATION_BUCKETS))));
|
||||
|
||||
listener.onEnd(context2, responseAttributes, nanos(300));
|
||||
|
||||
|
|
@ -114,11 +115,11 @@ class HttpClientMetricsTest {
|
|||
.satisfiesExactlyInAnyOrder(
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.client.duration")
|
||||
.hasName("http.client.request.duration")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
point -> point.hasSum(300 /* millis */))));
|
||||
point -> point.hasSum(0.3 /* seconds */))));
|
||||
}
|
||||
|
||||
private static long nanos(int millis) {
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ import static java.util.Collections.singletonMap;
|
|||
import static org.assertj.core.api.Assertions.entry;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
|
|
@ -76,7 +74,6 @@ class HttpClientPeerServiceAttributesExtractorTest {
|
|||
assertTrue(endAttributes.build().isEmpty());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // old semconv
|
||||
@Test
|
||||
void shouldSetPeerNameIfItMatches() {
|
||||
// given
|
||||
|
|
@ -100,37 +97,6 @@ class HttpClientPeerServiceAttributesExtractorTest {
|
|||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
underTest.onEnd(endAttributes, context, "request", "response", null);
|
||||
|
||||
// then
|
||||
assertThat(startAttributes.build()).isEmpty();
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.PEER_SERVICE, "myService"));
|
||||
verify(httpAttributesExtractor, never()).getServerSocketDomain(any(), any());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // old semconv
|
||||
@Test
|
||||
void shouldSetSockPeerNameIfItMatchesAndNoPeerNameProvided() {
|
||||
// given
|
||||
Map<String, String> peerServiceMapping = new HashMap<>();
|
||||
peerServiceMapping.put("example.com", "myService");
|
||||
peerServiceMapping.put("1.2.3.4", "someOtherService");
|
||||
|
||||
PeerServiceResolver peerServiceResolver = PeerServiceResolver.create(peerServiceMapping);
|
||||
|
||||
HttpClientPeerServiceAttributesExtractor<String, String> underTest =
|
||||
new HttpClientPeerServiceAttributesExtractor<>(
|
||||
httpAttributesExtractor, peerServiceResolver);
|
||||
|
||||
when(httpAttributesExtractor.getServerSocketDomain(any(), any())).thenReturn("example.com");
|
||||
|
||||
Context context = Context.root();
|
||||
|
||||
// when
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
underTest.onStart(startAttributes, context, "request");
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
underTest.onEnd(endAttributes, context, "request", "response", null);
|
||||
|
||||
// then
|
||||
assertThat(startAttributes.build()).isEmpty();
|
||||
assertThat(endAttributes.build())
|
||||
|
|
|
|||
|
|
@ -8,138 +8,182 @@ package io.opentelemetry.instrumentation.api.instrumenter.http;
|
|||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
|
||||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.net.ConnectException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.ArgumentsProvider;
|
||||
import org.junit.jupiter.params.provider.ArgumentsSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
class HttpServerAttributesExtractorTest {
|
||||
|
||||
static class TestHttpServerAttributesGetter
|
||||
implements HttpServerAttributesGetter<Map<String, Object>, Map<String, Object>> {
|
||||
implements HttpServerAttributesGetter<Map<String, String>, Map<String, String>> {
|
||||
|
||||
@Override
|
||||
public String getHttpRequestMethod(Map<String, Object> request) {
|
||||
return (String) request.get("method");
|
||||
public String getHttpRequestMethod(Map<String, String> request) {
|
||||
return request.get("method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrlScheme(Map<String, Object> request) {
|
||||
return (String) request.get("urlScheme");
|
||||
public String getUrlScheme(Map<String, String> request) {
|
||||
return request.get("urlScheme");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUrlPath(Map<String, Object> request) {
|
||||
return (String) request.get("urlPath");
|
||||
public String getUrlPath(Map<String, String> request) {
|
||||
return request.get("urlPath");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUrlQuery(Map<String, Object> request) {
|
||||
return (String) request.get("urlQuery");
|
||||
public String getUrlQuery(Map<String, String> request) {
|
||||
return request.get("urlQuery");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHttpRoute(Map<String, Object> request) {
|
||||
return (String) request.get("route");
|
||||
public String getHttpRoute(Map<String, String> request) {
|
||||
return request.get("route");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getHttpRequestHeader(Map<String, Object> request, String name) {
|
||||
String values = (String) request.get("header." + name);
|
||||
public List<String> getHttpRequestHeader(Map<String, String> request, String name) {
|
||||
String values = request.get("header." + name);
|
||||
return values == null ? emptyList() : asList(values.split(","));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getHttpResponseStatusCode(
|
||||
Map<String, Object> request, Map<String, Object> response, @Nullable Throwable error) {
|
||||
String value = (String) response.get("statusCode");
|
||||
Map<String, String> request, Map<String, String> response, @Nullable Throwable error) {
|
||||
String value = response.get("statusCode");
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getHttpResponseHeader(
|
||||
Map<String, Object> request, Map<String, Object> response, String name) {
|
||||
String values = (String) response.get("header." + name);
|
||||
Map<String, String> request, Map<String, String> response, String name) {
|
||||
String values = response.get("header." + name);
|
||||
return values == null ? emptyList() : asList(values.split(","));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkTransport(
|
||||
Map<String, Object> request, @Nullable Map<String, Object> response) {
|
||||
return (String) request.get("networkTransport");
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("networkTransport");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkType(
|
||||
Map<String, Object> request, @Nullable Map<String, Object> response) {
|
||||
return (String) request.get("networkType");
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("networkType");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolName(
|
||||
Map<String, Object> request, Map<String, Object> response) {
|
||||
return (String) request.get("protocolName");
|
||||
Map<String, String> request, Map<String, String> response) {
|
||||
return request.get("networkProtocolName");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolVersion(
|
||||
Map<String, Object> request, Map<String, Object> response) {
|
||||
return (String) request.get("protocolVersion");
|
||||
Map<String, String> request, Map<String, String> response) {
|
||||
return request.get("networkProtocolVersion");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkLocalAddress(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("networkLocalAddress");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getNetworkLocalPort(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
String value = request.get("networkLocalPort");
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkPeerAddress(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("networkPeerAddress");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getNetworkPeerPort(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
String value = request.get("networkPeerPort");
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getErrorType(
|
||||
Map<String, String> request,
|
||||
@Nullable Map<String, String> respobse,
|
||||
@Nullable Throwable error) {
|
||||
return request.get("errorType");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void normal() {
|
||||
Map<String, Object> request = new HashMap<>();
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", "POST");
|
||||
request.put("urlFull", "http://github.com");
|
||||
request.put("urlFull", "https://github.com");
|
||||
request.put("urlPath", "/repositories/1");
|
||||
request.put("urlQuery", "details=true");
|
||||
request.put("urlScheme", "http");
|
||||
request.put("urlScheme", "https");
|
||||
request.put("header.content-length", "10");
|
||||
request.put("route", "/repositories/{id}");
|
||||
request.put("header.user-agent", "okhttp 3.x");
|
||||
request.put("header.host", "github.com:80");
|
||||
request.put("header.host", "github.com:443");
|
||||
request.put("header.forwarded", "for=1.1.1.1;proto=https");
|
||||
request.put("header.custom-request-header", "123,456");
|
||||
request.put("networkTransport", "tcp");
|
||||
request.put("networkTransport", "udp");
|
||||
request.put("networkType", "ipv4");
|
||||
request.put("protocolName", "http");
|
||||
request.put("protocolVersion", "2.0");
|
||||
request.put("networkProtocolName", "http");
|
||||
request.put("networkProtocolVersion", "2.0");
|
||||
request.put("networkLocalAddress", "1.2.3.4");
|
||||
request.put("networkLocalPort", "42");
|
||||
request.put("networkPeerAddress", "4.3.2.1");
|
||||
request.put("networkPeerPort", "456");
|
||||
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "202");
|
||||
response.put("header.content-length", "20");
|
||||
response.put("header.custom-response-header", "654,321");
|
||||
|
||||
Function<Context, String> routeFromContext = ctx -> "/repositories/{repoId}";
|
||||
|
||||
AttributesExtractor<Map<String, Object>, Map<String, Object>> extractor =
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter())
|
||||
.setCapturedRequestHeaders(singletonList("Custom-Request-Header"))
|
||||
.setCapturedResponseHeaders(singletonList("Custom-Response-Header"))
|
||||
|
|
@ -150,122 +194,362 @@ class HttpServerAttributesExtractorTest {
|
|||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_HOST_NAME, "github.com"),
|
||||
entry(SemanticAttributes.NET_HOST_PORT, 80L),
|
||||
entry(SemanticAttributes.HTTP_METHOD, "POST"),
|
||||
entry(SemanticAttributes.HTTP_SCHEME, "https"),
|
||||
entry(SemanticAttributes.HTTP_TARGET, "/repositories/1?details=true"),
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "github.com"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 443L),
|
||||
entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||
entry(SemanticAttributes.URL_SCHEME, "https"),
|
||||
entry(SemanticAttributes.URL_PATH, "/repositories/1"),
|
||||
entry(SemanticAttributes.URL_QUERY, "details=true"),
|
||||
entry(SemanticAttributes.USER_AGENT_ORIGINAL, "okhttp 3.x"),
|
||||
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{id}"),
|
||||
entry(SemanticAttributes.HTTP_CLIENT_IP, "1.1.1.1"),
|
||||
entry(SemanticAttributes.CLIENT_ADDRESS, "1.1.1.1"),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.request.header.custom_request_header"),
|
||||
AttributeKey.stringArrayKey("http.request.header.custom-request-header"),
|
||||
asList("123", "456")));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "4.3.2.1"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_PORT, 456L),
|
||||
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"),
|
||||
entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L),
|
||||
entry(SemanticAttributes.HTTP_STATUS_CODE, 202L),
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 20L),
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.response.header.custom_response_header"),
|
||||
AttributeKey.stringArrayKey("http.response.header.custom-response-header"),
|
||||
asList("654", "321")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void extractClientIpFromX_Forwarded_For() {
|
||||
Map<String, Object> request = new HashMap<>();
|
||||
request.put("header.x-forwarded-for", "1.1.1.1");
|
||||
|
||||
AttributesExtractor<Map<String, Object>, Map<String, Object>> extractor =
|
||||
HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter())
|
||||
.setCapturedRequestHeaders(emptyList())
|
||||
.setCapturedResponseHeaders(emptyList())
|
||||
.build();
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
assertThat(attributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.HTTP_CLIENT_IP, "1.1.1.1"));
|
||||
|
||||
extractor.onEnd(attributes, Context.root(), request, null, null);
|
||||
assertThat(attributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.HTTP_CLIENT_IP, "1.1.1.1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void extractClientIpFromX_Forwarded_Proto() {
|
||||
Map<String, Object> request = new HashMap<>();
|
||||
request.put("header.x-forwarded-proto", "https");
|
||||
|
||||
AttributesExtractor<Map<String, Object>, Map<String, Object>> extractor =
|
||||
HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter())
|
||||
.setCapturedRequestHeaders(emptyList())
|
||||
.setCapturedResponseHeaders(emptyList())
|
||||
.build();
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.HTTP_SCHEME, "https"));
|
||||
|
||||
extractor.onEnd(attributes, Context.root(), request, null, null);
|
||||
assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.HTTP_SCHEME, "https"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void extractNetHostAndPortFromHostHeader() {
|
||||
Map<String, Object> request = new HashMap<>();
|
||||
request.put("header.host", "thehost:777");
|
||||
|
||||
AttributesExtractor<Map<String, Object>, Map<String, Object>> extractor =
|
||||
HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter())
|
||||
.setCapturedRequestHeaders(emptyList())
|
||||
.setCapturedResponseHeaders(emptyList())
|
||||
.build();
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
assertThat(attributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_HOST_NAME, "thehost"),
|
||||
entry(SemanticAttributes.NET_HOST_PORT, 777L));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ArgumentsSource(PathAndQueryArgumentSource.class)
|
||||
void computeTargetFromPathAndQuery(String path, String query, String expectedTarget) {
|
||||
Map<String, Object> request = new HashMap<>();
|
||||
request.put("urlPath", path);
|
||||
request.put("urlQuery", query);
|
||||
@ArgumentsSource(ValidRequestMethodsProvider.class)
|
||||
void shouldExtractKnownMethods(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, Object>, Map<String, Object>> extractor =
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
if (expectedTarget == null) {
|
||||
assertThat(attributes.build()).doesNotContainKey(SemanticAttributes.HTTP_TARGET);
|
||||
} else {
|
||||
assertThat(attributes.build()).containsEntry(SemanticAttributes.HTTP_TARGET, expectedTarget);
|
||||
}
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod)
|
||||
.doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL);
|
||||
}
|
||||
|
||||
static class PathAndQueryArgumentSource implements ArgumentsProvider {
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"get", "Get"})
|
||||
void shouldTreatMethodsAsCaseSensitive(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
@Override
|
||||
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
|
||||
return Stream.of(
|
||||
arguments(null, null, null),
|
||||
arguments("path", null, "path"),
|
||||
arguments("path", "", "path"),
|
||||
arguments(null, "query", "?query"),
|
||||
arguments("path", "query", "path?query"));
|
||||
}
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"PURGE", "not a method really"})
|
||||
void shouldUseOtherForUnknownMethods(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"only", "custom", "methods", "allowed"})
|
||||
void shouldExtractKnownMethods_override(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter())
|
||||
.setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed")))
|
||||
.build();
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod)
|
||||
.doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ArgumentsSource(ValidRequestMethodsProvider.class)
|
||||
void shouldUseOtherForUnknownMethods_override(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter())
|
||||
.setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed")))
|
||||
.build();
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractErrorType_httpStatusCode() {
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "500");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), emptyMap());
|
||||
extractor.onEnd(attributes, Context.root(), emptyMap(), response, null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 500)
|
||||
.containsEntry(HttpAttributes.ERROR_TYPE, "500");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractErrorType_getter() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("statusCode", "0");
|
||||
request.put("errorType", "custom error type");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), emptyMap());
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, "custom error type");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractErrorType_exceptionClassName() {
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), emptyMap());
|
||||
extractor.onEnd(attributes, Context.root(), emptyMap(), emptyMap(), new ConnectException());
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(HttpAttributes.ERROR_TYPE, "java.net.ConnectException");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractErrorType_other() {
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), emptyMap());
|
||||
extractor.onEnd(attributes, Context.root(), emptyMap(), emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, HttpConstants._OTHER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPreferUrlSchemeFromForwardedHeader() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("urlScheme", "http");
|
||||
request.put("header.forwarded", "proto=https");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "202");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build()).containsOnly(entry(SemanticAttributes.URL_SCHEME, "https"));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractServerAddressAndPortFromForwardedHeader() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("header.forwarded", "host=example.com:42");
|
||||
request.put("header.x-forwarded-host", "opentelemetry.io:987");
|
||||
request.put("header.host", "github.com:123");
|
||||
request.put("header.:authority", "opentelemetry.io:456");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "example.com"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 42L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractServerAddressAndPortFromForwardedHostHeader() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("header.x-forwarded-host", "opentelemetry.io:987");
|
||||
request.put("header.host", "github.com:123");
|
||||
request.put("header.:authority", "opentelemetry.io:42");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 987L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractServerAddressAndPortFromAuthorityPseudoHeader() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("header.:authority", "opentelemetry.io:42");
|
||||
request.put("header.host", "github.com:123");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 42L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractServerAddressAndPortFromHostHeader() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("header.host", "github.com:123");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "github.com"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 123L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractPeerAddressEvenIfItDuplicatesClientAddress() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("networkPeerAddress", "1.2.3.4");
|
||||
request.put("networkPeerPort", "456");
|
||||
request.put("header.forwarded", "for=1.2.3.4:123");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.CLIENT_ADDRESS, "1.2.3.4"));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L),
|
||||
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_PORT, 456L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractProtocolNameDifferentFromHttp() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("networkProtocolName", "spdy");
|
||||
request.put("networkProtocolVersion", "3.1");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build()).isEmpty();
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "spdy"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "3.1"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.instrumentation.api.instrumenter.http;
|
|||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
|
|
@ -16,6 +15,8 @@ import io.opentelemetry.api.trace.TraceFlags;
|
|||
import io.opentelemetry.api.trace.TraceState;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.OperationListener;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
|
||||
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
|
|
@ -25,7 +26,6 @@ import org.junit.jupiter.api.Test;
|
|||
class HttpServerExperimentalMetricsTest {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
void collectsMetrics() {
|
||||
InMemoryMetricReader metricReader = InMemoryMetricReader.create();
|
||||
SdkMeterProvider meterProvider =
|
||||
|
|
@ -36,26 +36,28 @@ class HttpServerExperimentalMetricsTest {
|
|||
|
||||
Attributes requestAttributes =
|
||||
Attributes.builder()
|
||||
.put("http.method", "GET")
|
||||
.put("http.target", "/")
|
||||
.put("http.scheme", "https")
|
||||
.put("net.transport", IP_TCP)
|
||||
.put(SemanticAttributes.NET_PROTOCOL_NAME, "http")
|
||||
.put(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0")
|
||||
.put("net.host.name", "localhost")
|
||||
.put("net.host.port", 1234)
|
||||
.put("net.sock.family", "inet")
|
||||
.put("net.sock.peer.addr", "1.2.3.4")
|
||||
.put("net.sock.peer.port", 8080)
|
||||
.put("net.sock.host.addr", "4.3.2.1")
|
||||
.put("net.sock.host.port", 9090)
|
||||
.put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET")
|
||||
.put(SemanticAttributes.URL_SCHEME, "https")
|
||||
.put(SemanticAttributes.URL_PATH, "/")
|
||||
.put(SemanticAttributes.URL_QUERY, "q=a")
|
||||
.put(SemanticAttributes.NETWORK_TRANSPORT, "tcp")
|
||||
.put(SemanticAttributes.NETWORK_TYPE, "ipv4")
|
||||
.put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http")
|
||||
.put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0")
|
||||
.put(SemanticAttributes.SERVER_ADDRESS, "localhost")
|
||||
.put(SemanticAttributes.SERVER_PORT, 1234)
|
||||
.build();
|
||||
|
||||
Attributes responseAttributes =
|
||||
Attributes.builder()
|
||||
.put("http.status_code", 200)
|
||||
.put("http.request_content_length", 100)
|
||||
.put("http.response_content_length", 200)
|
||||
.put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)
|
||||
.put(HttpAttributes.ERROR_TYPE, "500")
|
||||
.put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100)
|
||||
.put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200)
|
||||
.put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4")
|
||||
.put(NetworkAttributes.NETWORK_PEER_PORT, 8080)
|
||||
.put(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4.3.2.1")
|
||||
.put(NetworkAttributes.NETWORK_LOCAL_PORT, 9090)
|
||||
.build();
|
||||
|
||||
SpanContext spanContext1 =
|
||||
|
|
@ -80,6 +82,7 @@ class HttpServerExperimentalMetricsTest {
|
|||
assertThat(metric)
|
||||
.hasName("http.server.active_requests")
|
||||
.hasUnit("{requests}")
|
||||
.hasDescription("Number of active HTTP server requests.")
|
||||
.hasLongSumSatisfying(
|
||||
sum ->
|
||||
sum.hasPointsSatisfying(
|
||||
|
|
@ -87,10 +90,8 @@ class HttpServerExperimentalMetricsTest {
|
|||
point
|
||||
.hasValue(1)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, 1234L))
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.URL_SCHEME, "https"))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
|
|
@ -112,10 +113,8 @@ class HttpServerExperimentalMetricsTest {
|
|||
point
|
||||
.hasValue(2)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, 1234L))
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.URL_SCHEME, "https"))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
|
|
@ -136,10 +135,8 @@ class HttpServerExperimentalMetricsTest {
|
|||
point
|
||||
.hasValue(1)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, 1234L))
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.URL_SCHEME, "https"))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
|
|
@ -149,6 +146,7 @@ class HttpServerExperimentalMetricsTest {
|
|||
assertThat(metric)
|
||||
.hasName("http.server.request.size")
|
||||
.hasUnit("By")
|
||||
.hasDescription("Size of HTTP server request bodies.")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
|
|
@ -156,13 +154,15 @@ class HttpServerExperimentalMetricsTest {
|
|||
point
|
||||
.hasSum(100 /* bytes */)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, 1234))
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
|
||||
equalTo(HttpAttributes.ERROR_TYPE, "500"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.URL_SCHEME, "https"))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
|
|
@ -172,6 +172,7 @@ class HttpServerExperimentalMetricsTest {
|
|||
assertThat(metric)
|
||||
.hasName("http.server.response.size")
|
||||
.hasUnit("By")
|
||||
.hasDescription("Size of HTTP server response bodies.")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
|
|
@ -179,13 +180,15 @@ class HttpServerExperimentalMetricsTest {
|
|||
point
|
||||
.hasSum(200 /* bytes */)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, 1234))
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
|
||||
equalTo(HttpAttributes.ERROR_TYPE, "500"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.URL_SCHEME, "https"))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.instrumentation.api.instrumenter.http;
|
|||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
|
|
@ -16,20 +15,18 @@ import io.opentelemetry.api.trace.TraceFlags;
|
|||
import io.opentelemetry.api.trace.TraceState;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.OperationListener;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
|
||||
import io.opentelemetry.sdk.metrics.internal.aggregator.ExplicitBucketHistogramUtils;
|
||||
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
class HttpServerMetricsTest {
|
||||
|
||||
static final double[] DEFAULT_BUCKETS =
|
||||
ExplicitBucketHistogramUtils.DEFAULT_HISTOGRAM_BUCKET_BOUNDARIES.stream()
|
||||
.mapToDouble(d -> d)
|
||||
.toArray();
|
||||
static final double[] DURATION_BUCKETS =
|
||||
HttpMetricsUtil.DURATION_SECONDS_BUCKETS.stream().mapToDouble(d -> d).toArray();
|
||||
|
||||
@Test
|
||||
void collectsMetrics() {
|
||||
|
|
@ -41,26 +38,28 @@ class HttpServerMetricsTest {
|
|||
|
||||
Attributes requestAttributes =
|
||||
Attributes.builder()
|
||||
.put("http.method", "GET")
|
||||
.put("http.target", "/")
|
||||
.put("http.scheme", "https")
|
||||
.put("net.transport", IP_TCP)
|
||||
.put(SemanticAttributes.NET_PROTOCOL_NAME, "http")
|
||||
.put(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0")
|
||||
.put("net.host.name", "localhost")
|
||||
.put("net.host.port", 1234)
|
||||
.put("net.sock.family", "inet")
|
||||
.put("net.sock.peer.addr", "1.2.3.4")
|
||||
.put("net.sock.peer.port", 8080)
|
||||
.put("net.sock.host.addr", "4.3.2.1")
|
||||
.put("net.sock.host.port", 9090)
|
||||
.put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET")
|
||||
.put(SemanticAttributes.URL_SCHEME, "https")
|
||||
.put(SemanticAttributes.URL_PATH, "/")
|
||||
.put(SemanticAttributes.URL_QUERY, "q=a")
|
||||
.put(SemanticAttributes.NETWORK_TRANSPORT, "tcp")
|
||||
.put(SemanticAttributes.NETWORK_TYPE, "ipv4")
|
||||
.put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http")
|
||||
.put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0")
|
||||
.put(SemanticAttributes.SERVER_ADDRESS, "localhost")
|
||||
.put(SemanticAttributes.SERVER_PORT, 1234)
|
||||
.build();
|
||||
|
||||
Attributes responseAttributes =
|
||||
Attributes.builder()
|
||||
.put("http.status_code", 200)
|
||||
.put("http.request_content_length", 100)
|
||||
.put("http.response_content_length", 200)
|
||||
.put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)
|
||||
.put(HttpAttributes.ERROR_TYPE, "500")
|
||||
.put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100)
|
||||
.put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200)
|
||||
.put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4")
|
||||
.put(NetworkAttributes.NETWORK_PEER_PORT, 8080)
|
||||
.put(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4.3.2.1")
|
||||
.put(NetworkAttributes.NETWORK_LOCAL_PORT, 9090)
|
||||
.build();
|
||||
|
||||
SpanContext spanContext1 =
|
||||
|
|
@ -88,28 +87,31 @@ class HttpServerMetricsTest {
|
|||
.satisfiesExactlyInAnyOrder(
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.server.duration")
|
||||
.hasUnit("ms")
|
||||
.hasName("http.server.request.duration")
|
||||
.hasDescription("Duration of HTTP server requests.")
|
||||
.hasUnit("s")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasSum(150 /* millis */)
|
||||
.hasSum(0.15 /* seconds */)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, 1234))
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
|
||||
equalTo(HttpAttributes.ERROR_TYPE, "500"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.URL_SCHEME, "https"))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
.hasTraceId(spanContext1.getTraceId())
|
||||
.hasSpanId(spanContext1.getSpanId()))
|
||||
.hasBucketBoundaries(DEFAULT_BUCKETS))));
|
||||
.hasBucketBoundaries(DURATION_BUCKETS))));
|
||||
|
||||
listener.onEnd(context2, responseAttributes, nanos(300));
|
||||
|
||||
|
|
@ -117,13 +119,13 @@ class HttpServerMetricsTest {
|
|||
.satisfiesExactlyInAnyOrder(
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.server.duration")
|
||||
.hasName("http.server.request.duration")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasSum(300 /* millis */)
|
||||
.hasSum(0.3 /* seconds */)
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
|
|
@ -141,9 +143,13 @@ class HttpServerMetricsTest {
|
|||
OperationListener listener = HttpServerMetrics.get().create(meterProvider.get("test"));
|
||||
|
||||
Attributes requestAttributes =
|
||||
Attributes.builder().put("net.host.name", "host").put("http.scheme", "https").build();
|
||||
Attributes.builder()
|
||||
.put(SemanticAttributes.SERVER_ADDRESS, "host")
|
||||
.put(SemanticAttributes.URL_SCHEME, "https")
|
||||
.build();
|
||||
|
||||
Attributes responseAttributes = Attributes.builder().put("http.route", "/test/{id}").build();
|
||||
Attributes responseAttributes =
|
||||
Attributes.builder().put(SemanticAttributes.HTTP_ROUTE, "/test/{id}").build();
|
||||
|
||||
Context parentContext = Context.root();
|
||||
|
||||
|
|
@ -156,17 +162,16 @@ class HttpServerMetricsTest {
|
|||
.anySatisfy(
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.server.duration")
|
||||
.hasUnit("ms")
|
||||
.hasName("http.server.request.duration")
|
||||
.hasUnit("s")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasSum(100 /* millis */)
|
||||
.hasSum(0.100 /* seconds */)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "host"),
|
||||
equalTo(SemanticAttributes.URL_SCHEME, "https"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_ROUTE, "/test/{id}")))));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,109 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.net;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetSocketAddress;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
@SuppressWarnings("deprecation") // testing deprecated class
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class InetSocketAddressNetClientAttributesGetterTest {
|
||||
|
||||
static class TestNetClientAttributesGetter
|
||||
implements NetClientAttributesGetter<InetSocketAddress, InetSocketAddress> {
|
||||
|
||||
@Override
|
||||
public String getServerAddress(InetSocketAddress request) {
|
||||
// net.peer.name and net.peer.port are tested in NetClientAttributesExtractorTest
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getServerPort(InetSocketAddress request) {
|
||||
// net.peer.name and net.peer.port are tested in NetClientAttributesExtractorTest
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getNetworkPeerInetSocketAddress(
|
||||
InetSocketAddress request, InetSocketAddress response) {
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
private final AttributesExtractor<InetSocketAddress, InetSocketAddress> extractor =
|
||||
NetClientAttributesExtractor.create(new TestNetClientAttributesGetter());
|
||||
|
||||
@Test
|
||||
void noInetSocketAddress() {
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onEnd(attributes, Context.root(), null, null, null);
|
||||
assertThat(attributes.build()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("AddressSelection")
|
||||
void fullAddress() {
|
||||
// given
|
||||
InetSocketAddress address = new InetSocketAddress("api.github.com", 456);
|
||||
assertThat(address.getAddress().getHostAddress()).isNotNull();
|
||||
|
||||
boolean ipv4 = address.getAddress() instanceof Inet4Address;
|
||||
|
||||
Context context = Context.root();
|
||||
|
||||
// when
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, context, address);
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, context, address, address, null);
|
||||
|
||||
// then
|
||||
assertThat(startAttributes.build()).isEmpty();
|
||||
|
||||
AttributesBuilder builder = Attributes.builder();
|
||||
builder.put(SemanticAttributes.NET_SOCK_PEER_ADDR, address.getAddress().getHostAddress());
|
||||
if (!ipv4) {
|
||||
builder.put(SemanticAttributes.NET_SOCK_FAMILY, "inet6");
|
||||
}
|
||||
builder.put(SemanticAttributes.NET_SOCK_PEER_NAME, "api.github.com");
|
||||
builder.put(SemanticAttributes.NET_SOCK_PEER_PORT, 456L);
|
||||
|
||||
assertThat(endAttributes.build()).isEqualTo(builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unresolved() {
|
||||
// given
|
||||
InetSocketAddress address = InetSocketAddress.createUnresolved("api.github.com", 456);
|
||||
assertThat(address.getAddress()).isNull();
|
||||
|
||||
Context context = Context.root();
|
||||
|
||||
// when
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, context, address);
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, context, address, address, null);
|
||||
|
||||
// then
|
||||
assertThat(startAttributes.build()).isEmpty();
|
||||
assertThat(endAttributes.build()).isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,139 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.net;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetSocketAddress;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
@SuppressWarnings("deprecation") // testing deprecated class
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class InetSocketAddressNetServerAttributesGetterTest {
|
||||
|
||||
static class TestNetServerAttributesGetter
|
||||
implements NetServerAttributesGetter<Addresses, Addresses> {
|
||||
|
||||
@Override
|
||||
public String getServerAddress(Addresses request) {
|
||||
// net.host.name and net.host.port are tested in NetClientAttributesExtractorTest
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getServerPort(Addresses request) {
|
||||
// net.host.name and net.host.port are tested in NetClientAttributesExtractorTest
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getNetworkPeerInetSocketAddress(
|
||||
Addresses request, Addresses response) {
|
||||
return request.peer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getNetworkLocalInetSocketAddress(
|
||||
Addresses request, Addresses response) {
|
||||
return request.host;
|
||||
}
|
||||
}
|
||||
|
||||
private final AttributesExtractor<Addresses, Addresses> extractor =
|
||||
NetServerAttributesExtractor.create(new TestNetServerAttributesGetter());
|
||||
|
||||
@Test
|
||||
void noInetSocketAddress() {
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), new Addresses(null, null));
|
||||
assertThat(attributes.build()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("AddressSelection")
|
||||
void fullAddress() {
|
||||
// given
|
||||
Addresses request =
|
||||
new Addresses(
|
||||
new InetSocketAddress("github.com", 123), new InetSocketAddress("api.github.com", 456));
|
||||
assertThat(request.peer.getAddress().getHostAddress()).isNotNull();
|
||||
assertThat(request.host.getAddress().getHostAddress()).isNotNull();
|
||||
|
||||
Context context = Context.root();
|
||||
|
||||
// when
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, context, request);
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, context, request, request, null);
|
||||
|
||||
// then
|
||||
if (!request.isIpv4()) {
|
||||
assertThat(startAttributes.build())
|
||||
.isEqualTo(Attributes.of(SemanticAttributes.NET_SOCK_FAMILY, "inet6"));
|
||||
} else {
|
||||
assertThat(startAttributes.build()).isEmpty();
|
||||
}
|
||||
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(
|
||||
SemanticAttributes.NET_SOCK_HOST_ADDR, request.host.getAddress().getHostAddress()),
|
||||
entry(SemanticAttributes.NET_SOCK_HOST_PORT, 456L),
|
||||
entry(
|
||||
SemanticAttributes.NET_SOCK_PEER_ADDR, request.peer.getAddress().getHostAddress()),
|
||||
entry(SemanticAttributes.NET_SOCK_PEER_PORT, 123L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unresolved() {
|
||||
// given
|
||||
Addresses request =
|
||||
new Addresses(
|
||||
InetSocketAddress.createUnresolved("github.com", 123),
|
||||
InetSocketAddress.createUnresolved("api.github.com", 456));
|
||||
assertThat(request.peer.getAddress()).isNull();
|
||||
assertThat(request.host.getAddress()).isNull();
|
||||
|
||||
Context context = Context.root();
|
||||
|
||||
// when
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, context, request);
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, context, request, request, null);
|
||||
|
||||
// then
|
||||
assertThat(startAttributes.build()).isEmpty();
|
||||
assertThat(endAttributes.build()).isEmpty();
|
||||
}
|
||||
|
||||
static final class Addresses {
|
||||
|
||||
private final InetSocketAddress peer;
|
||||
private final InetSocketAddress host;
|
||||
|
||||
Addresses(InetSocketAddress peer, InetSocketAddress host) {
|
||||
this.peer = peer;
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
boolean isIpv4() {
|
||||
return peer.getAddress() instanceof Inet4Address;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,13 +7,13 @@ package io.opentelemetry.instrumentation.api.instrumenter.net;
|
|||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -117,84 +117,16 @@ class NetClientAttributesExtractorTest {
|
|||
// then
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.NET_PEER_PORT, 42L));
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 42L));
|
||||
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
||||
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"),
|
||||
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"),
|
||||
entry(SemanticAttributes.NET_SOCK_PEER_PORT, 123L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void empty() {
|
||||
// given
|
||||
Context context = Context.root();
|
||||
|
||||
// when
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, context, emptyMap());
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, context, emptyMap(), emptyMap(), null);
|
||||
|
||||
// then
|
||||
assertThat(startAttributes.build()).isEmpty();
|
||||
assertThat(endAttributes.build()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotSetNegativePortValues() {
|
||||
// given
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("peerName", "opentelemetry.io");
|
||||
map.put("peerPort", "-12");
|
||||
map.put("sockPeerAddr", "1:2:3:4::");
|
||||
map.put("sockPeerPort", "-42");
|
||||
|
||||
Context context = Context.root();
|
||||
|
||||
// when
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, context, map);
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, context, map, map, null);
|
||||
|
||||
// then
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io"));
|
||||
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotSetSockFamilyInet() {
|
||||
// given
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("peerName", "opentelemetry.io");
|
||||
map.put("sockPeerAddr", "1.2.3.4");
|
||||
map.put("sockFamily", SemanticAttributes.NetSockFamilyValues.INET);
|
||||
|
||||
Context context = Context.root();
|
||||
|
||||
// when
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, context, map);
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, context, map, map, null);
|
||||
|
||||
// then
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io"));
|
||||
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4"));
|
||||
entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"),
|
||||
entry(SemanticAttributes.NETWORK_TYPE, "ipv6"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1:2:3:4::"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_PORT, 123L));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ package io.opentelemetry.instrumentation.api.instrumenter.net;
|
|||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -131,90 +131,18 @@ class NetServerAttributesExtractorTest {
|
|||
// then
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
||||
entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.NET_HOST_PORT, 80L),
|
||||
entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"));
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 80L));
|
||||
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "4:3:2:1::"),
|
||||
entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L),
|
||||
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"),
|
||||
entry(SemanticAttributes.NET_SOCK_PEER_PORT, 42L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void empty() {
|
||||
// given
|
||||
Context context = Context.root();
|
||||
|
||||
// when
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, context, emptyMap());
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, context, emptyMap(), null, null);
|
||||
|
||||
// then
|
||||
assertThat(startAttributes.build()).isEmpty();
|
||||
assertThat(endAttributes.build()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotSetNegativePort() {
|
||||
// given
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("hostName", "opentelemetry.io");
|
||||
map.put("hostPort", "-80");
|
||||
map.put("sockPeerAddr", "1:2:3:4::");
|
||||
map.put("sockPeerPort", "-42");
|
||||
map.put("sockHostAddr", "4:3:2:1::");
|
||||
map.put("sockHostPort", "-8080");
|
||||
|
||||
Context context = Context.root();
|
||||
|
||||
// when
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, context, map);
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, context, map, null, null);
|
||||
|
||||
// then
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"));
|
||||
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "4:3:2:1::"),
|
||||
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotSetSockFamilyInet() {
|
||||
// given
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("hostName", "opentelemetry.io");
|
||||
map.put("sockPeerAddr", "1.2.3.4");
|
||||
map.put("sockFamily", SemanticAttributes.NetSockFamilyValues.INET);
|
||||
|
||||
Context context = Context.root();
|
||||
|
||||
// when
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, context, map);
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, context, map, null, null);
|
||||
|
||||
// then
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"));
|
||||
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4"));
|
||||
entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"),
|
||||
entry(SemanticAttributes.NETWORK_TYPE, "ipv6"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
entry(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4:3:2:1::"),
|
||||
entry(NetworkAttributes.NETWORK_LOCAL_PORT, 8080L),
|
||||
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1:2:3:4::"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_PORT, 42L));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.network;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
class ClientAttributesExtractorOldSemconvTest {
|
||||
|
||||
static class TestClientAttributesGetter
|
||||
implements ClientAttributesGetter<Map<String, String>, Void> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getClientAddress(Map<String, String> request) {
|
||||
return request.get("address");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getClientPort(Map<String, String> request) {
|
||||
String value = request.get("port");
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void allAttributes() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("address", "opentelemetry.io");
|
||||
request.put("port", "80");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Void> extractor =
|
||||
ClientAttributesExtractor.create(new TestClientAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.HTTP_CLIENT_IP, "opentelemetry.io"));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, null, null);
|
||||
assertThat(endAttributes.build()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void noAttributes() {
|
||||
AttributesExtractor<Map<String, String>, Void> extractor =
|
||||
ClientAttributesExtractor.create(new TestClientAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), emptyMap());
|
||||
assertThat(startAttributes.build()).isEmpty();
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), emptyMap(), null, null);
|
||||
assertThat(endAttributes.build()).isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,124 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.network;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
class NetworkAttributesExtractorOldSemconvTest {
|
||||
|
||||
static class TestNetworkAttributesGetter
|
||||
implements NetworkAttributesGetter<Map<String, String>, Void> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkTransport(Map<String, String> request, @Nullable Void response) {
|
||||
return request.get("transport");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkType(Map<String, String> request, @Nullable Void response) {
|
||||
return request.get("type");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolName(Map<String, String> request, @Nullable Void response) {
|
||||
return request.get("protocolName");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolVersion(Map<String, String> request, @Nullable Void response) {
|
||||
return request.get("protocolVersion");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkLocalAddress(Map<String, String> request, @Nullable Void response) {
|
||||
return request.get("localAddress");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getNetworkLocalPort(Map<String, String> request, @Nullable Void response) {
|
||||
String value = request.get("localPort");
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkPeerAddress(Map<String, String> request, @Nullable Void response) {
|
||||
return request.get("peerAddress");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getNetworkPeerPort(Map<String, String> request, @Nullable Void response) {
|
||||
String value = request.get("peerPort");
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void allAttributes() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("transport", "TcP");
|
||||
request.put("type", "IPv4");
|
||||
request.put("protocolName", "Http");
|
||||
request.put("protocolVersion", "1.1");
|
||||
request.put("localAddress", "1.2.3.4");
|
||||
request.put("localPort", "8080");
|
||||
request.put("peerAddress", "4.3.2.1");
|
||||
request.put("peerPort", "9090");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Void> extractor =
|
||||
NetworkAttributesExtractor.create(new TestNetworkAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build()).isEmpty();
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, null, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
// the NetworkAttributesExtractor can't emit old net.transport & net.sock.family
|
||||
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "1.2.3.4"),
|
||||
entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L),
|
||||
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "4.3.2.1"),
|
||||
entry(SemanticAttributes.NET_SOCK_PEER_PORT, 9090L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void noAttributes() {
|
||||
AttributesExtractor<Map<String, String>, Void> extractor =
|
||||
NetworkAttributesExtractor.create(new TestNetworkAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), emptyMap());
|
||||
assertThat(startAttributes.build()).isEmpty();
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), emptyMap(), null, null);
|
||||
assertThat(endAttributes.build()).isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.network;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
class ServerAttributesExtractorOldSemconvTest {
|
||||
|
||||
static class TestServerAttributesGetter
|
||||
implements ServerAttributesGetter<Map<String, String>, Void> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getServerAddress(Map<String, String> request) {
|
||||
return request.get("address");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getServerPort(Map<String, String> request) {
|
||||
String port = request.get("port");
|
||||
return port == null ? null : Integer.parseInt(port);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void allAttributes_peer() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("address", "opentelemetry.io");
|
||||
request.put("port", "80");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Void> extractor =
|
||||
ServerAttributesExtractor.create(new TestServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.NET_PEER_PORT, 80L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, null, null);
|
||||
assertThat(endAttributes.build()).isEmpty();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // need to test the old semconv too
|
||||
@Test
|
||||
void allAttributes_host() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("address", "opentelemetry.io");
|
||||
request.put("port", "80");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Void> extractor =
|
||||
ServerAttributesExtractor.createForServerSide(new TestServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.NET_HOST_PORT, 80L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, null, null);
|
||||
assertThat(endAttributes.build()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void noAttributes() {
|
||||
AttributesExtractor<Map<String, String>, Void> extractor =
|
||||
ServerAttributesExtractor.create(new TestServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), emptyMap());
|
||||
assertThat(startAttributes.build()).isEmpty();
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), emptyMap(), null, null);
|
||||
assertThat(endAttributes.build()).isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
@ -24,7 +24,6 @@ import org.junit.jupiter.api.Test;
|
|||
class RpcClientMetricsTest {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
void collectsMetrics() {
|
||||
InMemoryMetricReader metricReader = InMemoryMetricReader.createDelta();
|
||||
SdkMeterProvider meterProvider =
|
||||
|
|
@ -41,15 +40,16 @@ class RpcClientMetricsTest {
|
|||
|
||||
Attributes responseAttributes1 =
|
||||
Attributes.builder()
|
||||
.put(SemanticAttributes.NET_PEER_NAME, "example.com")
|
||||
.put(SemanticAttributes.NET_PEER_PORT, 8080)
|
||||
.put(SemanticAttributes.NET_TRANSPORT, "ip_tcp")
|
||||
.put(SemanticAttributes.SERVER_ADDRESS, "example.com")
|
||||
.put(SemanticAttributes.SERVER_PORT, 8080)
|
||||
.put(SemanticAttributes.NETWORK_TRANSPORT, "tcp")
|
||||
.put(SemanticAttributes.NETWORK_TYPE, "ipv4")
|
||||
.build();
|
||||
|
||||
Attributes responseAttributes2 =
|
||||
Attributes.builder()
|
||||
.put(SemanticAttributes.NET_PEER_PORT, 8080)
|
||||
.put(SemanticAttributes.NET_TRANSPORT, "ip_tcp")
|
||||
.put(SemanticAttributes.SERVER_PORT, 8080)
|
||||
.put(SemanticAttributes.NETWORK_TRANSPORT, "tcp")
|
||||
.build();
|
||||
|
||||
Context parent =
|
||||
|
|
@ -91,9 +91,10 @@ class RpcClientMetricsTest {
|
|||
"myservice.EchoService"),
|
||||
equalTo(SemanticAttributes.RPC_METHOD, "exampleMethod"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_NAME, "example.com"),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, 8080),
|
||||
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"))
|
||||
SemanticAttributes.SERVER_ADDRESS, "example.com"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, 8080),
|
||||
equalTo(SemanticAttributes.NETWORK_TRANSPORT, "tcp"),
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
|
|
@ -120,8 +121,9 @@ class RpcClientMetricsTest {
|
|||
SemanticAttributes.RPC_SERVICE,
|
||||
"myservice.EchoService"),
|
||||
equalTo(SemanticAttributes.RPC_METHOD, "exampleMethod"),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, 8080),
|
||||
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp")))));
|
||||
equalTo(SemanticAttributes.SERVER_PORT, 8080),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_TRANSPORT, "tcp")))));
|
||||
}
|
||||
|
||||
private static long nanos(int millis) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import io.opentelemetry.api.trace.TraceFlags;
|
|||
import io.opentelemetry.api.trace.TraceState;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.OperationListener;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
|
||||
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
|
|
@ -24,7 +25,6 @@ import org.junit.jupiter.api.Test;
|
|||
class RpcServerMetricsTest {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
void collectsMetrics() {
|
||||
InMemoryMetricReader metricReader = InMemoryMetricReader.createDelta();
|
||||
SdkMeterProvider meterProvider =
|
||||
|
|
@ -41,17 +41,18 @@ class RpcServerMetricsTest {
|
|||
|
||||
Attributes responseAttributes1 =
|
||||
Attributes.builder()
|
||||
.put(SemanticAttributes.NET_HOST_NAME, "example.com")
|
||||
.put(SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1")
|
||||
.put(SemanticAttributes.NET_HOST_PORT, 8080)
|
||||
.put(SemanticAttributes.NET_TRANSPORT, "ip_tcp")
|
||||
.put(SemanticAttributes.SERVER_ADDRESS, "example.com")
|
||||
.put(SemanticAttributes.SERVER_PORT, 8080)
|
||||
.put(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "127.0.0.1")
|
||||
.put(SemanticAttributes.NETWORK_TRANSPORT, "tcp")
|
||||
.put(SemanticAttributes.NETWORK_TYPE, "ipv4")
|
||||
.build();
|
||||
|
||||
Attributes responseAttributes2 =
|
||||
Attributes.builder()
|
||||
.put(SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1")
|
||||
.put(SemanticAttributes.NET_HOST_PORT, 8080)
|
||||
.put(SemanticAttributes.NET_TRANSPORT, "ip_tcp")
|
||||
.put(SemanticAttributes.SERVER_PORT, 8080)
|
||||
.put(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "127.0.0.1")
|
||||
.put(SemanticAttributes.NETWORK_TRANSPORT, "tcp")
|
||||
.build();
|
||||
|
||||
Context parent =
|
||||
|
|
@ -93,8 +94,9 @@ class RpcServerMetricsTest {
|
|||
"myservice.EchoService"),
|
||||
equalTo(SemanticAttributes.RPC_METHOD, "exampleMethod"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_HOST_NAME, "example.com"),
|
||||
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"))
|
||||
SemanticAttributes.SERVER_ADDRESS, "example.com"),
|
||||
equalTo(SemanticAttributes.NETWORK_TRANSPORT, "tcp"),
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
|
|
@ -122,8 +124,7 @@ class RpcServerMetricsTest {
|
|||
"myservice.EchoService"),
|
||||
equalTo(SemanticAttributes.RPC_METHOD, "exampleMethod"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1"),
|
||||
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp")))));
|
||||
SemanticAttributes.NETWORK_TRANSPORT, "tcp")))));
|
||||
}
|
||||
|
||||
private static long nanos(int millis) {
|
||||
|
|
|
|||
|
|
@ -1,172 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.http;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.ToIntFunction;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class HttpClientAttributesExtractorBothSemconvTest {
|
||||
|
||||
static class TestHttpClientAttributesGetter
|
||||
implements HttpClientAttributesGetter<Map<String, String>, Map<String, String>> {
|
||||
|
||||
@Override
|
||||
public String getUrlFull(Map<String, String> request) {
|
||||
return request.get("urlFull");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHttpRequestMethod(Map<String, String> request) {
|
||||
return request.get("method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getHttpRequestHeader(Map<String, String> request, String name) {
|
||||
String value = request.get("header." + name);
|
||||
return value == null ? emptyList() : asList(value.split(","));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getHttpResponseStatusCode(
|
||||
Map<String, String> request, Map<String, String> response, @Nullable Throwable error) {
|
||||
return Integer.parseInt(response.get("statusCode"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getHttpResponseHeader(
|
||||
Map<String, String> request, Map<String, String> response, String name) {
|
||||
String value = response.get("header." + name);
|
||||
return value == null ? emptyList() : asList(value.split(","));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkTransport(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("networkTransport");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkType(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("networkType");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolName(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("protocolName");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolVersion(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("protocolVersion");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getServerAddress(Map<String, String> request) {
|
||||
return request.get("serverAddress");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getServerPort(Map<String, String> request) {
|
||||
String statusCode = request.get("serverPort");
|
||||
return statusCode == null ? null : Integer.parseInt(statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
void normal() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", "POST");
|
||||
request.put("urlFull", "http://github.com");
|
||||
request.put("header.content-length", "10");
|
||||
request.put("header.user-agent", "okhttp 3.x");
|
||||
request.put("header.custom-request-header", "123,456");
|
||||
request.put("networkTransport", "udp");
|
||||
request.put("networkType", "ipv4");
|
||||
request.put("protocolName", "http");
|
||||
request.put("protocolVersion", "1.1");
|
||||
request.put("serverAddress", "github.com");
|
||||
request.put("serverPort", "123");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "202");
|
||||
response.put("header.content-length", "20");
|
||||
response.put("header.custom-response-header", "654,321");
|
||||
|
||||
ToIntFunction<Context> resendCountFromContext = context -> 2;
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter())
|
||||
.setCapturedRequestHeaders(singletonList("Custom-Request-Header"))
|
||||
.setCapturedResponseHeaders(singletonList("Custom-Response-Header"))
|
||||
.setResendCountIncrementer(resendCountFromContext)
|
||||
.build();
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.HTTP_METHOD, "POST"),
|
||||
entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||
entry(SemanticAttributes.HTTP_URL, "http://github.com"),
|
||||
entry(SemanticAttributes.URL_FULL, "http://github.com"),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.request.header.custom_request_header"),
|
||||
asList("123", "456")),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.request.header.custom-request-header"),
|
||||
asList("123", "456")),
|
||||
entry(SemanticAttributes.NET_PEER_NAME, "github.com"),
|
||||
entry(SemanticAttributes.NET_PEER_PORT, 123L),
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "github.com"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 123L),
|
||||
entry(HttpAttributes.HTTP_REQUEST_RESEND_COUNT, 2L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L),
|
||||
entry(SemanticAttributes.HTTP_STATUS_CODE, 202L),
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L),
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 20L),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.response.header.custom_response_header"),
|
||||
asList("654", "321")),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.response.header.custom-response-header"),
|
||||
asList("654", "321")),
|
||||
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,185 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.http;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class HttpServerAttributesExtractorBothSemconvTest {
|
||||
|
||||
static class TestHttpServerAttributesGetter
|
||||
implements HttpServerAttributesGetter<Map<String, Object>, Map<String, Object>> {
|
||||
|
||||
@Override
|
||||
public String getHttpRequestMethod(Map<String, Object> request) {
|
||||
return (String) request.get("method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrlScheme(Map<String, Object> request) {
|
||||
return (String) request.get("urlScheme");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUrlPath(Map<String, Object> request) {
|
||||
return (String) request.get("urlPath");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUrlQuery(Map<String, Object> request) {
|
||||
return (String) request.get("urlQuery");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHttpRoute(Map<String, Object> request) {
|
||||
return (String) request.get("route");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getHttpRequestHeader(Map<String, Object> request, String name) {
|
||||
String values = (String) request.get("header." + name);
|
||||
return values == null ? emptyList() : asList(values.split(","));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getHttpResponseStatusCode(
|
||||
Map<String, Object> request, Map<String, Object> response, @Nullable Throwable error) {
|
||||
String value = (String) response.get("statusCode");
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getHttpResponseHeader(
|
||||
Map<String, Object> request, Map<String, Object> response, String name) {
|
||||
String values = (String) response.get("header." + name);
|
||||
return values == null ? emptyList() : asList(values.split(","));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkTransport(
|
||||
Map<String, Object> request, @Nullable Map<String, Object> response) {
|
||||
return (String) request.get("networkTransport");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkType(
|
||||
Map<String, Object> request, @Nullable Map<String, Object> response) {
|
||||
return (String) request.get("networkType");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolName(
|
||||
Map<String, Object> request, Map<String, Object> response) {
|
||||
return (String) request.get("protocolName");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolVersion(
|
||||
Map<String, Object> request, Map<String, Object> response) {
|
||||
return (String) request.get("protocolVersion");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
void normal() {
|
||||
Map<String, Object> request = new HashMap<>();
|
||||
request.put("method", "POST");
|
||||
request.put("urlFull", "https://github.com");
|
||||
request.put("urlPath", "/repositories/1");
|
||||
request.put("urlQuery", "details=true");
|
||||
request.put("urlScheme", "https");
|
||||
request.put("header.content-length", "10");
|
||||
request.put("route", "/repositories/{id}");
|
||||
request.put("header.user-agent", "okhttp 3.x");
|
||||
request.put("header.host", "github.com");
|
||||
request.put("header.forwarded", "for=1.1.1.1;proto=https");
|
||||
request.put("header.custom-request-header", "123,456");
|
||||
request.put("networkTransport", "udp");
|
||||
request.put("networkType", "ipv4");
|
||||
request.put("protocolName", "http");
|
||||
request.put("protocolVersion", "2.0");
|
||||
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("statusCode", "202");
|
||||
response.put("header.content-length", "20");
|
||||
response.put("header.custom-response-header", "654,321");
|
||||
|
||||
Function<Context, String> routeFromContext = ctx -> "/repositories/{repoId}";
|
||||
|
||||
AttributesExtractor<Map<String, Object>, Map<String, Object>> extractor =
|
||||
HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter())
|
||||
.setCapturedRequestHeaders(singletonList("Custom-Request-Header"))
|
||||
.setCapturedResponseHeaders(singletonList("Custom-Response-Header"))
|
||||
.setHttpRouteGetter(routeFromContext)
|
||||
.build();
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_HOST_NAME, "github.com"),
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "github.com"),
|
||||
entry(SemanticAttributes.HTTP_METHOD, "POST"),
|
||||
entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||
entry(SemanticAttributes.HTTP_SCHEME, "https"),
|
||||
entry(SemanticAttributes.HTTP_TARGET, "/repositories/1?details=true"),
|
||||
entry(SemanticAttributes.URL_SCHEME, "https"),
|
||||
entry(SemanticAttributes.URL_PATH, "/repositories/1"),
|
||||
entry(SemanticAttributes.URL_QUERY, "details=true"),
|
||||
entry(SemanticAttributes.USER_AGENT_ORIGINAL, "okhttp 3.x"),
|
||||
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{id}"),
|
||||
entry(SemanticAttributes.HTTP_CLIENT_IP, "1.1.1.1"),
|
||||
entry(SemanticAttributes.CLIENT_ADDRESS, "1.1.1.1"),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.request.header.custom_request_header"),
|
||||
asList("123", "456")),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.request.header.custom-request-header"),
|
||||
asList("123", "456")));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "2.0"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"),
|
||||
entry(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, 10L),
|
||||
entry(SemanticAttributes.HTTP_STATUS_CODE, 202L),
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L),
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 20L),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.response.header.custom_response_header"),
|
||||
asList("654", "321")),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.response.header.custom-response-header"),
|
||||
asList("654", "321")));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.net;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings("deprecation") // testing deprecated class
|
||||
class NetClientAttributesExtractorBothSemconvTest {
|
||||
|
||||
static class TestNetClientAttributesGetter
|
||||
implements NetClientAttributesGetter<Map<String, String>, Map<String, String>> {
|
||||
|
||||
@Override
|
||||
public String getTransport(Map<String, String> request, Map<String, String> response) {
|
||||
return response.get("netTransport");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkTransport(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("transport");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkType(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("type");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolName(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("protocolName");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolVersion(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("protocolVersion");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerAddress(Map<String, String> request) {
|
||||
return request.get("peerName");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getServerPort(Map<String, String> request) {
|
||||
String peerPort = request.get("peerPort");
|
||||
return peerPort == null ? null : Integer.valueOf(peerPort);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSockFamily(Map<String, String> request, Map<String, String> response) {
|
||||
return response.get("sockFamily");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNetworkPeerAddress(Map<String, String> request, Map<String, String> response) {
|
||||
return response.get("sockPeerAddr");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getNetworkPeerPort(Map<String, String> request, Map<String, String> response) {
|
||||
String sockPeerPort = response.get("sockPeerPort");
|
||||
return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort);
|
||||
}
|
||||
}
|
||||
|
||||
private final AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
NetClientAttributesExtractor.create(new TestNetClientAttributesGetter());
|
||||
|
||||
@Test
|
||||
void normal() {
|
||||
// given
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("netTransport", IP_TCP);
|
||||
map.put("transport", "tcp");
|
||||
map.put("type", "ipv6");
|
||||
map.put("protocolName", "http");
|
||||
map.put("protocolVersion", "1.1");
|
||||
map.put("peerName", "opentelemetry.io");
|
||||
map.put("peerPort", "42");
|
||||
map.put("sockFamily", "inet6");
|
||||
map.put("sockPeerAddr", "1:2:3:4::");
|
||||
map.put("sockPeerName", "proxy.opentelemetry.io");
|
||||
map.put("sockPeerPort", "123");
|
||||
|
||||
Context context = Context.root();
|
||||
|
||||
// when
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, context, map);
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, context, map, map, null);
|
||||
|
||||
// then
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.NET_PEER_PORT, 42L),
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 42L));
|
||||
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
||||
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"),
|
||||
entry(SemanticAttributes.NETWORK_TYPE, "ipv6"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"),
|
||||
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"),
|
||||
entry(SemanticAttributes.NET_SOCK_PEER_PORT, 123L),
|
||||
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1:2:3:4::"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_PORT, 123L));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,158 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.net;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings("deprecation") // testing deprecated class
|
||||
class NetServerAttributesExtractorBothSemconvTest {
|
||||
|
||||
static class TestNetServerAttributesGetter
|
||||
implements NetServerAttributesGetter<Map<String, String>, Void> {
|
||||
|
||||
@Override
|
||||
public String getTransport(Map<String, String> request) {
|
||||
return request.get("netTransport");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkTransport(Map<String, String> request, @Nullable Void response) {
|
||||
return request.get("transport");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkType(Map<String, String> request, @Nullable Void response) {
|
||||
return request.get("type");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolName(Map<String, String> request, Void response) {
|
||||
return request.get("protocolName");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolVersion(Map<String, String> request, Void response) {
|
||||
return request.get("protocolVersion");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getServerAddress(Map<String, String> request) {
|
||||
return request.get("hostName");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getServerPort(Map<String, String> request) {
|
||||
String hostPort = request.get("hostPort");
|
||||
return hostPort == null ? null : Integer.valueOf(hostPort);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getSockFamily(Map<String, String> request) {
|
||||
return request.get("sockFamily");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNetworkPeerAddress(Map<String, String> request, Void response) {
|
||||
return request.get("sockPeerAddr");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getNetworkPeerPort(Map<String, String> request, Void response) {
|
||||
String sockPeerPort = request.get("sockPeerPort");
|
||||
return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkLocalAddress(Map<String, String> request, Void response) {
|
||||
return request.get("sockHostAddr");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getNetworkLocalPort(Map<String, String> request, Void response) {
|
||||
String sockHostPort = request.get("sockHostPort");
|
||||
return sockHostPort == null ? null : Integer.valueOf(sockHostPort);
|
||||
}
|
||||
}
|
||||
|
||||
AttributesExtractor<Map<String, String>, Void> extractor =
|
||||
NetServerAttributesExtractor.create(new TestNetServerAttributesGetter());
|
||||
|
||||
@Test
|
||||
void normal() {
|
||||
// given
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("netTransport", IP_TCP);
|
||||
map.put("transport", "tcp");
|
||||
map.put("type", "ipv6");
|
||||
map.put("protocolName", "http");
|
||||
map.put("protocolVersion", "1.1");
|
||||
map.put("hostName", "opentelemetry.io");
|
||||
map.put("hostPort", "80");
|
||||
map.put("sockFamily", "inet6");
|
||||
map.put("sockPeerAddr", "1:2:3:4::");
|
||||
map.put("sockPeerPort", "42");
|
||||
map.put("sockHostAddr", "4:3:2:1::");
|
||||
map.put("sockHostPort", "8080");
|
||||
|
||||
Context context = Context.root();
|
||||
|
||||
// when
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, context, map);
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, context, map, null, null);
|
||||
|
||||
// then
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_TRANSPORT, IP_TCP),
|
||||
entry(SemanticAttributes.NET_HOST_NAME, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.NET_HOST_PORT, 80L),
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 80L),
|
||||
entry(SemanticAttributes.NET_SOCK_FAMILY, "inet6"));
|
||||
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "4:3:2:1::"),
|
||||
entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L),
|
||||
entry(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4:3:2:1::"),
|
||||
entry(NetworkAttributes.NETWORK_LOCAL_PORT, 8080L),
|
||||
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1:2:3:4::"),
|
||||
entry(SemanticAttributes.NET_SOCK_PEER_PORT, 42L),
|
||||
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1:2:3:4::"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_PORT, 42L),
|
||||
entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"),
|
||||
entry(SemanticAttributes.NETWORK_TYPE, "ipv6"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
entry(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,424 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.http;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.net.ConnectException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.ToIntFunction;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ArgumentsSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
class HttpClientAttributesExtractorStableSemconvTest {
|
||||
|
||||
static class TestHttpClientAttributesGetter
|
||||
implements HttpClientAttributesGetter<Map<String, String>, Map<String, String>> {
|
||||
|
||||
@Override
|
||||
public String getUrlFull(Map<String, String> request) {
|
||||
return request.get("urlFull");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHttpRequestMethod(Map<String, String> request) {
|
||||
return request.get("method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getHttpRequestHeader(Map<String, String> request, String name) {
|
||||
String value = request.get("header." + name);
|
||||
return value == null ? emptyList() : asList(value.split(","));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getHttpResponseStatusCode(
|
||||
Map<String, String> request, Map<String, String> response, @Nullable Throwable error) {
|
||||
String value = response.get("statusCode");
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getHttpResponseHeader(
|
||||
Map<String, String> request, Map<String, String> response, String name) {
|
||||
String value = response.get("header." + name);
|
||||
return value == null ? emptyList() : asList(value.split(","));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkTransport(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("networkTransport");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkType(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("networkType");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolName(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("networkProtocolName");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolVersion(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("networkProtocolVersion");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkPeerAddress(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("networkPeerAddress");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getNetworkPeerPort(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
String value = request.get("networkPeerPort");
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getServerAddress(Map<String, String> request) {
|
||||
return request.get("serverAddress");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getServerPort(Map<String, String> request) {
|
||||
String value = request.get("serverPort");
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getErrorType(
|
||||
Map<String, String> request,
|
||||
@Nullable Map<String, String> respobse,
|
||||
@Nullable Throwable error) {
|
||||
return request.get("errorType");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void normal() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", "POST");
|
||||
request.put("urlFull", "http://github.com");
|
||||
request.put("header.content-length", "10");
|
||||
request.put("header.user-agent", "okhttp 3.x");
|
||||
request.put("header.custom-request-header", "123,456");
|
||||
request.put("networkTransport", "udp");
|
||||
request.put("networkType", "ipv4");
|
||||
request.put("networkProtocolName", "http");
|
||||
request.put("networkProtocolVersion", "1.1");
|
||||
request.put("networkPeerAddress", "4.3.2.1");
|
||||
request.put("networkPeerPort", "456");
|
||||
request.put("serverAddress", "github.com");
|
||||
request.put("serverPort", "80");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "202");
|
||||
response.put("header.content-length", "20");
|
||||
response.put("header.custom-response-header", "654,321");
|
||||
|
||||
ToIntFunction<Context> resendCountFromContext = context -> 2;
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter())
|
||||
.setCapturedRequestHeaders(singletonList("Custom-Request-Header"))
|
||||
.setCapturedResponseHeaders(singletonList("Custom-Response-Header"))
|
||||
.setResendCountIncrementer(resendCountFromContext)
|
||||
.build();
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||
entry(SemanticAttributes.URL_FULL, "http://github.com"),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.request.header.custom-request-header"),
|
||||
asList("123", "456")),
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "github.com"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 80L),
|
||||
entry(HttpAttributes.HTTP_REQUEST_RESEND_COUNT, 2L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.response.header.custom-response-header"),
|
||||
asList("654", "321")),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "4.3.2.1"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_PORT, 456L));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ArgumentsSource(ValidRequestMethodsProvider.class)
|
||||
void shouldExtractKnownMethods(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod)
|
||||
.doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"get", "Get"})
|
||||
void shouldTreatMethodsAsCaseSensitive(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"PURGE", "not a method really"})
|
||||
void shouldUseOtherForUnknownMethods(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"only", "custom", "methods", "allowed"})
|
||||
void shouldExtractKnownMethods_override(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter())
|
||||
.setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed")))
|
||||
.build();
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod)
|
||||
.doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ArgumentsSource(ValidRequestMethodsProvider.class)
|
||||
void shouldUseOtherForUnknownMethods_override(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter())
|
||||
.setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed")))
|
||||
.build();
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractErrorType_httpStatusCode() {
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "400");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), emptyMap());
|
||||
extractor.onEnd(attributes, Context.root(), emptyMap(), response, null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 400)
|
||||
.containsEntry(HttpAttributes.ERROR_TYPE, "400");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractErrorType_getter() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("statusCode", "0");
|
||||
request.put("errorType", "custom error type");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), emptyMap());
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, "custom error type");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractErrorType_exceptionClassName() {
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), emptyMap());
|
||||
extractor.onEnd(attributes, Context.root(), emptyMap(), emptyMap(), new ConnectException());
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(HttpAttributes.ERROR_TYPE, "java.net.ConnectException");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractErrorType_other() {
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), emptyMap());
|
||||
extractor.onEnd(attributes, Context.root(), emptyMap(), emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, HttpConstants._OTHER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractServerAddressAndPortFromHostHeader() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("header.host", "github.com:123");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "github.com"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 123L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractPeerAddressEvenIfItDuplicatesServerAddress() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("networkPeerAddress", "1.2.3.4");
|
||||
request.put("networkPeerPort", "456");
|
||||
request.put("serverAddress", "1.2.3.4");
|
||||
request.put("serverPort", "123");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "1.2.3.4"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 123L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L),
|
||||
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_PORT, 456L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractProtocolNameDifferentFromHttp() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("networkProtocolName", "spdy");
|
||||
request.put("networkProtocolVersion", "3.1");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpClientAttributesExtractor.create(new TestHttpClientAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build()).isEmpty();
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "spdy"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "3.1"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,157 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.http;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.SpanContext;
|
||||
import io.opentelemetry.api.trace.TraceFlags;
|
||||
import io.opentelemetry.api.trace.TraceState;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.OperationListener;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
|
||||
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class HttpClientExperimentalMetricsStableSemconvTest {
|
||||
|
||||
@Test
|
||||
void collectsMetrics() {
|
||||
InMemoryMetricReader metricReader = InMemoryMetricReader.create();
|
||||
SdkMeterProvider meterProvider =
|
||||
SdkMeterProvider.builder().registerMetricReader(metricReader).build();
|
||||
|
||||
OperationListener listener =
|
||||
HttpClientExperimentalMetrics.get().create(meterProvider.get("test"));
|
||||
|
||||
Attributes requestAttributes =
|
||||
Attributes.builder()
|
||||
.put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET")
|
||||
.put(SemanticAttributes.URL_FULL, "https://localhost:1234/")
|
||||
.put(SemanticAttributes.URL_PATH, "/")
|
||||
.put(SemanticAttributes.URL_QUERY, "q=a")
|
||||
.put(SemanticAttributes.SERVER_ADDRESS, "localhost")
|
||||
.put(SemanticAttributes.SERVER_PORT, 1234)
|
||||
.build();
|
||||
|
||||
Attributes responseAttributes =
|
||||
Attributes.builder()
|
||||
.put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)
|
||||
.put(HttpAttributes.ERROR_TYPE, "400")
|
||||
.put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100)
|
||||
.put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200)
|
||||
.put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http")
|
||||
.put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0")
|
||||
.put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4")
|
||||
.put(NetworkAttributes.NETWORK_PEER_PORT, 8080)
|
||||
.build();
|
||||
|
||||
Context parent =
|
||||
Context.root()
|
||||
.with(
|
||||
Span.wrap(
|
||||
SpanContext.create(
|
||||
"ff01020304050600ff0a0b0c0d0e0f00",
|
||||
"090a0b0c0d0e0f00",
|
||||
TraceFlags.getSampled(),
|
||||
TraceState.getDefault())));
|
||||
|
||||
Context context1 = listener.onStart(parent, requestAttributes, nanos(100));
|
||||
|
||||
assertThat(metricReader.collectAllMetrics()).isEmpty();
|
||||
|
||||
Context context2 = listener.onStart(Context.root(), requestAttributes, nanos(150));
|
||||
|
||||
assertThat(metricReader.collectAllMetrics()).isEmpty();
|
||||
|
||||
listener.onEnd(context1, responseAttributes, nanos(250));
|
||||
|
||||
assertThat(metricReader.collectAllMetrics())
|
||||
.satisfiesExactlyInAnyOrder(
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.client.request.size")
|
||||
.hasUnit("By")
|
||||
.hasDescription("Size of HTTP client request bodies.")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasSum(100 /* bytes */)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
|
||||
equalTo(HttpAttributes.ERROR_TYPE, "400"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, 1234))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
|
||||
.hasSpanId("090a0b0c0d0e0f00")))),
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.client.response.size")
|
||||
.hasUnit("By")
|
||||
.hasDescription("Size of HTTP client response bodies.")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasSum(200 /* bytes */)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
|
||||
equalTo(HttpAttributes.ERROR_TYPE, "400"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, 1234))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
|
||||
.hasSpanId("090a0b0c0d0e0f00")))));
|
||||
|
||||
listener.onEnd(context2, responseAttributes, nanos(300));
|
||||
|
||||
assertThat(metricReader.collectAllMetrics())
|
||||
.satisfiesExactlyInAnyOrder(
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.client.request.size")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(point -> point.hasSum(200 /* bytes */))),
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.client.response.size")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(point -> point.hasSum(400 /* bytes */))));
|
||||
}
|
||||
|
||||
private static long nanos(int millis) {
|
||||
return TimeUnit.MILLISECONDS.toNanos(millis);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,128 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.http;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.SpanContext;
|
||||
import io.opentelemetry.api.trace.TraceFlags;
|
||||
import io.opentelemetry.api.trace.TraceState;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.OperationListener;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
|
||||
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class HttpClientMetricsStableSemconvTest {
|
||||
|
||||
static final double[] DURATION_BUCKETS =
|
||||
HttpMetricsUtil.DURATION_SECONDS_BUCKETS.stream().mapToDouble(d -> d).toArray();
|
||||
|
||||
@Test
|
||||
void collectsMetrics() {
|
||||
InMemoryMetricReader metricReader = InMemoryMetricReader.create();
|
||||
SdkMeterProvider meterProvider =
|
||||
SdkMeterProvider.builder().registerMetricReader(metricReader).build();
|
||||
|
||||
OperationListener listener = HttpClientMetrics.get().create(meterProvider.get("test"));
|
||||
|
||||
Attributes requestAttributes =
|
||||
Attributes.builder()
|
||||
.put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET")
|
||||
.put(SemanticAttributes.URL_FULL, "https://localhost:1234/")
|
||||
.put(SemanticAttributes.URL_PATH, "/")
|
||||
.put(SemanticAttributes.URL_QUERY, "q=a")
|
||||
.put(SemanticAttributes.SERVER_ADDRESS, "localhost")
|
||||
.put(SemanticAttributes.SERVER_PORT, 1234)
|
||||
.build();
|
||||
|
||||
Attributes responseAttributes =
|
||||
Attributes.builder()
|
||||
.put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)
|
||||
.put(HttpAttributes.ERROR_TYPE, "400")
|
||||
.put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100)
|
||||
.put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200)
|
||||
.put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http")
|
||||
.put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0")
|
||||
.put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4")
|
||||
.put(NetworkAttributes.NETWORK_PEER_PORT, 8080)
|
||||
.build();
|
||||
|
||||
Context parent =
|
||||
Context.root()
|
||||
.with(
|
||||
Span.wrap(
|
||||
SpanContext.create(
|
||||
"ff01020304050600ff0a0b0c0d0e0f00",
|
||||
"090a0b0c0d0e0f00",
|
||||
TraceFlags.getSampled(),
|
||||
TraceState.getDefault())));
|
||||
|
||||
Context context1 = listener.onStart(parent, requestAttributes, nanos(100));
|
||||
|
||||
assertThat(metricReader.collectAllMetrics()).isEmpty();
|
||||
|
||||
Context context2 = listener.onStart(Context.root(), requestAttributes, nanos(150));
|
||||
|
||||
assertThat(metricReader.collectAllMetrics()).isEmpty();
|
||||
|
||||
listener.onEnd(context1, responseAttributes, nanos(250));
|
||||
|
||||
assertThat(metricReader.collectAllMetrics())
|
||||
.satisfiesExactlyInAnyOrder(
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.client.request.duration")
|
||||
.hasUnit("s")
|
||||
.hasDescription("Duration of HTTP client requests.")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasSum(0.15 /* seconds */)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
|
||||
equalTo(HttpAttributes.ERROR_TYPE, "400"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, 1234))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
|
||||
.hasSpanId("090a0b0c0d0e0f00"))
|
||||
.hasBucketBoundaries(DURATION_BUCKETS))));
|
||||
|
||||
listener.onEnd(context2, responseAttributes, nanos(300));
|
||||
|
||||
assertThat(metricReader.collectAllMetrics())
|
||||
.satisfiesExactlyInAnyOrder(
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.client.request.duration")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
point -> point.hasSum(0.3 /* seconds */))));
|
||||
}
|
||||
|
||||
private static long nanos(int millis) {
|
||||
return TimeUnit.MILLISECONDS.toNanos(millis);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,555 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.http;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.net.ConnectException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ArgumentsSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
class HttpServerAttributesExtractorStableSemconvTest {
|
||||
|
||||
static class TestHttpServerAttributesGetter
|
||||
implements HttpServerAttributesGetter<Map<String, String>, Map<String, String>> {
|
||||
|
||||
@Override
|
||||
public String getHttpRequestMethod(Map<String, String> request) {
|
||||
return request.get("method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrlScheme(Map<String, String> request) {
|
||||
return request.get("urlScheme");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUrlPath(Map<String, String> request) {
|
||||
return request.get("urlPath");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUrlQuery(Map<String, String> request) {
|
||||
return request.get("urlQuery");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHttpRoute(Map<String, String> request) {
|
||||
return request.get("route");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getHttpRequestHeader(Map<String, String> request, String name) {
|
||||
String values = request.get("header." + name);
|
||||
return values == null ? emptyList() : asList(values.split(","));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getHttpResponseStatusCode(
|
||||
Map<String, String> request, Map<String, String> response, @Nullable Throwable error) {
|
||||
String value = response.get("statusCode");
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getHttpResponseHeader(
|
||||
Map<String, String> request, Map<String, String> response, String name) {
|
||||
String values = response.get("header." + name);
|
||||
return values == null ? emptyList() : asList(values.split(","));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkTransport(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("networkTransport");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkType(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("networkType");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolName(
|
||||
Map<String, String> request, Map<String, String> response) {
|
||||
return request.get("networkProtocolName");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolVersion(
|
||||
Map<String, String> request, Map<String, String> response) {
|
||||
return request.get("networkProtocolVersion");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkLocalAddress(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("networkLocalAddress");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getNetworkLocalPort(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
String value = request.get("networkLocalPort");
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkPeerAddress(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("networkPeerAddress");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getNetworkPeerPort(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
String value = request.get("networkPeerPort");
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getErrorType(
|
||||
Map<String, String> request,
|
||||
@Nullable Map<String, String> respobse,
|
||||
@Nullable Throwable error) {
|
||||
return request.get("errorType");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void normal() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", "POST");
|
||||
request.put("urlFull", "https://github.com");
|
||||
request.put("urlPath", "/repositories/1");
|
||||
request.put("urlQuery", "details=true");
|
||||
request.put("urlScheme", "https");
|
||||
request.put("header.content-length", "10");
|
||||
request.put("route", "/repositories/{id}");
|
||||
request.put("header.user-agent", "okhttp 3.x");
|
||||
request.put("header.host", "github.com:443");
|
||||
request.put("header.forwarded", "for=1.1.1.1;proto=https");
|
||||
request.put("header.custom-request-header", "123,456");
|
||||
request.put("networkTransport", "udp");
|
||||
request.put("networkType", "ipv4");
|
||||
request.put("networkProtocolName", "http");
|
||||
request.put("networkProtocolVersion", "2.0");
|
||||
request.put("networkLocalAddress", "1.2.3.4");
|
||||
request.put("networkLocalPort", "42");
|
||||
request.put("networkPeerAddress", "4.3.2.1");
|
||||
request.put("networkPeerPort", "456");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "202");
|
||||
response.put("header.content-length", "20");
|
||||
response.put("header.custom-response-header", "654,321");
|
||||
|
||||
Function<Context, String> routeFromContext = ctx -> "/repositories/{repoId}";
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter())
|
||||
.setCapturedRequestHeaders(singletonList("Custom-Request-Header"))
|
||||
.setCapturedResponseHeaders(singletonList("Custom-Response-Header"))
|
||||
.setHttpRouteGetter(routeFromContext)
|
||||
.build();
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "github.com"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 443L),
|
||||
entry(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||
entry(SemanticAttributes.URL_SCHEME, "https"),
|
||||
entry(SemanticAttributes.URL_PATH, "/repositories/1"),
|
||||
entry(SemanticAttributes.URL_QUERY, "details=true"),
|
||||
entry(SemanticAttributes.USER_AGENT_ORIGINAL, "okhttp 3.x"),
|
||||
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{id}"),
|
||||
entry(SemanticAttributes.CLIENT_ADDRESS, "1.1.1.1"),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.request.header.custom-request-header"),
|
||||
asList("123", "456")));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "4.3.2.1"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_PORT, 456L),
|
||||
entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"),
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L),
|
||||
entry(
|
||||
AttributeKey.stringArrayKey("http.response.header.custom-response-header"),
|
||||
asList("654", "321")));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ArgumentsSource(ValidRequestMethodsProvider.class)
|
||||
void shouldExtractKnownMethods(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod)
|
||||
.doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"get", "Get"})
|
||||
void shouldTreatMethodsAsCaseSensitive(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"PURGE", "not a method really"})
|
||||
void shouldUseOtherForUnknownMethods(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"only", "custom", "methods", "allowed"})
|
||||
void shouldExtractKnownMethods_override(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter())
|
||||
.setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed")))
|
||||
.build();
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, requestMethod)
|
||||
.doesNotContainKey(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ArgumentsSource(ValidRequestMethodsProvider.class)
|
||||
void shouldUseOtherForUnknownMethods_override(String requestMethod) {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("method", requestMethod);
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.builder(new TestHttpServerAttributesGetter())
|
||||
.setKnownMethods(new HashSet<>(asList("only", "custom", "methods", "allowed")))
|
||||
.build();
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), request);
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, HttpConstants._OTHER)
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, requestMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractErrorType_httpStatusCode() {
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "500");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), emptyMap());
|
||||
extractor.onEnd(attributes, Context.root(), emptyMap(), response, null);
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 500)
|
||||
.containsEntry(HttpAttributes.ERROR_TYPE, "500");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractErrorType_getter() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("statusCode", "0");
|
||||
request.put("errorType", "custom error type");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), emptyMap());
|
||||
extractor.onEnd(attributes, Context.root(), request, emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, "custom error type");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractErrorType_exceptionClassName() {
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), emptyMap());
|
||||
extractor.onEnd(attributes, Context.root(), emptyMap(), emptyMap(), new ConnectException());
|
||||
|
||||
assertThat(attributes.build())
|
||||
.containsEntry(HttpAttributes.ERROR_TYPE, "java.net.ConnectException");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractErrorType_other() {
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder attributes = Attributes.builder();
|
||||
extractor.onStart(attributes, Context.root(), emptyMap());
|
||||
extractor.onEnd(attributes, Context.root(), emptyMap(), emptyMap(), null);
|
||||
|
||||
assertThat(attributes.build()).containsEntry(HttpAttributes.ERROR_TYPE, HttpConstants._OTHER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPreferUrlSchemeFromForwardedHeader() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("urlScheme", "http");
|
||||
request.put("header.forwarded", "proto=https");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "202");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build()).containsOnly(entry(SemanticAttributes.URL_SCHEME, "https"));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractServerAddressAndPortFromForwardedHeader() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("header.forwarded", "host=example.com:42");
|
||||
request.put("header.x-forwarded-host", "opentelemetry.io:987");
|
||||
request.put("header.host", "github.com:123");
|
||||
request.put("header.:authority", "opentelemetry.io:42");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "example.com"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 42L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractServerAddressAndPortFromForwardedHostHeader() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("header.x-forwarded-host", "opentelemetry.io:987");
|
||||
request.put("header.host", "github.com:123");
|
||||
request.put("header.:authority", "opentelemetry.io:42");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 987L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractServerAddressAndPortFromAuthorityPseudoHeader() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("header.:authority", "opentelemetry.io:42");
|
||||
request.put("header.host", "github.com:123");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 42L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractServerAddressAndPortFromHostHeader() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("header.host", "github.com:123");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "github.com"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 123L));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractPeerAddressEvenIfItDuplicatesClientAddress() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("networkPeerAddress", "1.2.3.4");
|
||||
request.put("networkPeerPort", "456");
|
||||
request.put("header.forwarded", "for=1.2.3.4:123");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(entry(SemanticAttributes.CLIENT_ADDRESS, "1.2.3.4"));
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L),
|
||||
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_PORT, 456L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExtractProtocolNameDifferentFromHttp() {
|
||||
Map<String, String> request = new HashMap<>();
|
||||
request.put("networkProtocolName", "spdy");
|
||||
request.put("networkProtocolVersion", "3.1");
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("statusCode", "200");
|
||||
|
||||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
HttpServerAttributesExtractor.create(new TestHttpServerAttributesGetter());
|
||||
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, Context.root(), request);
|
||||
assertThat(startAttributes.build()).isEmpty();
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, Context.root(), request, response, null);
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "spdy"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "3.1"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,249 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.http;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.SpanContext;
|
||||
import io.opentelemetry.api.trace.TraceFlags;
|
||||
import io.opentelemetry.api.trace.TraceState;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.OperationListener;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
|
||||
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class HttpServerExperimentalMetricsStableSemconvTest {
|
||||
|
||||
@Test
|
||||
void collectsMetrics() {
|
||||
InMemoryMetricReader metricReader = InMemoryMetricReader.create();
|
||||
SdkMeterProvider meterProvider =
|
||||
SdkMeterProvider.builder().registerMetricReader(metricReader).build();
|
||||
|
||||
OperationListener listener =
|
||||
HttpServerExperimentalMetrics.get().create(meterProvider.get("test"));
|
||||
|
||||
Attributes requestAttributes =
|
||||
Attributes.builder()
|
||||
.put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET")
|
||||
.put(SemanticAttributes.URL_SCHEME, "https")
|
||||
.put(SemanticAttributes.URL_PATH, "/")
|
||||
.put(SemanticAttributes.URL_QUERY, "q=a")
|
||||
.put(SemanticAttributes.NETWORK_TRANSPORT, "tcp")
|
||||
.put(SemanticAttributes.NETWORK_TYPE, "ipv4")
|
||||
.put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http")
|
||||
.put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0")
|
||||
.put(SemanticAttributes.SERVER_ADDRESS, "localhost")
|
||||
.put(SemanticAttributes.SERVER_PORT, 1234)
|
||||
.build();
|
||||
|
||||
Attributes responseAttributes =
|
||||
Attributes.builder()
|
||||
.put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)
|
||||
.put(HttpAttributes.ERROR_TYPE, "500")
|
||||
.put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100)
|
||||
.put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200)
|
||||
.put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4")
|
||||
.put(NetworkAttributes.NETWORK_PEER_PORT, 8080)
|
||||
.put(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4.3.2.1")
|
||||
.put(NetworkAttributes.NETWORK_LOCAL_PORT, 9090)
|
||||
.build();
|
||||
|
||||
SpanContext spanContext1 =
|
||||
SpanContext.create(
|
||||
"ff01020304050600ff0a0b0c0d0e0f00",
|
||||
"090a0b0c0d0e0f00",
|
||||
TraceFlags.getSampled(),
|
||||
TraceState.getDefault());
|
||||
SpanContext spanContext2 =
|
||||
SpanContext.create(
|
||||
"123456789abcdef00000000000999999",
|
||||
"abcde00000054321",
|
||||
TraceFlags.getSampled(),
|
||||
TraceState.getDefault());
|
||||
|
||||
Context parent1 = Context.root().with(Span.wrap(spanContext1));
|
||||
Context context1 = listener.onStart(parent1, requestAttributes, nanos(100));
|
||||
|
||||
assertThat(metricReader.collectAllMetrics())
|
||||
.satisfiesExactlyInAnyOrder(
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.server.active_requests")
|
||||
.hasUnit("{requests}")
|
||||
.hasDescription("Number of active HTTP server requests.")
|
||||
.hasLongSumSatisfying(
|
||||
sum ->
|
||||
sum.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasValue(1)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.URL_SCHEME, "https"))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
.hasTraceId(spanContext1.getTraceId())
|
||||
.hasSpanId(spanContext1.getSpanId())))));
|
||||
|
||||
Context parent2 = Context.root().with(Span.wrap(spanContext2));
|
||||
Context context2 = listener.onStart(parent2, requestAttributes, nanos(150));
|
||||
|
||||
assertThat(metricReader.collectAllMetrics())
|
||||
.satisfiesExactlyInAnyOrder(
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.server.active_requests")
|
||||
.hasLongSumSatisfying(
|
||||
sum ->
|
||||
sum.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasValue(2)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.URL_SCHEME, "https"))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
.hasTraceId(spanContext2.getTraceId())
|
||||
.hasSpanId(spanContext2.getSpanId())))));
|
||||
|
||||
listener.onEnd(context1, responseAttributes, nanos(250));
|
||||
|
||||
assertThat(metricReader.collectAllMetrics())
|
||||
.satisfiesExactlyInAnyOrder(
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.server.active_requests")
|
||||
.hasLongSumSatisfying(
|
||||
sum ->
|
||||
sum.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasValue(1)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.URL_SCHEME, "https"))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
.hasTraceId(spanContext1.getTraceId())
|
||||
.hasSpanId(spanContext1.getSpanId())))),
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.server.request.size")
|
||||
.hasUnit("By")
|
||||
.hasDescription("Size of HTTP server request bodies.")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasSum(100 /* bytes */)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
|
||||
equalTo(HttpAttributes.ERROR_TYPE, "500"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.URL_SCHEME, "https"))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
.hasTraceId(spanContext1.getTraceId())
|
||||
.hasSpanId(spanContext1.getSpanId())))),
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.server.response.size")
|
||||
.hasUnit("By")
|
||||
.hasDescription("Size of HTTP server response bodies.")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasSum(200 /* bytes */)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
|
||||
equalTo(HttpAttributes.ERROR_TYPE, "500"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.URL_SCHEME, "https"))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
.hasTraceId(spanContext1.getTraceId())
|
||||
.hasSpanId(spanContext1.getSpanId())))));
|
||||
|
||||
listener.onEnd(context2, responseAttributes, nanos(300));
|
||||
|
||||
assertThat(metricReader.collectAllMetrics())
|
||||
.satisfiesExactlyInAnyOrder(
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.server.active_requests")
|
||||
.hasLongSumSatisfying(
|
||||
sum ->
|
||||
sum.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasValue(0)
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
.hasTraceId(spanContext2.getTraceId())
|
||||
.hasSpanId(spanContext2.getSpanId())))),
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.server.request.size")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasSum(200 /* bytes */)
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
.hasTraceId(spanContext2.getTraceId())
|
||||
.hasSpanId(spanContext2.getSpanId())))),
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.server.response.size")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasSum(400 /* bytes */)
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
.hasTraceId(spanContext2.getTraceId())
|
||||
.hasSpanId(spanContext2.getSpanId())))));
|
||||
}
|
||||
|
||||
private static long nanos(int millis) {
|
||||
return TimeUnit.MILLISECONDS.toNanos(millis);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,182 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.http;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.SpanContext;
|
||||
import io.opentelemetry.api.trace.TraceFlags;
|
||||
import io.opentelemetry.api.trace.TraceState;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.OperationListener;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
|
||||
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class HttpServerMetricsStableSemconvTest {
|
||||
|
||||
static final double[] DURATION_BUCKETS =
|
||||
HttpMetricsUtil.DURATION_SECONDS_BUCKETS.stream().mapToDouble(d -> d).toArray();
|
||||
|
||||
@Test
|
||||
void collectsMetrics() {
|
||||
InMemoryMetricReader metricReader = InMemoryMetricReader.create();
|
||||
SdkMeterProvider meterProvider =
|
||||
SdkMeterProvider.builder().registerMetricReader(metricReader).build();
|
||||
|
||||
OperationListener listener = HttpServerMetrics.get().create(meterProvider.get("test"));
|
||||
|
||||
Attributes requestAttributes =
|
||||
Attributes.builder()
|
||||
.put(SemanticAttributes.HTTP_REQUEST_METHOD, "GET")
|
||||
.put(SemanticAttributes.URL_SCHEME, "https")
|
||||
.put(SemanticAttributes.URL_PATH, "/")
|
||||
.put(SemanticAttributes.URL_QUERY, "q=a")
|
||||
.put(SemanticAttributes.NETWORK_TRANSPORT, "tcp")
|
||||
.put(SemanticAttributes.NETWORK_TYPE, "ipv4")
|
||||
.put(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http")
|
||||
.put(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0")
|
||||
.put(SemanticAttributes.SERVER_ADDRESS, "localhost")
|
||||
.put(SemanticAttributes.SERVER_PORT, 1234)
|
||||
.build();
|
||||
|
||||
Attributes responseAttributes =
|
||||
Attributes.builder()
|
||||
.put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)
|
||||
.put(HttpAttributes.ERROR_TYPE, "500")
|
||||
.put(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, 100)
|
||||
.put(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, 200)
|
||||
.put(NetworkAttributes.NETWORK_PEER_ADDRESS, "1.2.3.4")
|
||||
.put(NetworkAttributes.NETWORK_PEER_PORT, 8080)
|
||||
.put(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4.3.2.1")
|
||||
.put(NetworkAttributes.NETWORK_LOCAL_PORT, 9090)
|
||||
.build();
|
||||
|
||||
SpanContext spanContext1 =
|
||||
SpanContext.create(
|
||||
"ff01020304050600ff0a0b0c0d0e0f00",
|
||||
"090a0b0c0d0e0f00",
|
||||
TraceFlags.getSampled(),
|
||||
TraceState.getDefault());
|
||||
SpanContext spanContext2 =
|
||||
SpanContext.create(
|
||||
"123456789abcdef00000000000999999",
|
||||
"abcde00000054321",
|
||||
TraceFlags.getSampled(),
|
||||
TraceState.getDefault());
|
||||
|
||||
Context parent1 = Context.root().with(Span.wrap(spanContext1));
|
||||
Context context1 = listener.onStart(parent1, requestAttributes, nanos(100));
|
||||
|
||||
Context parent2 = Context.root().with(Span.wrap(spanContext2));
|
||||
Context context2 = listener.onStart(parent2, requestAttributes, nanos(150));
|
||||
|
||||
listener.onEnd(context1, responseAttributes, nanos(250));
|
||||
|
||||
assertThat(metricReader.collectAllMetrics())
|
||||
.satisfiesExactlyInAnyOrder(
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.server.request.duration")
|
||||
.hasDescription("Duration of HTTP server requests.")
|
||||
.hasUnit("s")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasSum(0.15 /* seconds */)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
|
||||
equalTo(HttpAttributes.ERROR_TYPE, "500"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
equalTo(
|
||||
SemanticAttributes.NETWORK_PROTOCOL_VERSION, "2.0"),
|
||||
equalTo(SemanticAttributes.URL_SCHEME, "https"))
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
.hasTraceId(spanContext1.getTraceId())
|
||||
.hasSpanId(spanContext1.getSpanId()))
|
||||
.hasBucketBoundaries(DURATION_BUCKETS))));
|
||||
|
||||
listener.onEnd(context2, responseAttributes, nanos(300));
|
||||
|
||||
assertThat(metricReader.collectAllMetrics())
|
||||
.satisfiesExactlyInAnyOrder(
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.server.request.duration")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasSum(0.3 /* seconds */)
|
||||
.hasExemplarsSatisfying(
|
||||
exemplar ->
|
||||
exemplar
|
||||
.hasTraceId(spanContext2.getTraceId())
|
||||
.hasSpanId(spanContext2.getSpanId())))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void collectsHttpRouteFromEndAttributes() {
|
||||
// given
|
||||
InMemoryMetricReader metricReader = InMemoryMetricReader.create();
|
||||
SdkMeterProvider meterProvider =
|
||||
SdkMeterProvider.builder().registerMetricReader(metricReader).build();
|
||||
|
||||
OperationListener listener = HttpServerMetrics.get().create(meterProvider.get("test"));
|
||||
|
||||
Attributes requestAttributes =
|
||||
Attributes.builder()
|
||||
.put(SemanticAttributes.SERVER_ADDRESS, "host")
|
||||
.put(SemanticAttributes.URL_SCHEME, "https")
|
||||
.build();
|
||||
|
||||
Attributes responseAttributes =
|
||||
Attributes.builder().put(SemanticAttributes.HTTP_ROUTE, "/test/{id}").build();
|
||||
|
||||
Context parentContext = Context.root();
|
||||
|
||||
// when
|
||||
Context context = listener.onStart(parentContext, requestAttributes, nanos(100));
|
||||
listener.onEnd(context, responseAttributes, nanos(200));
|
||||
|
||||
// then
|
||||
assertThat(metricReader.collectAllMetrics())
|
||||
.anySatisfy(
|
||||
metric ->
|
||||
assertThat(metric)
|
||||
.hasName("http.server.request.duration")
|
||||
.hasUnit("s")
|
||||
.hasHistogramSatisfying(
|
||||
histogram ->
|
||||
histogram.hasPointsSatisfying(
|
||||
point ->
|
||||
point
|
||||
.hasSum(0.100 /* seconds */)
|
||||
.hasAttributesSatisfying(
|
||||
equalTo(SemanticAttributes.URL_SCHEME, "https"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_ROUTE, "/test/{id}")))));
|
||||
}
|
||||
|
||||
private static long nanos(int millis) {
|
||||
return TimeUnit.MILLISECONDS.toNanos(millis);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.net;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings("deprecation") // testing deprecated class
|
||||
class NetClientAttributesExtractorStableSemconvTest {
|
||||
|
||||
static class TestNetClientAttributesGetter
|
||||
implements NetClientAttributesGetter<Map<String, String>, Map<String, String>> {
|
||||
|
||||
@Override
|
||||
public String getTransport(Map<String, String> request, Map<String, String> response) {
|
||||
return response.get("netTransport");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkTransport(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("transport");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkType(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("type");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolName(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("protocolName");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolVersion(
|
||||
Map<String, String> request, @Nullable Map<String, String> response) {
|
||||
return request.get("protocolVersion");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerAddress(Map<String, String> request) {
|
||||
return request.get("peerName");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getServerPort(Map<String, String> request) {
|
||||
String peerPort = request.get("peerPort");
|
||||
return peerPort == null ? null : Integer.valueOf(peerPort);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSockFamily(Map<String, String> request, Map<String, String> response) {
|
||||
return response.get("sockFamily");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNetworkPeerAddress(Map<String, String> request, Map<String, String> response) {
|
||||
return response.get("sockPeerAddr");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getNetworkPeerPort(Map<String, String> request, Map<String, String> response) {
|
||||
String sockPeerPort = response.get("sockPeerPort");
|
||||
return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort);
|
||||
}
|
||||
}
|
||||
|
||||
private final AttributesExtractor<Map<String, String>, Map<String, String>> extractor =
|
||||
NetClientAttributesExtractor.create(new TestNetClientAttributesGetter());
|
||||
|
||||
@Test
|
||||
void normal() {
|
||||
// given
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("netTransport", IP_TCP);
|
||||
map.put("transport", "tcp");
|
||||
map.put("type", "ipv6");
|
||||
map.put("protocolName", "http");
|
||||
map.put("protocolVersion", "1.1");
|
||||
map.put("peerName", "opentelemetry.io");
|
||||
map.put("peerPort", "42");
|
||||
map.put("sockFamily", "inet6");
|
||||
map.put("sockPeerAddr", "1:2:3:4::");
|
||||
map.put("sockPeerPort", "123");
|
||||
|
||||
Context context = Context.root();
|
||||
|
||||
// when
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, context, map);
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, context, map, map, null);
|
||||
|
||||
// then
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 42L));
|
||||
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"),
|
||||
entry(SemanticAttributes.NETWORK_TYPE, "ipv6"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1:2:3:4::"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_PORT, 123L));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,148 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.api.instrumenter.net;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NetTransportValues.IP_TCP;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings("deprecation") // testing deprecated class
|
||||
class NetServerAttributesExtractorStableSemconvTest {
|
||||
|
||||
static class TestNetServerAttributesGetter
|
||||
implements NetServerAttributesGetter<Map<String, String>, Void> {
|
||||
|
||||
@Override
|
||||
public String getTransport(Map<String, String> request) {
|
||||
return request.get("netTransport");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkTransport(Map<String, String> request, @Nullable Void response) {
|
||||
return request.get("transport");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkType(Map<String, String> request, @Nullable Void response) {
|
||||
return request.get("type");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolName(Map<String, String> request, Void response) {
|
||||
return request.get("protocolName");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkProtocolVersion(Map<String, String> request, Void response) {
|
||||
return request.get("protocolVersion");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getServerAddress(Map<String, String> request) {
|
||||
return request.get("hostName");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getServerPort(Map<String, String> request) {
|
||||
String hostPort = request.get("hostPort");
|
||||
return hostPort == null ? null : Integer.valueOf(hostPort);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getSockFamily(Map<String, String> request) {
|
||||
return request.get("sockFamily");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNetworkPeerAddress(Map<String, String> request, Void response) {
|
||||
return request.get("sockPeerAddr");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getNetworkPeerPort(Map<String, String> request, Void response) {
|
||||
String sockPeerPort = request.get("sockPeerPort");
|
||||
return sockPeerPort == null ? null : Integer.valueOf(sockPeerPort);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getNetworkLocalAddress(Map<String, String> request, Void response) {
|
||||
return request.get("sockHostAddr");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer getNetworkLocalPort(Map<String, String> request, Void response) {
|
||||
String sockHostPort = request.get("sockHostPort");
|
||||
return sockHostPort == null ? null : Integer.valueOf(sockHostPort);
|
||||
}
|
||||
}
|
||||
|
||||
AttributesExtractor<Map<String, String>, Void> extractor =
|
||||
NetServerAttributesExtractor.create(new TestNetServerAttributesGetter());
|
||||
|
||||
@Test
|
||||
void normal() {
|
||||
// given
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("netTransport", IP_TCP);
|
||||
map.put("transport", "tcp");
|
||||
map.put("type", "ipv6");
|
||||
map.put("protocolName", "http");
|
||||
map.put("protocolVersion", "1.1");
|
||||
map.put("hostName", "opentelemetry.io");
|
||||
map.put("hostPort", "80");
|
||||
map.put("sockFamily", "inet6");
|
||||
map.put("sockPeerAddr", "1:2:3:4::");
|
||||
map.put("sockPeerPort", "42");
|
||||
map.put("sockHostAddr", "4:3:2:1::");
|
||||
map.put("sockHostPort", "8080");
|
||||
|
||||
Context context = Context.root();
|
||||
|
||||
// when
|
||||
AttributesBuilder startAttributes = Attributes.builder();
|
||||
extractor.onStart(startAttributes, context, map);
|
||||
|
||||
AttributesBuilder endAttributes = Attributes.builder();
|
||||
extractor.onEnd(endAttributes, context, map, null, null);
|
||||
|
||||
// then
|
||||
assertThat(startAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.SERVER_ADDRESS, "opentelemetry.io"),
|
||||
entry(SemanticAttributes.SERVER_PORT, 80L));
|
||||
|
||||
assertThat(endAttributes.build())
|
||||
.containsOnly(
|
||||
entry(SemanticAttributes.NETWORK_TRANSPORT, "tcp"),
|
||||
entry(SemanticAttributes.NETWORK_TYPE, "ipv6"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_NAME, "http"),
|
||||
entry(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
entry(NetworkAttributes.NETWORK_LOCAL_ADDRESS, "4:3:2:1::"),
|
||||
entry(NetworkAttributes.NETWORK_LOCAL_PORT, 8080L),
|
||||
entry(NetworkAttributes.NETWORK_PEER_ADDRESS, "1:2:3:4::"),
|
||||
entry(NetworkAttributes.NETWORK_PEER_PORT, 42L));
|
||||
}
|
||||
}
|
||||
|
|
@ -16,31 +16,16 @@ import java.util.Set;
|
|||
*/
|
||||
public final class SemconvStability {
|
||||
|
||||
private static final boolean emitOldHttpSemconv;
|
||||
private static final boolean emitStableHttpSemconv;
|
||||
private static final boolean emitOldJvmSemconv;
|
||||
private static final boolean emitStableJvmSemconv;
|
||||
|
||||
static {
|
||||
boolean oldHttp = true;
|
||||
boolean stableHttp = false;
|
||||
boolean oldJvm = true;
|
||||
boolean stableJvm = false;
|
||||
|
||||
String value = ConfigPropertiesUtil.getString("otel.semconv-stability.opt-in");
|
||||
if (value != null) {
|
||||
Set<String> values = new HashSet<>(asList(value.split(",")));
|
||||
if (values.contains("http")) {
|
||||
oldHttp = false;
|
||||
stableHttp = true;
|
||||
}
|
||||
// no else -- technically it's possible to set "http,http/dup", in which case we should emit
|
||||
// both sets of attributes
|
||||
if (values.contains("http/dup")) {
|
||||
oldHttp = true;
|
||||
stableHttp = true;
|
||||
}
|
||||
|
||||
if (values.contains("jvm")) {
|
||||
oldJvm = false;
|
||||
stableJvm = true;
|
||||
|
|
@ -51,18 +36,16 @@ public final class SemconvStability {
|
|||
}
|
||||
}
|
||||
|
||||
emitOldHttpSemconv = oldHttp;
|
||||
emitStableHttpSemconv = stableHttp;
|
||||
emitOldJvmSemconv = oldJvm;
|
||||
emitStableJvmSemconv = stableJvm;
|
||||
}
|
||||
|
||||
public static boolean emitOldHttpSemconv() {
|
||||
return emitOldHttpSemconv;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean emitStableHttpSemconv() {
|
||||
return emitStableHttpSemconv;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean emitOldJvmSemconv() {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ package io.opentelemetry.instrumentation.apachedubbo.v2_7
|
|||
import io.opentelemetry.api.trace.SpanKind
|
||||
import io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService
|
||||
import io.opentelemetry.instrumentation.apachedubbo.v2_7.impl.HelloServiceImpl
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes
|
||||
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
|
||||
import io.opentelemetry.instrumentation.test.utils.PortUtils
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
|
|
@ -102,11 +103,11 @@ abstract class AbstractDubboTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.RPC_SYSTEM" "apache_dubbo"
|
||||
"$SemanticAttributes.RPC_SERVICE" "org.apache.dubbo.rpc.service.GenericService"
|
||||
"$SemanticAttributes.RPC_METHOD" "\$invoke"
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.NET_PEER_PORT" Long
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == null || it instanceof String}
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" { it == null || it instanceof Long}
|
||||
"$SemanticAttributes.NET_SOCK_PEER_NAME" { it == null || it instanceof String}
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" Long
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == null || it instanceof String}
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" { it == null || it instanceof Long}
|
||||
"$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
@ -117,10 +118,9 @@ abstract class AbstractDubboTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.RPC_SYSTEM" "apache_dubbo"
|
||||
"$SemanticAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"
|
||||
"$SemanticAttributes.RPC_METHOD" "hello"
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" String
|
||||
"$SemanticAttributes.NET_SOCK_PEER_NAME" String
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" Long
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" String
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" Long
|
||||
"$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -179,11 +179,11 @@ abstract class AbstractDubboTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.RPC_SYSTEM" "apache_dubbo"
|
||||
"$SemanticAttributes.RPC_SERVICE" "org.apache.dubbo.rpc.service.GenericService"
|
||||
"$SemanticAttributes.RPC_METHOD" "\$invokeAsync"
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.NET_PEER_PORT" Long
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == null || it instanceof String}
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" { it == null || it instanceof Long}
|
||||
"$SemanticAttributes.NET_SOCK_PEER_NAME" { it == null || it instanceof String}
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" Long
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == null || it instanceof String}
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" { it == null || it instanceof Long}
|
||||
"$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
@ -194,10 +194,9 @@ abstract class AbstractDubboTest extends InstrumentationSpecification {
|
|||
"$SemanticAttributes.RPC_SYSTEM" "apache_dubbo"
|
||||
"$SemanticAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"
|
||||
"$SemanticAttributes.RPC_METHOD" "hello"
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" String
|
||||
"$SemanticAttributes.NET_SOCK_PEER_NAME" String
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" Long
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" String
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" Long
|
||||
"$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService
|
|||
import io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService
|
||||
import io.opentelemetry.instrumentation.apachedubbo.v2_7.impl.HelloServiceImpl
|
||||
import io.opentelemetry.instrumentation.apachedubbo.v2_7.impl.MiddleServiceImpl
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes
|
||||
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
|
||||
import io.opentelemetry.instrumentation.test.utils.PortUtils
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
|
|
@ -138,11 +139,11 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification
|
|||
"$SemanticAttributes.RPC_SYSTEM" "apache_dubbo"
|
||||
"$SemanticAttributes.RPC_SERVICE" "org.apache.dubbo.rpc.service.GenericService"
|
||||
"$SemanticAttributes.RPC_METHOD" "\$invoke"
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.NET_PEER_PORT" Long
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == null || it instanceof String}
|
||||
"$SemanticAttributes.NET_SOCK_PEER_NAME" { it == null || it instanceof String}
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" { it == null || it instanceof Long}
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" Long
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == null || it instanceof String}
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" { it == null || it instanceof Long}
|
||||
"$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
@ -153,10 +154,9 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification
|
|||
"$SemanticAttributes.RPC_SYSTEM" "apache_dubbo"
|
||||
"$SemanticAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService"
|
||||
"$SemanticAttributes.RPC_METHOD" "hello"
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" String
|
||||
"$SemanticAttributes.NET_SOCK_PEER_NAME" String
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" Long
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" String
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" Long
|
||||
"$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
||||
}
|
||||
}
|
||||
span(3) {
|
||||
|
|
@ -167,11 +167,11 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification
|
|||
"$SemanticAttributes.RPC_SYSTEM" "apache_dubbo"
|
||||
"$SemanticAttributes.RPC_SERVICE" "org.apache.dubbo.rpc.service.GenericService"
|
||||
"$SemanticAttributes.RPC_METHOD" "\$invoke"
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.NET_PEER_PORT" Long
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == null || it instanceof String }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_NAME" { it == null || it instanceof String }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" Long
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == null || it instanceof String }
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
||||
}
|
||||
}
|
||||
span(4) {
|
||||
|
|
@ -182,10 +182,9 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification
|
|||
"$SemanticAttributes.RPC_SYSTEM" "apache_dubbo"
|
||||
"$SemanticAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"
|
||||
"$SemanticAttributes.RPC_METHOD" "hello"
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" String
|
||||
"$SemanticAttributes.NET_SOCK_PEER_NAME" String
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" Long
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" String
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" Long
|
||||
"$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -256,11 +255,11 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification
|
|||
"$SemanticAttributes.RPC_SYSTEM" "apache_dubbo"
|
||||
"$SemanticAttributes.RPC_SERVICE" "org.apache.dubbo.rpc.service.GenericService"
|
||||
"$SemanticAttributes.RPC_METHOD" "\$invoke"
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.NET_PEER_PORT" Long
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == null || it instanceof String}
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" { it == null || it instanceof Long}
|
||||
"$SemanticAttributes.NET_SOCK_PEER_NAME" { it == null || it instanceof String}
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" Long
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == null || it instanceof String}
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" { it == null || it instanceof Long}
|
||||
"$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
@ -271,10 +270,9 @@ abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification
|
|||
"$SemanticAttributes.RPC_SYSTEM" "apache_dubbo"
|
||||
"$SemanticAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService"
|
||||
"$SemanticAttributes.RPC_METHOD" "hello"
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" String
|
||||
"$SemanticAttributes.NET_SOCK_PEER_NAME" String
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" Long
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" String
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" Long
|
||||
"$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,8 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import io.opentelemetry.api.common.AttributeKey
|
||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.base.HttpClientTest
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
import org.apache.commons.httpclient.HttpClient
|
||||
import org.apache.commons.httpclient.HttpConnectionManager
|
||||
import org.apache.commons.httpclient.HttpMethod
|
||||
|
|
@ -97,13 +95,4 @@ abstract class AbstractCommonsHttpClientTest extends HttpClientTest<HttpMethod>
|
|||
boolean testNonStandardHttpMethod() {
|
||||
false
|
||||
}
|
||||
|
||||
@Override
|
||||
Set<AttributeKey<?>> httpAttributes(URI uri) {
|
||||
Set<AttributeKey<?>> extra = [
|
||||
SemanticAttributes.HTTP_SCHEME,
|
||||
SemanticAttributes.HTTP_TARGET
|
||||
]
|
||||
super.httpAttributes(uri) + extra
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
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;
|
||||
|
|
@ -33,19 +32,15 @@ abstract class AbstractApacheHttpClientTest<T extends HttpRequest>
|
|||
optionsBuilder.setHttpAttributes(this::getHttpAttributes);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
protected Set<AttributeKey<?>> getHttpAttributes(URI uri) {
|
||||
Set<AttributeKey<?>> attributes = new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
|
||||
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);
|
||||
}
|
||||
// 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.NETWORK_PROTOCOL_VERSION);
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ 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;
|
||||
|
|
@ -69,7 +68,7 @@ class AsyncHttpClientTest extends AbstractHttpClientTest<Request> {
|
|||
request,
|
||||
new AsyncCompletionHandler<Void>() {
|
||||
@Override
|
||||
public Void onCompleted(Response response) throws Exception {
|
||||
public Void onCompleted(Response response) {
|
||||
requestResult.complete(response.getStatusCode());
|
||||
return null;
|
||||
}
|
||||
|
|
@ -82,7 +81,6 @@ class AsyncHttpClientTest extends AbstractHttpClientTest<Request> {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
protected void configure(HttpClientTestOptions.Builder optionsBuilder) {
|
||||
optionsBuilder.disableTestRedirects();
|
||||
|
||||
|
|
@ -90,15 +88,13 @@ class AsyncHttpClientTest extends AbstractHttpClientTest<Request> {
|
|||
if (!Boolean.getBoolean("testLatestDeps")) {
|
||||
optionsBuilder.disableTestReadTimeout();
|
||||
}
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
optionsBuilder.setHttpAttributes(
|
||||
endpoint -> {
|
||||
Set<AttributeKey<?>> attributes =
|
||||
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
|
||||
attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION);
|
||||
return attributes;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import static io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.MapUt
|
|||
import static io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.MapUtils.lowercaseMap;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.FAAS_TRIGGER;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_RESPONSE_STATUS_CODE;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_STATUS_CODE;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.USER_AGENT_ORIGINAL;
|
||||
|
||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
|
||||
|
|
@ -19,7 +18,6 @@ import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
|
|||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
|
||||
import io.opentelemetry.instrumentation.awslambdacore.v1_0.AwsLambdaRequest;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
|
@ -47,19 +45,13 @@ final class ApiGatewayProxyAttributesExtractor
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
void onRequest(AttributesBuilder attributes, APIGatewayProxyRequestEvent request) {
|
||||
String method = request.getHttpMethod();
|
||||
if (SemconvStability.emitStableHttpSemconv()) {
|
||||
if (method == null || knownMethods.contains(method)) {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method);
|
||||
} else {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER);
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method);
|
||||
}
|
||||
}
|
||||
if (SemconvStability.emitOldHttpSemconv()) {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_METHOD, method);
|
||||
if (method == null || knownMethods.contains(method)) {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method);
|
||||
} else {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER);
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method);
|
||||
}
|
||||
|
||||
Map<String, String> headers = lowercaseMap(request.getHeaders());
|
||||
|
|
@ -68,16 +60,7 @@ final class ApiGatewayProxyAttributesExtractor
|
|||
attributes.put(USER_AGENT_ORIGINAL, userAgent);
|
||||
}
|
||||
|
||||
String httpUrl = getHttpUrl(request, headers);
|
||||
if (httpUrl != null) {
|
||||
if (SemconvStability.emitStableHttpSemconv()) {
|
||||
internalSet(attributes, SemanticAttributes.URL_FULL, httpUrl);
|
||||
}
|
||||
|
||||
if (SemconvStability.emitOldHttpSemconv()) {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_URL, httpUrl);
|
||||
}
|
||||
}
|
||||
internalSet(attributes, SemanticAttributes.URL_FULL, getHttpUrl(request, headers));
|
||||
}
|
||||
|
||||
private static String getHttpUrl(
|
||||
|
|
@ -113,7 +96,6 @@ final class ApiGatewayProxyAttributesExtractor
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
public void onEnd(
|
||||
AttributesBuilder attributes,
|
||||
Context context,
|
||||
|
|
@ -123,12 +105,7 @@ final class ApiGatewayProxyAttributesExtractor
|
|||
if (response instanceof APIGatewayProxyResponseEvent) {
|
||||
Integer statusCode = ((APIGatewayProxyResponseEvent) response).getStatusCode();
|
||||
if (statusCode != null) {
|
||||
if (SemconvStability.emitStableHttpSemconv()) {
|
||||
attributes.put(HTTP_RESPONSE_STATUS_CODE, statusCode);
|
||||
}
|
||||
if (SemconvStability.emitOldHttpSemconv()) {
|
||||
attributes.put(HTTP_STATUS_CODE, statusCode);
|
||||
}
|
||||
attributes.put(HTTP_RESPONSE_STATUS_CODE, statusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ import org.mockito.quality.Strictness;
|
|||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
public class AwsLambdaApiGatewayWrapperTest {
|
||||
|
||||
@RegisterExtension
|
||||
|
|
@ -103,12 +102,12 @@ public class AwsLambdaApiGatewayWrapperTest {
|
|||
equalTo(ResourceAttributes.CLOUD_ACCOUNT_ID, "123456789"),
|
||||
equalTo(SemanticAttributes.FAAS_INVOCATION_ID, "1-22-333"),
|
||||
equalTo(SemanticAttributes.FAAS_TRIGGER, "http"),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.USER_AGENT_ORIGINAL, "Test Client"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL,
|
||||
SemanticAttributes.URL_FULL,
|
||||
"http://localhost:123/hello/world?a=b&c=d"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L))));
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L))));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes
|
||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
import spock.lang.Shared
|
||||
|
|
@ -60,15 +61,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.name" queueName
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -85,15 +83,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.method" "PUT"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "PUT"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -110,15 +105,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -135,15 +127,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -160,15 +149,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.method" "PUT"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "PUT"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -184,15 +170,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.method" "PUT"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "PUT"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
span(1) {
|
||||
|
|
@ -206,14 +189,15 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "s3ToSqsTestQueue"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "process"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
@ -235,15 +219,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.method" "GET"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -259,15 +240,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.method" "DELETE"
|
||||
"http.status_code" 204
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "DELETE"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 204
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -283,15 +261,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.method" "DELETE"
|
||||
"http.status_code" 204
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "DELETE"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 204
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -307,15 +282,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -364,15 +336,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.name" queueName
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -388,15 +357,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -412,15 +378,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.method" "PUT"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "PUT"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -435,15 +398,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.method" "CreateTopic"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSNS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -458,15 +418,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.method" "Subscribe"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSNS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -482,15 +439,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -505,15 +459,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.method" "SetTopicAttributes"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSNS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -529,15 +480,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.method" "PUT"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "PUT"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -553,15 +501,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.method" "PUT"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "PUT"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -577,16 +522,15 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "s3ToSnsToSqsTestQueue"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "process"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
span(1) {
|
||||
|
|
@ -608,15 +552,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.method" "GET"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -632,15 +573,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.method" "DELETE"
|
||||
"http.status_code" 204
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "DELETE"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 204
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -656,15 +594,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Amazon S3"
|
||||
"aws.bucket.name" bucketName
|
||||
"http.method" "DELETE"
|
||||
"http.status_code" 204
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "DELETE"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 204
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -680,15 +615,12 @@ class S3TracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes
|
||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
import spock.lang.Shared
|
||||
|
|
@ -52,14 +53,12 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.name" queueName
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" String
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -76,14 +75,12 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" String
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -100,14 +97,12 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
|
|||
"aws.queue.url" queueUrl
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" String
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -123,14 +118,12 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.method" "CreateTopic"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSNS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" String
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -146,14 +139,12 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.method" "Subscribe"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSNS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" String
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -168,14 +159,12 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.method" "Publish"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSNS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" String
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
}
|
||||
}
|
||||
span(1) {
|
||||
|
|
@ -189,14 +178,15 @@ class SnsTracingTest extends AgentInstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"rpc.method" "ReceiveMessage"
|
||||
"http.method" "POST"
|
||||
"http.url" String
|
||||
"net.peer.name" String
|
||||
"net.peer.port" { it == null || Number }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.URL_FULL" String
|
||||
"$SemanticAttributes.SERVER_ADDRESS" String
|
||||
"$SemanticAttributes.SERVER_PORT" { it == null || Number }
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "snsToSqsTestQueue"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "process"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import com.amazonaws.services.s3.AmazonS3Client
|
|||
import com.amazonaws.services.s3.AmazonS3ClientBuilder
|
||||
import io.opentelemetry.api.trace.Span
|
||||
import io.opentelemetry.api.trace.SpanKind
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes
|
||||
import io.opentelemetry.instrumentation.awssdk.v1_11.AbstractAws1ClientTest
|
||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
|
|
@ -99,15 +100,16 @@ class Aws1ClientTest extends AbstractAws1ClientTest implements AgentTestTrait {
|
|||
errorEvent IllegalStateException, "bad handler"
|
||||
hasNoParent()
|
||||
attributes {
|
||||
"$SemanticAttributes.HTTP_URL" "https://s3.amazonaws.com"
|
||||
"$SemanticAttributes.HTTP_METHOD" "HEAD"
|
||||
"$SemanticAttributes.NET_PEER_NAME" "s3.amazonaws.com"
|
||||
"$SemanticAttributes.URL_FULL" "https://s3.amazonaws.com"
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "HEAD"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "s3.amazonaws.com"
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" "Amazon S3"
|
||||
"$SemanticAttributes.RPC_METHOD" "HeadBucket"
|
||||
"aws.endpoint" "https://s3.amazonaws.com"
|
||||
"aws.agent" "java-aws-sdk"
|
||||
"aws.bucket.name" "someBucket"
|
||||
"$HttpAttributes.ERROR_TYPE" IllegalStateException.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import com.amazonaws.services.rds.model.DeleteOptionGroupRequest
|
|||
import com.amazonaws.services.s3.AmazonS3Client
|
||||
import com.amazonaws.services.s3.S3ClientOptions
|
||||
import io.opentelemetry.api.trace.Span
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes
|
||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
import io.opentelemetry.testing.internal.armeria.common.HttpResponse
|
||||
|
|
@ -106,14 +107,12 @@ class Aws0ClientTest extends AgentInstrumentationSpecification {
|
|||
kind CLIENT
|
||||
hasNoParent()
|
||||
attributes {
|
||||
"$SemanticAttributes.HTTP_URL" "${server.httpUri()}"
|
||||
"$SemanticAttributes.HTTP_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" 200
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "127.0.0.1"
|
||||
"$SemanticAttributes.URL_FULL" "${server.httpUri()}"
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "127.0.0.1"
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" { it.contains(service) }
|
||||
"$SemanticAttributes.RPC_METHOD" "${operation}"
|
||||
|
|
@ -170,10 +169,10 @@ class Aws0ClientTest extends AgentInstrumentationSpecification {
|
|||
errorEvent AmazonClientException, ~/Unable to execute HTTP request/
|
||||
hasNoParent()
|
||||
attributes {
|
||||
"$SemanticAttributes.HTTP_URL" "http://localhost:${UNUSABLE_PORT}"
|
||||
"$SemanticAttributes.HTTP_METHOD" "$method"
|
||||
"$SemanticAttributes.NET_PEER_PORT" 61
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:${UNUSABLE_PORT}"
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "$method"
|
||||
"$SemanticAttributes.SERVER_PORT" 61
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" { it.contains(service) }
|
||||
"$SemanticAttributes.RPC_METHOD" "${operation}"
|
||||
|
|
@ -182,6 +181,7 @@ class Aws0ClientTest extends AgentInstrumentationSpecification {
|
|||
for (def addedTag : additionalAttributes) {
|
||||
"$addedTag.key" "$addedTag.value"
|
||||
}
|
||||
"$HttpAttributes.ERROR_TYPE" AmazonClientException.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -217,15 +217,16 @@ class Aws0ClientTest extends AgentInstrumentationSpecification {
|
|||
errorEvent IllegalStateException, "bad handler"
|
||||
hasNoParent()
|
||||
attributes {
|
||||
"$SemanticAttributes.HTTP_URL" "https://s3.amazonaws.com"
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.NET_PEER_NAME" "s3.amazonaws.com"
|
||||
"$SemanticAttributes.URL_FULL" "https://s3.amazonaws.com"
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "GET"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "s3.amazonaws.com"
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" "Amazon S3"
|
||||
"$SemanticAttributes.RPC_METHOD" "GetObject"
|
||||
"aws.endpoint" "https://s3.amazonaws.com"
|
||||
"aws.agent" "java-aws-sdk"
|
||||
"aws.bucket.name" "someBucket"
|
||||
"$HttpAttributes.ERROR_TYPE" IllegalStateException.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -259,16 +260,17 @@ class Aws0ClientTest extends AgentInstrumentationSpecification {
|
|||
errorEvent AmazonClientException, ~/Unable to execute HTTP request/
|
||||
hasNoParent()
|
||||
attributes {
|
||||
"$SemanticAttributes.HTTP_URL" "${server.httpUri()}"
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "127.0.0.1"
|
||||
"$SemanticAttributes.URL_FULL" "${server.httpUri()}"
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "GET"
|
||||
"$SemanticAttributes.SERVER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "127.0.0.1"
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" "Amazon S3"
|
||||
"$SemanticAttributes.RPC_METHOD" "GetObject"
|
||||
"aws.endpoint" "${server.httpUri()}"
|
||||
"aws.agent" "java-aws-sdk"
|
||||
"aws.bucket.name" "someBucket"
|
||||
"$HttpAttributes.ERROR_TYPE" AmazonClientException.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import com.amazonaws.services.rds.model.DeleteOptionGroupRequest
|
|||
import com.amazonaws.services.s3.AmazonS3Client
|
||||
import com.amazonaws.services.s3.AmazonS3ClientBuilder
|
||||
import io.opentelemetry.api.trace.Span
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes
|
||||
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
import io.opentelemetry.testing.internal.armeria.common.HttpResponse
|
||||
|
|
@ -102,15 +103,12 @@ abstract class AbstractAws1ClientTest extends InstrumentationSpecification {
|
|||
kind operation == "SendMessage" ? PRODUCER : CLIENT
|
||||
hasNoParent()
|
||||
attributes {
|
||||
"$SemanticAttributes.HTTP_URL" "${server.httpUri()}"
|
||||
"$SemanticAttributes.HTTP_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" 200
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "127.0.0.1"
|
||||
"$SemanticAttributes.URL_FULL" "${server.httpUri()}"
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "127.0.0.1"
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" { it.contains(service) }
|
||||
"$SemanticAttributes.RPC_METHOD" "${operation}"
|
||||
|
|
@ -182,10 +180,10 @@ abstract class AbstractAws1ClientTest extends InstrumentationSpecification {
|
|||
errorEvent SdkClientException, ~/Unable to execute HTTP request/
|
||||
hasNoParent()
|
||||
attributes {
|
||||
"$SemanticAttributes.HTTP_URL" "http://127.0.0.1:${UNUSABLE_PORT}"
|
||||
"$SemanticAttributes.HTTP_METHOD" "$method"
|
||||
"$SemanticAttributes.NET_PEER_NAME" "127.0.0.1"
|
||||
"$SemanticAttributes.NET_PEER_PORT" 61
|
||||
"$SemanticAttributes.URL_FULL" "http://127.0.0.1:${UNUSABLE_PORT}"
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "$method"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "127.0.0.1"
|
||||
"$SemanticAttributes.SERVER_PORT" 61
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" { it.contains(service) }
|
||||
"$SemanticAttributes.RPC_METHOD" "${operation}"
|
||||
|
|
@ -194,6 +192,7 @@ abstract class AbstractAws1ClientTest extends InstrumentationSpecification {
|
|||
for (def addedTag : additionalAttributes) {
|
||||
"$addedTag.key" "$addedTag.value"
|
||||
}
|
||||
"$HttpAttributes.ERROR_TYPE" SdkClientException.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -237,16 +236,17 @@ abstract class AbstractAws1ClientTest extends InstrumentationSpecification {
|
|||
}
|
||||
hasNoParent()
|
||||
attributes {
|
||||
"$SemanticAttributes.HTTP_URL" "${server.httpUri()}"
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.NET_PEER_NAME" "127.0.0.1"
|
||||
"$SemanticAttributes.URL_FULL" "${server.httpUri()}"
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "GET"
|
||||
"$SemanticAttributes.SERVER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "127.0.0.1"
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" "Amazon S3"
|
||||
"$SemanticAttributes.RPC_METHOD" "GetObject"
|
||||
"aws.endpoint" "${server.httpUri()}"
|
||||
"aws.agent" "java-aws-sdk"
|
||||
"aws.bucket.name" "someBucket"
|
||||
"$HttpAttributes.ERROR_TYPE" {it == SdkClientException.name || it == AmazonClientException.name }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.amazonaws.services.sqs.AmazonSQSAsyncClient
|
|||
import com.amazonaws.services.sqs.AmazonSQSAsyncClientBuilder
|
||||
import com.amazonaws.services.sqs.model.ReceiveMessageRequest
|
||||
import com.amazonaws.services.sqs.model.SendMessageRequest
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes
|
||||
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
|
||||
import io.opentelemetry.instrumentation.test.utils.PortUtils
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
|
|
@ -75,14 +76,12 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"rpc.method" "CreateQueue"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -98,18 +97,16 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.method" "SendMessage"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "publish"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
}
|
||||
}
|
||||
span(1) {
|
||||
|
|
@ -123,14 +120,15 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif
|
|||
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "process"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
@ -170,14 +168,12 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"rpc.method" "CreateQueue"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -193,18 +189,16 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.method" "SendMessage"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "publish"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
}
|
||||
}
|
||||
span(1) {
|
||||
|
|
@ -218,14 +212,15 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif
|
|||
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "process"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
@ -255,14 +250,12 @@ abstract class AbstractSqsSuppressReceiveSpansTest extends InstrumentationSpecif
|
|||
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import com.amazonaws.services.sqs.AmazonSQSAsyncClientBuilder
|
|||
import com.amazonaws.services.sqs.model.MessageAttributeValue
|
||||
import com.amazonaws.services.sqs.model.ReceiveMessageRequest
|
||||
import com.amazonaws.services.sqs.model.SendMessageRequest
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes
|
||||
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
|
||||
import io.opentelemetry.instrumentation.test.utils.PortUtils
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
|
|
@ -87,14 +88,12 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"rpc.method" "CreateQueue"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -110,18 +109,16 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.method" "SendMessage"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "publish"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
if (testCaptureHeaders) {
|
||||
"messaging.header.test_message_header" { it == ["test"] }
|
||||
}
|
||||
|
|
@ -141,17 +138,15 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
|
|||
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "receive"
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
if (testCaptureHeaders) {
|
||||
"messaging.header.test_message_header" { it == ["test"] }
|
||||
}
|
||||
|
|
@ -169,10 +164,10 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
|
|||
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "process"
|
||||
|
|
@ -180,6 +175,7 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
|
|||
if (testCaptureHeaders) {
|
||||
"messaging.header.test_message_header" { it == ["test"] }
|
||||
}
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
@ -223,14 +219,12 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"rpc.method" "CreateQueue"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -246,18 +240,16 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.method" "SendMessage"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "publish"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
}
|
||||
}
|
||||
publishSpan = span(0)
|
||||
|
|
@ -293,14 +285,12 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
|
|||
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
@ -314,17 +304,15 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
|
|||
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "receive"
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
}
|
||||
}
|
||||
span(3) {
|
||||
|
|
@ -339,14 +327,15 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
|
|||
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "AmazonSQS"
|
||||
"http.method" "POST"
|
||||
"http.url" "http://localhost:$sqsPort"
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.URL_FULL" "http://localhost:$sqsPort"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "process"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
span(4) {
|
||||
|
|
|
|||
|
|
@ -133,13 +133,11 @@ abstract class AbstractAws2ClientCoreTest extends InstrumentationSpecification {
|
|||
kind CLIENT
|
||||
hasNoParent()
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_PEER_NAME" "127.0.0.1"
|
||||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.HTTP_URL" { it.startsWith("${server.httpUri()}${path}") }
|
||||
"$SemanticAttributes.HTTP_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" 200
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "127.0.0.1"
|
||||
"$SemanticAttributes.SERVER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("${server.httpUri()}${path}") }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" "DynamoDb"
|
||||
"$SemanticAttributes.RPC_METHOD" "CreateTable"
|
||||
|
|
@ -168,13 +166,11 @@ abstract class AbstractAws2ClientCoreTest extends InstrumentationSpecification {
|
|||
kind CLIENT
|
||||
hasNoParent()
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_PEER_NAME" "127.0.0.1"
|
||||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.HTTP_URL" { it.startsWith("${server.httpUri()}${path}") }
|
||||
"$SemanticAttributes.HTTP_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" 200
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "127.0.0.1"
|
||||
"$SemanticAttributes.SERVER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("${server.httpUri()}${path}") }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" "DynamoDb"
|
||||
"$SemanticAttributes.RPC_METHOD" "Query"
|
||||
|
|
@ -202,13 +198,11 @@ abstract class AbstractAws2ClientCoreTest extends InstrumentationSpecification {
|
|||
kind CLIENT
|
||||
hasNoParent()
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_PEER_NAME" "127.0.0.1"
|
||||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.HTTP_URL" { it.startsWith("${server.httpUri()}${path}") }
|
||||
"$SemanticAttributes.HTTP_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" 200
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "127.0.0.1"
|
||||
"$SemanticAttributes.SERVER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("${server.httpUri()}${path}") }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" "$service"
|
||||
"$SemanticAttributes.RPC_METHOD" "${operation}"
|
||||
|
|
|
|||
|
|
@ -116,17 +116,15 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest {
|
|||
// the bucket name is a valid DNS label, even in the case that we are using an endpoint override.
|
||||
// Previously the sdk was only doing that if endpoint had "s3" as label in the FQDN.
|
||||
// Our test assert both cases so that we don't need to know what version is being tested.
|
||||
"$SemanticAttributes.NET_PEER_NAME" { it == "somebucket.localhost" || it == "localhost" }
|
||||
"$SemanticAttributes.HTTP_URL" { it.startsWith("http://somebucket.localhost:${server.httpPort()}") || it.startsWith("http://localhost:${server.httpPort()}/somebucket") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" { it == "somebucket.localhost" || it == "localhost" }
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://somebucket.localhost:${server.httpPort()}") || it.startsWith("http://localhost:${server.httpPort()}/somebucket") }
|
||||
} else {
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.HTTP_URL" { it.startsWith("http://localhost:${server.httpPort()}") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:${server.httpPort()}") }
|
||||
}
|
||||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.HTTP_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" 200
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.SERVER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" "$service"
|
||||
"$SemanticAttributes.RPC_METHOD" "${operation}"
|
||||
|
|
@ -256,17 +254,15 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest {
|
|||
// the bucket name is a valid DNS label, even in the case that we are using an endpoint override.
|
||||
// Previously the sdk was only doing that if endpoint had "s3" as label in the FQDN.
|
||||
// Our test assert both cases so that we don't need to know what version is being tested.
|
||||
"$SemanticAttributes.NET_PEER_NAME" { it == "somebucket.localhost" || it == "localhost" }
|
||||
"$SemanticAttributes.HTTP_URL" { it.startsWith("http://somebucket.localhost:${server.httpPort()}") || it.startsWith("http://localhost:${server.httpPort()}") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" { it == "somebucket.localhost" || it == "localhost" }
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://somebucket.localhost:${server.httpPort()}") || it.startsWith("http://localhost:${server.httpPort()}") }
|
||||
} else {
|
||||
"$SemanticAttributes.NET_PEER_NAME" "localhost"
|
||||
"$SemanticAttributes.HTTP_URL" { it == "http://localhost:${server.httpPort()}" || it == "http://localhost:${server.httpPort()}/" }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.URL_FULL" { it == "http://localhost:${server.httpPort()}" || it == "http://localhost:${server.httpPort()}/" }
|
||||
}
|
||||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.HTTP_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" 200
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.SERVER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "$method"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" "$service"
|
||||
"$SemanticAttributes.RPC_METHOD" "${operation}"
|
||||
|
|
@ -424,10 +420,10 @@ abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest {
|
|||
// the bucket name is a valid DNS label, even in the case that we are using an endpoint override.
|
||||
// Previously the sdk was only doing that if endpoint had "s3" as label in the FQDN.
|
||||
// Our test assert both cases so that we don't need to know what version is being tested.
|
||||
"$SemanticAttributes.NET_PEER_NAME" { it == "somebucket.localhost" || it == "localhost" }
|
||||
"$SemanticAttributes.HTTP_URL" { it == "http://somebucket.localhost:${server.httpPort()}/somekey" || it == "http://localhost:${server.httpPort()}/somebucket/somekey" }
|
||||
"$SemanticAttributes.NET_PEER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" { it == "somebucket.localhost" || it == "localhost" }
|
||||
"$SemanticAttributes.URL_FULL" { it == "http://somebucket.localhost:${server.httpPort()}/somekey" || it == "http://localhost:${server.httpPort()}/somebucket/somekey" }
|
||||
"$SemanticAttributes.SERVER_PORT" server.httpPort()
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "GET"
|
||||
"$SemanticAttributes.RPC_SYSTEM" "aws-api"
|
||||
"$SemanticAttributes.RPC_SERVICE" "S3"
|
||||
"$SemanticAttributes.RPC_METHOD" "GetObject"
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
package io.opentelemetry.instrumentation.awssdk.v2_2
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes
|
||||
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
import org.elasticmq.rest.sqs.SQSRestServerBuilder
|
||||
|
|
@ -129,13 +130,11 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Sqs"
|
||||
"rpc.method" "CreateQueue"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -151,17 +150,15 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.method" "SendMessage"
|
||||
"rpc.service" "Sqs"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "publish"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
}
|
||||
}
|
||||
span(1) {
|
||||
|
|
@ -174,15 +171,15 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp
|
|||
"rpc.method" "ReceiveMessage"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Sqs"
|
||||
"http.method" "POST"
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "process"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
span(2) {
|
||||
|
|
@ -214,13 +211,11 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp
|
|||
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Sqs"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -327,16 +322,14 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.method" "SendMessageBatch"
|
||||
"rpc.service" "Sqs"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "publish"
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
}
|
||||
}
|
||||
for (int i: 1..(xrayInjectionEnabled ? 3 : 2)) {
|
||||
|
|
@ -351,15 +344,15 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp
|
|||
"rpc.method" "ReceiveMessage"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Sqs"
|
||||
"http.method" "POST"
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "process"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -379,15 +372,15 @@ abstract class AbstractAws2SqsSuppressReceiveSpansTest extends InstrumentationSp
|
|||
"rpc.method" "ReceiveMessage"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Sqs"
|
||||
"http.method" "POST"
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "process"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
package io.opentelemetry.instrumentation.awssdk.v2_2
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes
|
||||
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
|
|
@ -131,13 +132,11 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Sqs"
|
||||
"rpc.method" "CreateQueue"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -153,17 +152,15 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.method" "SendMessage"
|
||||
"rpc.service" "Sqs"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "publish"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
if (captureHeaders) {
|
||||
"messaging.header.test_message_header" { it == ["test"] }
|
||||
}
|
||||
|
|
@ -194,13 +191,11 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
|
|||
"aws.queue.url" "http://localhost:$sqsPort/000000000000/testSdkSqs"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Sqs"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -218,16 +213,14 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
|
|||
"rpc.method" "ReceiveMessage"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Sqs"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "receive"
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
if (captureHeaders) {
|
||||
"messaging.header.test_message_header" { it == ["test"] }
|
||||
}
|
||||
|
|
@ -243,18 +236,18 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
|
|||
"rpc.method" "ReceiveMessage"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Sqs"
|
||||
"http.method" "POST"
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "process"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
if (captureHeaders) {
|
||||
"messaging.header.test_message_header" { it == ["test"] }
|
||||
}
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
span(2 + offset) {
|
||||
|
|
@ -393,16 +386,14 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
|
|||
"rpc.system" "aws-api"
|
||||
"rpc.method" "SendMessageBatch"
|
||||
"rpc.service" "Sqs"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "publish"
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
}
|
||||
}
|
||||
publishSpan = span(0)
|
||||
|
|
@ -419,16 +410,14 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
|
|||
"rpc.method" "ReceiveMessage"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Sqs"
|
||||
"http.method" "POST"
|
||||
"http.status_code" 200
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" 200
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "receive"
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
}
|
||||
}
|
||||
if (!xrayInjectionEnabled) {
|
||||
|
|
@ -459,15 +448,15 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {
|
|||
"rpc.method" "ReceiveMessage"
|
||||
"rpc.system" "aws-api"
|
||||
"rpc.service" "Sqs"
|
||||
"http.method" "POST"
|
||||
"http.url" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"net.peer.name" "localhost"
|
||||
"net.peer.port" sqsPort
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "POST"
|
||||
"$SemanticAttributes.URL_FULL" { it.startsWith("http://localhost:$sqsPort") }
|
||||
"$SemanticAttributes.SERVER_ADDRESS" "localhost"
|
||||
"$SemanticAttributes.SERVER_PORT" sqsPort
|
||||
"$SemanticAttributes.MESSAGING_SYSTEM" "AmazonSQS"
|
||||
"$SemanticAttributes.MESSAGING_DESTINATION_NAME" "testSdkSqs"
|
||||
"$SemanticAttributes.MESSAGING_OPERATION" "process"
|
||||
"$SemanticAttributes.MESSAGING_MESSAGE_ID" String
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
span(1 + 2*i + 1) {
|
||||
|
|
|
|||
|
|
@ -163,10 +163,10 @@ public abstract class AbstractAws2ClientRecordHttpErrorTest {
|
|||
span.hasAttributesSatisfying(
|
||||
attributes -> {
|
||||
assertThat(attributes)
|
||||
.containsEntry(SemanticAttributes.NET_PEER_NAME, "127.0.0.1")
|
||||
.containsEntry(SemanticAttributes.NET_PEER_PORT, server.httpPort())
|
||||
.containsEntry(SemanticAttributes.HTTP_METHOD, method)
|
||||
.containsEntry(SemanticAttributes.HTTP_STATUS_CODE, 200)
|
||||
.containsEntry(SemanticAttributes.SERVER_ADDRESS, "127.0.0.1")
|
||||
.containsEntry(SemanticAttributes.SERVER_PORT, server.httpPort())
|
||||
.containsEntry(SemanticAttributes.HTTP_REQUEST_METHOD, method)
|
||||
.containsEntry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200)
|
||||
.containsEntry(SemanticAttributes.RPC_SYSTEM, "aws-api")
|
||||
.containsEntry(SemanticAttributes.RPC_SERVICE, service)
|
||||
.containsEntry(SemanticAttributes.RPC_METHOD, operation)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
package io.opentelemetry.instrumentation.awssdk.v2_2;
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.HTTP_URL;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.URL_FULL;
|
||||
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||
|
|
@ -55,7 +55,6 @@ public abstract class AbstractQueryProtocolModelTest {
|
|||
protected abstract InstrumentationExtension getTesting();
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
void testClientWithQueryProtocolModel() {
|
||||
server.enqueue(
|
||||
HttpResponse.of(
|
||||
|
|
@ -95,7 +94,7 @@ public abstract class AbstractQueryProtocolModelTest {
|
|||
attributes -> {
|
||||
assertThat(attributes)
|
||||
.hasEntrySatisfying(
|
||||
HTTP_URL,
|
||||
URL_FULL,
|
||||
entry -> {
|
||||
assertThat(entry)
|
||||
.satisfies(
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import io.opentelemetry.api.common.AttributesBuilder;
|
|||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerRoute;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerRouteSource;
|
||||
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
|
||||
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
|
||||
import io.opentelemetry.javaagent.instrumentation.apachecamel.CamelDirection;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
|
|
@ -89,7 +88,6 @@ class HttpSpanDecorator extends BaseSpanDecorator {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
public void pre(
|
||||
AttributesBuilder attributes,
|
||||
Exchange exchange,
|
||||
|
|
@ -97,28 +95,14 @@ class HttpSpanDecorator extends BaseSpanDecorator {
|
|||
CamelDirection camelDirection) {
|
||||
super.pre(attributes, exchange, endpoint, camelDirection);
|
||||
|
||||
String httpUrl = getHttpUrl(exchange, endpoint);
|
||||
if (httpUrl != null) {
|
||||
if (SemconvStability.emitStableHttpSemconv()) {
|
||||
internalSet(attributes, SemanticAttributes.URL_FULL, httpUrl);
|
||||
}
|
||||
|
||||
if (SemconvStability.emitOldHttpSemconv()) {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_URL, httpUrl);
|
||||
}
|
||||
}
|
||||
internalSet(attributes, SemanticAttributes.URL_FULL, getHttpUrl(exchange, endpoint));
|
||||
|
||||
String method = getHttpMethod(exchange, endpoint);
|
||||
if (SemconvStability.emitStableHttpSemconv()) {
|
||||
if (method == null || knownMethods.contains(method)) {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method);
|
||||
} else {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER);
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method);
|
||||
}
|
||||
}
|
||||
if (SemconvStability.emitOldHttpSemconv()) {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_METHOD, method);
|
||||
if (method == null || knownMethods.contains(method)) {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method);
|
||||
} else {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER);
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -175,19 +159,13 @@ class HttpSpanDecorator extends BaseSpanDecorator {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
public void post(AttributesBuilder attributes, Exchange exchange, Endpoint endpoint) {
|
||||
super.post(attributes, exchange, endpoint);
|
||||
|
||||
if (exchange.hasOut()) {
|
||||
Object responseCode = exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE);
|
||||
if (responseCode instanceof Integer) {
|
||||
if (SemconvStability.emitStableHttpSemconv()) {
|
||||
attributes.put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, (Integer) responseCode);
|
||||
}
|
||||
if (SemconvStability.emitOldHttpSemconv()) {
|
||||
attributes.put(SemanticAttributes.HTTP_STATUS_CODE, (Integer) responseCode);
|
||||
}
|
||||
attributes.put(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, (Integer) responseCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satis
|
|||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerUsingTest;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
|
||||
|
|
@ -61,7 +62,6 @@ class RestCamelTest extends AbstractHttpServerUsingTest<ConfigurableApplicationC
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
void restComponentServerAndClientCallWithJettyBackend() {
|
||||
CamelContext camelContext = appContext.getBean(CamelContext.class);
|
||||
ProducerTemplate template = camelContext.createProducerTemplate();
|
||||
|
|
@ -91,42 +91,36 @@ class RestCamelTest extends AbstractHttpServerUsingTest<ConfigurableApplicationC
|
|||
equalTo(
|
||||
stringKey("camel.uri"),
|
||||
"rest://get:api/%7Bmodule%7D/unit/%7BunitId%7D"),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L)),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)),
|
||||
span ->
|
||||
span.hasName("GET /api/{module}/unit/{unitId}")
|
||||
.hasKind(SpanKind.SERVER)
|
||||
.hasParent(trace.getSpan(1))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.HTTP_SCHEME, "http"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_TARGET, "/api/firstModule/unit/unitOne"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.URL_SCHEME, "http"),
|
||||
equalTo(SemanticAttributes.URL_PATH, "/api/firstModule/unit/unitOne"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_ROUTE, "/api/{module}/unit/{unitId}"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, Long.valueOf(port)),
|
||||
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1"),
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, Long.valueOf(port)),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.USER_AGENT_ORIGINAL,
|
||||
val -> val.isInstanceOf(String.class)),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_PORT,
|
||||
val -> val.isInstanceOf(Long.class)),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_HOST_PORT,
|
||||
NetworkAttributes.NETWORK_PEER_PORT,
|
||||
val -> val.isInstanceOf(Long.class))),
|
||||
span ->
|
||||
span.hasName("GET /api/{module}/unit/{unitId}")
|
||||
.hasKind(SpanKind.INTERNAL)
|
||||
.hasParent(trace.getSpan(2))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL,
|
||||
SemanticAttributes.URL_FULL,
|
||||
"http://localhost:" + port + "/api/firstModule/unit/unitOne"),
|
||||
satisfies(
|
||||
stringKey("camel.uri"), val -> val.isInstanceOf(String.class))),
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ class SingleServiceCamelTest extends AbstractHttpServerUsingTest<ConfigurableApp
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
public void singleCamelServiceSpan() {
|
||||
URI requestUrl = address.resolve("/camelService");
|
||||
|
||||
|
|
@ -69,8 +68,8 @@ class SingleServiceCamelTest extends AbstractHttpServerUsingTest<ConfigurableApp
|
|||
span.hasName("POST /camelService")
|
||||
.hasKind(SpanKind.SERVER)
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "POST"),
|
||||
equalTo(SemanticAttributes.HTTP_URL, requestUrl.toString()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||
equalTo(SemanticAttributes.URL_FULL, requestUrl.toString()),
|
||||
equalTo(
|
||||
stringKey("camel.uri"),
|
||||
requestUrl.toString().replace("localhost", "0.0.0.0")))));
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satis
|
|||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.instrumentation.test.utils.PortUtils;
|
||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerUsingTest;
|
||||
|
|
@ -85,7 +86,6 @@ class TwoServicesWithDirectClientCamelTest
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
void twoCamelServiceSpans() throws Exception {
|
||||
createAndStartClient();
|
||||
|
||||
|
|
@ -107,11 +107,11 @@ class TwoServicesWithDirectClientCamelTest
|
|||
.hasKind(SpanKind.CLIENT)
|
||||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "POST"),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL,
|
||||
SemanticAttributes.URL_FULL,
|
||||
"http://localhost:" + portOne + "/serviceOne"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L),
|
||||
equalTo(
|
||||
stringKey("camel.uri"),
|
||||
"http://localhost:" + portOne + "/serviceOne")),
|
||||
|
|
@ -120,11 +120,11 @@ class TwoServicesWithDirectClientCamelTest
|
|||
.hasKind(SpanKind.SERVER)
|
||||
.hasParent(trace.getSpan(1))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "POST"),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL,
|
||||
SemanticAttributes.URL_FULL,
|
||||
"http://localhost:" + portOne + "/serviceOne"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L),
|
||||
equalTo(
|
||||
stringKey("camel.uri"),
|
||||
"http://0.0.0.0:" + portOne + "/serviceOne")),
|
||||
|
|
@ -133,11 +133,11 @@ class TwoServicesWithDirectClientCamelTest
|
|||
.hasKind(SpanKind.CLIENT)
|
||||
.hasParent(trace.getSpan(2))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "POST"),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL,
|
||||
SemanticAttributes.URL_FULL,
|
||||
"http://127.0.0.1:" + portTwo + "/serviceTwo"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L),
|
||||
equalTo(
|
||||
stringKey("camel.uri"),
|
||||
"http://127.0.0.1:" + portTwo + "/serviceTwo")),
|
||||
|
|
@ -146,37 +146,29 @@ class TwoServicesWithDirectClientCamelTest
|
|||
.hasKind(SpanKind.SERVER)
|
||||
.hasParent(trace.getSpan(3))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "POST"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L),
|
||||
equalTo(SemanticAttributes.HTTP_SCHEME, "http"),
|
||||
equalTo(SemanticAttributes.HTTP_TARGET, "/serviceTwo"),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L),
|
||||
equalTo(SemanticAttributes.URL_SCHEME, "http"),
|
||||
equalTo(SemanticAttributes.URL_PATH, "/serviceTwo"),
|
||||
equalTo(
|
||||
SemanticAttributes.USER_AGENT_ORIGINAL,
|
||||
"Jakarta Commons-HttpClient/3.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH,
|
||||
val -> val.isInstanceOf(Long.class)),
|
||||
equalTo(SemanticAttributes.HTTP_ROUTE, "/serviceTwo"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "127.0.0.1"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, portTwo),
|
||||
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "127.0.0.1"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, portTwo),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_PORT,
|
||||
val -> val.isInstanceOf(Long.class)),
|
||||
equalTo(SemanticAttributes.NET_SOCK_HOST_ADDR, "127.0.0.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_HOST_PORT,
|
||||
NetworkAttributes.NETWORK_PEER_PORT,
|
||||
val -> val.isInstanceOf(Long.class))),
|
||||
span ->
|
||||
span.hasName("POST /serviceTwo")
|
||||
.hasKind(SpanKind.INTERNAL)
|
||||
.hasParent(trace.getSpan(4))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "POST"),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL,
|
||||
SemanticAttributes.URL_FULL,
|
||||
"http://127.0.0.1:" + portTwo + "/serviceTwo"),
|
||||
equalTo(
|
||||
stringKey("camel.uri"),
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.apachecamel.aws;
|
||||
|
||||
import static io.opentelemetry.api.common.AttributeKey.longKey;
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||
import static io.opentelemetry.api.trace.SpanKind.CLIENT;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||
|
|
@ -13,6 +12,7 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satis
|
|||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
||||
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
|
||||
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
|
|
@ -37,7 +37,6 @@ class AwsSpanAssertions {
|
|||
return sqs(span, spanName, queueUrl, queueName, CLIENT);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
static SpanDataAssert sqs(
|
||||
SpanDataAssert span, String spanName, String queueUrl, String queueName, SpanKind spanKind) {
|
||||
|
||||
|
|
@ -67,18 +66,13 @@ class AwsSpanAssertions {
|
|||
val ->
|
||||
val.satisfiesAnyOf(
|
||||
v -> assertThat(v).isEqualTo(queueUrl), v -> assertThat(v).isNull())),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "POST"),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||
satisfies(SemanticAttributes.URL_FULL, val -> val.isInstanceOf(String.class)),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH,
|
||||
val ->
|
||||
val.satisfiesAnyOf(
|
||||
v -> assertThat(v).isNull(), v -> assertThat(v).isInstanceOf(Long.class))),
|
||||
satisfies(SemanticAttributes.HTTP_URL, val -> val.isInstanceOf(String.class)),
|
||||
satisfies(
|
||||
stringKey("net.peer.name"),
|
||||
SemanticAttributes.SERVER_ADDRESS,
|
||||
stringAssert -> stringAssert.isInstanceOf(String.class)),
|
||||
satisfies(
|
||||
longKey("net.peer.port"),
|
||||
SemanticAttributes.SERVER_PORT,
|
||||
val ->
|
||||
val.satisfiesAnyOf(
|
||||
v -> assertThat(v).isNull(),
|
||||
|
|
@ -90,15 +84,8 @@ class AwsSpanAssertions {
|
|||
if (!spanName.endsWith("process")) {
|
||||
attributeAssertions.addAll(
|
||||
Arrays.asList(
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
val ->
|
||||
val.satisfiesAnyOf(
|
||||
v -> assertThat(v).isNull(),
|
||||
v -> assertThat(v).isInstanceOf(Long.class))),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1")));
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1")));
|
||||
}
|
||||
if (spanName.endsWith("receive")
|
||||
|| spanName.endsWith("process")
|
||||
|
|
@ -113,6 +100,7 @@ class AwsSpanAssertions {
|
|||
attributeAssertions.add(equalTo(SemanticAttributes.MESSAGING_OPERATION, "process"));
|
||||
attributeAssertions.add(
|
||||
satisfies(SemanticAttributes.MESSAGING_MESSAGE_ID, val -> assertThat(val).isNotNull()));
|
||||
attributeAssertions.add(equalTo(HttpAttributes.ERROR_TYPE, "_OTHER"));
|
||||
} else if (spanName.endsWith("publish")) {
|
||||
attributeAssertions.add(equalTo(SemanticAttributes.MESSAGING_OPERATION, "publish"));
|
||||
attributeAssertions.add(
|
||||
|
|
@ -125,7 +113,6 @@ class AwsSpanAssertions {
|
|||
.hasAttributesSatisfyingExactly(attributeAssertions);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
static SpanDataAssert s3(SpanDataAssert span, String spanName, String bucketName, String method) {
|
||||
return span.hasName(spanName)
|
||||
.hasAttributesSatisfyingExactly(
|
||||
|
|
@ -135,25 +122,18 @@ class AwsSpanAssertions {
|
|||
equalTo(stringKey("rpc.method"), spanName.substring(3)),
|
||||
equalTo(stringKey("rpc.service"), "Amazon S3"),
|
||||
equalTo(stringKey("aws.bucket.name"), bucketName),
|
||||
equalTo(stringKey("http.method"), method),
|
||||
equalTo(longKey("http.status_code"), 200),
|
||||
satisfies(stringKey("http.url"), val -> val.isInstanceOf(String.class)),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
satisfies(stringKey("net.peer.name"), val -> val.isInstanceOf(String.class)),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, method),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
|
||||
satisfies(SemanticAttributes.URL_FULL, val -> val.isInstanceOf(String.class)),
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
satisfies(SemanticAttributes.SERVER_ADDRESS, val -> val.isInstanceOf(String.class)),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
val ->
|
||||
val.satisfiesAnyOf(
|
||||
v -> assertThat(v).isNull(), v -> assertThat(v).isInstanceOf(Long.class))),
|
||||
satisfies(
|
||||
stringKey("net.peer.port"),
|
||||
SemanticAttributes.SERVER_PORT,
|
||||
val ->
|
||||
val.satisfiesAnyOf(
|
||||
v -> val.isInstanceOf(Number.class), v -> assertThat(v).isNull())));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
static SpanDataAssert sns(SpanDataAssert span, String spanName) {
|
||||
return span.hasName(spanName)
|
||||
.hasKind(CLIENT)
|
||||
|
|
@ -163,21 +143,15 @@ class AwsSpanAssertions {
|
|||
equalTo(stringKey("rpc.system"), "aws-api"),
|
||||
equalTo(stringKey("rpc.method"), spanName.substring(4)),
|
||||
equalTo(stringKey("rpc.service"), "AmazonSNS"),
|
||||
equalTo(stringKey("http.method"), "POST"),
|
||||
equalTo(longKey("http.status_code"), 200),
|
||||
satisfies(stringKey("http.url"), val -> val.isInstanceOf(String.class)),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
satisfies(stringKey("net.peer.name"), val -> val.isInstanceOf(String.class)),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200),
|
||||
satisfies(SemanticAttributes.URL_FULL, val -> val.isInstanceOf(String.class)),
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
satisfies(SemanticAttributes.SERVER_ADDRESS, val -> val.isInstanceOf(String.class)),
|
||||
satisfies(
|
||||
stringKey("net.peer.port"),
|
||||
SemanticAttributes.SERVER_PORT,
|
||||
val ->
|
||||
val.satisfiesAnyOf(
|
||||
v -> val.isInstanceOf(Number.class), v -> assertThat(v).isNull())),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
val ->
|
||||
val.satisfiesAnyOf(
|
||||
v -> assertThat(v).isNull(), v -> assertThat(v).isInstanceOf(Long.class))));
|
||||
v -> val.isInstanceOf(Number.class), v -> assertThat(v).isNull())));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,22 +4,16 @@
|
|||
*/
|
||||
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.DB_CASSANDRA_TABLE;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.DB_NAME;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.DB_OPERATION;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.DB_STATEMENT;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.DB_SYSTEM;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_ADDR;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_NAME;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_PORT;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.ResultSetFuture;
|
||||
import com.datastax.driver.core.Session;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.Executor;
|
||||
|
|
@ -37,7 +31,6 @@ import org.slf4j.LoggerFactory;
|
|||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.output.Slf4jLogConsumer;
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
public class CassandraClientTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CassandraClientTest.class);
|
||||
|
|
@ -92,11 +85,12 @@ public class CassandraClientTest {
|
|||
.hasKind(SpanKind.CLIENT)
|
||||
.hasNoParent()
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(NET_SOCK_PEER_NAME, "localhost"),
|
||||
equalTo(NET_SOCK_PEER_PORT, cassandraPort),
|
||||
equalTo(DB_SYSTEM, "cassandra"),
|
||||
equalTo(DB_STATEMENT, "USE " + parameter.keyspace))),
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort),
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "cassandra"),
|
||||
equalTo(
|
||||
SemanticAttributes.DB_STATEMENT, "USE " + parameter.keyspace))),
|
||||
trace ->
|
||||
trace.hasSpansSatisfyingExactly(
|
||||
span ->
|
||||
|
|
@ -104,14 +98,14 @@ public class CassandraClientTest {
|
|||
.hasKind(SpanKind.CLIENT)
|
||||
.hasNoParent()
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(NET_SOCK_PEER_NAME, "localhost"),
|
||||
equalTo(NET_SOCK_PEER_PORT, cassandraPort),
|
||||
equalTo(DB_SYSTEM, "cassandra"),
|
||||
equalTo(DB_NAME, parameter.keyspace),
|
||||
equalTo(DB_STATEMENT, parameter.expectedStatement),
|
||||
equalTo(DB_OPERATION, parameter.operation),
|
||||
equalTo(DB_CASSANDRA_TABLE, parameter.table))));
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort),
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "cassandra"),
|
||||
equalTo(SemanticAttributes.DB_NAME, parameter.keyspace),
|
||||
equalTo(SemanticAttributes.DB_STATEMENT, parameter.expectedStatement),
|
||||
equalTo(SemanticAttributes.DB_OPERATION, parameter.operation),
|
||||
equalTo(SemanticAttributes.DB_CASSANDRA_TABLE, parameter.table))));
|
||||
} else {
|
||||
testing.waitAndAssertTraces(
|
||||
trace ->
|
||||
|
|
@ -121,13 +115,13 @@ public class CassandraClientTest {
|
|||
.hasKind(SpanKind.CLIENT)
|
||||
.hasNoParent()
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(NET_SOCK_PEER_NAME, "localhost"),
|
||||
equalTo(NET_SOCK_PEER_PORT, cassandraPort),
|
||||
equalTo(DB_SYSTEM, "cassandra"),
|
||||
equalTo(DB_STATEMENT, parameter.expectedStatement),
|
||||
equalTo(DB_OPERATION, parameter.operation),
|
||||
equalTo(DB_CASSANDRA_TABLE, parameter.table))));
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort),
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "cassandra"),
|
||||
equalTo(SemanticAttributes.DB_STATEMENT, parameter.expectedStatement),
|
||||
equalTo(SemanticAttributes.DB_OPERATION, parameter.operation),
|
||||
equalTo(SemanticAttributes.DB_CASSANDRA_TABLE, parameter.table))));
|
||||
}
|
||||
|
||||
session.close();
|
||||
|
|
@ -158,11 +152,12 @@ public class CassandraClientTest {
|
|||
.hasKind(SpanKind.CLIENT)
|
||||
.hasNoParent()
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(NET_SOCK_PEER_NAME, "localhost"),
|
||||
equalTo(NET_SOCK_PEER_PORT, cassandraPort),
|
||||
equalTo(DB_SYSTEM, "cassandra"),
|
||||
equalTo(DB_STATEMENT, "USE " + parameter.keyspace))),
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort),
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "cassandra"),
|
||||
equalTo(
|
||||
SemanticAttributes.DB_STATEMENT, "USE " + parameter.keyspace))),
|
||||
trace ->
|
||||
trace.hasSpansSatisfyingExactly(
|
||||
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(),
|
||||
|
|
@ -171,14 +166,14 @@ public class CassandraClientTest {
|
|||
.hasKind(SpanKind.CLIENT)
|
||||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(NET_SOCK_PEER_NAME, "localhost"),
|
||||
equalTo(NET_SOCK_PEER_PORT, cassandraPort),
|
||||
equalTo(DB_SYSTEM, "cassandra"),
|
||||
equalTo(DB_NAME, parameter.keyspace),
|
||||
equalTo(DB_STATEMENT, parameter.expectedStatement),
|
||||
equalTo(DB_OPERATION, parameter.operation),
|
||||
equalTo(DB_CASSANDRA_TABLE, parameter.table)),
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort),
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "cassandra"),
|
||||
equalTo(SemanticAttributes.DB_NAME, parameter.keyspace),
|
||||
equalTo(SemanticAttributes.DB_STATEMENT, parameter.expectedStatement),
|
||||
equalTo(SemanticAttributes.DB_OPERATION, parameter.operation),
|
||||
equalTo(SemanticAttributes.DB_CASSANDRA_TABLE, parameter.table)),
|
||||
span ->
|
||||
span.hasName("callbackListener")
|
||||
.hasKind(SpanKind.INTERNAL)
|
||||
|
|
@ -193,13 +188,13 @@ public class CassandraClientTest {
|
|||
.hasKind(SpanKind.CLIENT)
|
||||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(NET_SOCK_PEER_NAME, "localhost"),
|
||||
equalTo(NET_SOCK_PEER_PORT, cassandraPort),
|
||||
equalTo(DB_SYSTEM, "cassandra"),
|
||||
equalTo(DB_STATEMENT, parameter.expectedStatement),
|
||||
equalTo(DB_OPERATION, parameter.operation),
|
||||
equalTo(DB_CASSANDRA_TABLE, parameter.table)),
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort),
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "cassandra"),
|
||||
equalTo(SemanticAttributes.DB_STATEMENT, parameter.expectedStatement),
|
||||
equalTo(SemanticAttributes.DB_OPERATION, parameter.operation),
|
||||
equalTo(SemanticAttributes.DB_CASSANDRA_TABLE, parameter.table)),
|
||||
span ->
|
||||
span.hasName("callbackListener")
|
||||
.hasKind(SpanKind.INTERNAL)
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@ import static io.opentelemetry.semconv.SemanticAttributes.DB_NAME;
|
|||
import static io.opentelemetry.semconv.SemanticAttributes.DB_OPERATION;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.DB_STATEMENT;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.DB_SYSTEM;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_ADDR;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_NAME;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_PORT;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_TYPE;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
|
||||
import com.datastax.oss.driver.api.core.CqlSession;
|
||||
|
|
@ -28,6 +26,7 @@ import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
|
|||
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
|
||||
import com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.time.Duration;
|
||||
|
|
@ -42,7 +41,6 @@ import org.slf4j.LoggerFactory;
|
|||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.output.Slf4jLogConsumer;
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
public abstract class AbstractCassandraTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AbstractCassandraTest.class);
|
||||
|
|
@ -92,9 +90,9 @@ public abstract class AbstractCassandraTest {
|
|||
.hasKind(SpanKind.CLIENT)
|
||||
.hasNoParent()
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(NET_SOCK_PEER_NAME, "localhost"),
|
||||
equalTo(NET_SOCK_PEER_PORT, cassandraPort),
|
||||
equalTo(NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort),
|
||||
equalTo(DB_SYSTEM, "cassandra"),
|
||||
equalTo(DB_NAME, parameter.keyspace),
|
||||
equalTo(DB_STATEMENT, parameter.expectedStatement),
|
||||
|
|
@ -139,9 +137,9 @@ public abstract class AbstractCassandraTest {
|
|||
.hasKind(SpanKind.CLIENT)
|
||||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(NET_SOCK_PEER_NAME, "localhost"),
|
||||
equalTo(NET_SOCK_PEER_PORT, cassandraPort),
|
||||
equalTo(NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort),
|
||||
equalTo(DB_SYSTEM, "cassandra"),
|
||||
equalTo(DB_NAME, parameter.keyspace),
|
||||
equalTo(DB_STATEMENT, parameter.expectedStatement),
|
||||
|
|
|
|||
|
|
@ -18,14 +18,13 @@ import static io.opentelemetry.semconv.SemanticAttributes.DB_NAME;
|
|||
import static io.opentelemetry.semconv.SemanticAttributes.DB_OPERATION;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.DB_STATEMENT;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.DB_SYSTEM;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_ADDR;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_NAME;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NET_SOCK_PEER_PORT;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_TYPE;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
|
||||
import com.datastax.oss.driver.api.core.CqlSession;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.cassandra.v4.common.AbstractCassandraTest;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
|
@ -36,7 +35,6 @@ public abstract class AbstractCassandra44Test extends AbstractCassandraTest {
|
|||
|
||||
@ParameterizedTest(name = "{index}: {0}")
|
||||
@MethodSource("provideReactiveParameters")
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
void reactiveTest(Parameter parameter) {
|
||||
CqlSession session = getSession(parameter.keyspace);
|
||||
|
||||
|
|
@ -58,9 +56,9 @@ public abstract class AbstractCassandra44Test extends AbstractCassandraTest {
|
|||
.hasKind(SpanKind.CLIENT)
|
||||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(NET_SOCK_PEER_NAME, "localhost"),
|
||||
equalTo(NET_SOCK_PEER_PORT, cassandraPort),
|
||||
equalTo(NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_PORT, cassandraPort),
|
||||
equalTo(DB_SYSTEM, "cassandra"),
|
||||
equalTo(DB_NAME, parameter.keyspace),
|
||||
equalTo(DB_STATEMENT, parameter.expectedStatement),
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
|
|
@ -34,9 +35,9 @@ class CouchbaseSpanUtil {
|
|||
"$SemanticAttributes.DB_OPERATION"(operation ?: spanName)
|
||||
|
||||
// Because of caching, not all requests hit the server so these attributes may be absent
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_NAME" { it == "localhost" || it == "127.0.0.1" || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" { it == null || it instanceof Number }
|
||||
"$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == null }
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == "127.0.0.1" || it == null }
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" { it instanceof Number || it == null }
|
||||
|
||||
// Because of caching, not all requests hit the server so this tag may be absent
|
||||
"couchbase.local.address" { it == null || it instanceof String }
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import io.dropwizard.setup.Environment
|
|||
import io.dropwizard.testing.ConfigOverride
|
||||
import io.dropwizard.testing.DropwizardTestSupport
|
||||
import io.opentelemetry.api.trace.StatusCode
|
||||
import io.opentelemetry.instrumentation.api.internal.HttpConstants
|
||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
|
|
@ -84,6 +85,9 @@ class DropwizardTest extends HttpServerTest<DropwizardTestSupport> implements Ag
|
|||
|
||||
@Override
|
||||
String expectedHttpRoute(ServerEndpoint endpoint, String method) {
|
||||
if (method == HttpConstants._OTHER) {
|
||||
return getContextPath() + "/*"
|
||||
}
|
||||
switch (endpoint) {
|
||||
case NOT_FOUND:
|
||||
return getContextPath() + "/*"
|
||||
|
|
@ -94,6 +98,11 @@ class DropwizardTest extends HttpServerTest<DropwizardTestSupport> implements Ag
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
int getResponseCodeOnNonStandardHttpMethod() {
|
||||
405
|
||||
}
|
||||
|
||||
@Override
|
||||
void handlerSpan(TraceAssert trace, int index, Object parent, String method = "GET", ServerEndpoint endpoint = SUCCESS) {
|
||||
trace.span(index) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.javaagent.instrumentation.elasticsearch.apiclient;
|
|||
|
||||
import static io.opentelemetry.instrumentation.testing.GlobalTraceUtil.runWithSpan;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
|
||||
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
|
|
@ -24,7 +23,6 @@ import java.io.IOException;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.assertj.core.api.AbstractLongAssert;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
|
@ -33,7 +31,6 @@ import org.junit.jupiter.api.Test;
|
|||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
class ElasticsearchClientTest {
|
||||
@RegisterExtension
|
||||
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
|
||||
|
|
@ -90,25 +87,21 @@ class ElasticsearchClientTest {
|
|||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"),
|
||||
equalTo(SemanticAttributes.DB_OPERATION, "info"),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort())),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.URL_FULL, httpHost.toURI() + "/"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort())),
|
||||
span ->
|
||||
span.hasName("GET")
|
||||
.hasKind(SpanKind.CLIENT)
|
||||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
AbstractLongAssert::isPositive))));
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.URL_FULL, httpHost.toURI() + "/"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L))));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -130,11 +123,11 @@ class ElasticsearchClientTest {
|
|||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"),
|
||||
equalTo(SemanticAttributes.DB_OPERATION, "index"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "PUT"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "PUT"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL,
|
||||
SemanticAttributes.URL_FULL,
|
||||
httpHost.toURI() + "/test-index/_doc/test-id?timeout=10s"),
|
||||
equalTo(
|
||||
AttributeKey.stringKey("db.elasticsearch.path_parts.index"),
|
||||
|
|
@ -147,18 +140,14 @@ class ElasticsearchClientTest {
|
|||
.hasKind(SpanKind.CLIENT)
|
||||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "PUT"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "PUT"),
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL,
|
||||
SemanticAttributes.URL_FULL,
|
||||
httpHost.toURI() + "/test-index/_doc/test-id?timeout=10s"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 201L),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
AbstractLongAssert::isPositive))));
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 201L))));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -195,25 +184,21 @@ class ElasticsearchClientTest {
|
|||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"),
|
||||
equalTo(SemanticAttributes.DB_OPERATION, "info"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/")),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.URL_FULL, httpHost.toURI() + "/")),
|
||||
span ->
|
||||
span.hasName("GET")
|
||||
.hasKind(SpanKind.CLIENT)
|
||||
.hasParent(trace.getSpan(1))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
AbstractLongAssert::isPositive)),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.URL_FULL, httpHost.toURI() + "/"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)),
|
||||
span ->
|
||||
span.hasName("callback")
|
||||
.hasKind(SpanKind.INTERNAL)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import org.junit.jupiter.api.Test;
|
|||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
class ElasticsearchRest5Test {
|
||||
|
||||
@RegisterExtension
|
||||
|
|
@ -94,27 +93,23 @@ class ElasticsearchRest5Test {
|
|||
.hasNoParent()
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"));
|
||||
SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"));
|
||||
},
|
||||
span -> {
|
||||
span.hasName("GET")
|
||||
.hasKind(SpanKind.CLIENT)
|
||||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
response.getEntity().getContentLength()));
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -175,27 +170,23 @@ class ElasticsearchRest5Test {
|
|||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"));
|
||||
SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"));
|
||||
},
|
||||
span -> {
|
||||
span.hasName("GET")
|
||||
.hasKind(SpanKind.CLIENT)
|
||||
.hasParent(trace.getSpan(1))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
requestResponse[0].getEntity().getContentLength()));
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200));
|
||||
},
|
||||
span -> {
|
||||
span.hasName("callback").hasKind(SpanKind.INTERNAL).hasParent(trace.getSpan(0));
|
||||
|
|
|
|||
|
|
@ -84,27 +84,23 @@ class ElasticsearchRest6Test {
|
|||
.hasNoParent()
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"));
|
||||
SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"));
|
||||
},
|
||||
span -> {
|
||||
span.hasName("GET")
|
||||
.hasKind(SpanKind.CLIENT)
|
||||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
response.getEntity().getContentLength()));
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -164,27 +160,23 @@ class ElasticsearchRest6Test {
|
|||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"));
|
||||
SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"));
|
||||
},
|
||||
span -> {
|
||||
span.hasName("GET")
|
||||
.hasKind(SpanKind.CLIENT)
|
||||
.hasParent(trace.getSpan(1))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
requestResponse[0].getEntity().getContentLength()));
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200));
|
||||
},
|
||||
span -> {
|
||||
span.hasName("callback").hasKind(SpanKind.INTERNAL).hasParent(trace.getSpan(0));
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.javaagent.instrumentation.elasticsearch.rest.v7_0;
|
|||
|
||||
import static io.opentelemetry.instrumentation.testing.GlobalTraceUtil.runWithSpan;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
|
||||
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
||||
|
|
@ -17,7 +16,6 @@ import java.util.Map;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.assertj.core.api.AbstractLongAssert;
|
||||
import org.elasticsearch.client.Request;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.ResponseListener;
|
||||
|
|
@ -30,7 +28,6 @@ import org.junit.jupiter.api.extension.RegisterExtension;
|
|||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
class ElasticsearchRest7Test {
|
||||
@RegisterExtension
|
||||
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
|
||||
|
|
@ -85,28 +82,24 @@ class ElasticsearchRest7Test {
|
|||
.hasNoParent()
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL,
|
||||
SemanticAttributes.URL_FULL,
|
||||
httpHost.toURI() + "/_cluster/health")),
|
||||
span ->
|
||||
span.hasName("GET")
|
||||
.hasKind(SpanKind.CLIENT)
|
||||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
AbstractLongAssert::isPositive))));
|
||||
SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L))));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -162,28 +155,24 @@ class ElasticsearchRest7Test {
|
|||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL,
|
||||
SemanticAttributes.URL_FULL,
|
||||
httpHost.toURI() + "/_cluster/health")),
|
||||
span ->
|
||||
span.hasName("GET")
|
||||
.hasKind(SpanKind.CLIENT)
|
||||
.hasParent(trace.getSpan(1))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"),
|
||||
equalTo(SemanticAttributes.NET_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL, httpHost.toURI() + "/_cluster/health"),
|
||||
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200L),
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
AbstractLongAssert::isPositive)),
|
||||
SemanticAttributes.URL_FULL, httpHost.toURI() + "/_cluster/health"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)),
|
||||
span ->
|
||||
span.hasName("callback")
|
||||
.hasKind(SpanKind.INTERNAL)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import org.junit.jupiter.api.extension.RegisterExtension;
|
|||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
class ElasticsearchRest7Test {
|
||||
@RegisterExtension
|
||||
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();
|
||||
|
|
@ -84,11 +83,11 @@ class ElasticsearchRest7Test {
|
|||
.hasNoParent()
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL,
|
||||
SemanticAttributes.URL_FULL,
|
||||
httpHost.toURI() + "/_cluster/health"))));
|
||||
}
|
||||
|
||||
|
|
@ -145,11 +144,11 @@ class ElasticsearchRest7Test {
|
|||
.hasParent(trace.getSpan(0))
|
||||
.hasAttributesSatisfyingExactly(
|
||||
equalTo(SemanticAttributes.DB_SYSTEM, "elasticsearch"),
|
||||
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.NET_PEER_PORT, httpHost.getPort()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, httpHost.getHostName()),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, httpHost.getPort()),
|
||||
equalTo(
|
||||
SemanticAttributes.HTTP_URL,
|
||||
SemanticAttributes.URL_FULL,
|
||||
httpHost.toURI() + "/_cluster/health")),
|
||||
span ->
|
||||
span.hasName("callback")
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import io.opentelemetry.api.common.AttributeKey;
|
|||
import io.opentelemetry.api.common.AttributesBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
|
||||
import io.opentelemetry.instrumentation.api.internal.cache.Cache;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -38,34 +37,20 @@ public class ElasticsearchClientAttributeExtractor
|
|||
this.knownMethods = new HashSet<>(knownMethods);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
private static void setServerAttributes(AttributesBuilder attributes, Response response) {
|
||||
HttpHost host = response.getHost();
|
||||
if (host != null) {
|
||||
if (SemconvStability.emitStableHttpSemconv()) {
|
||||
internalSet(attributes, SemanticAttributes.SERVER_ADDRESS, host.getHostName());
|
||||
internalSet(attributes, SemanticAttributes.SERVER_PORT, (long) host.getPort());
|
||||
}
|
||||
if (SemconvStability.emitOldHttpSemconv()) {
|
||||
internalSet(attributes, SemanticAttributes.NET_PEER_NAME, host.getHostName());
|
||||
internalSet(attributes, SemanticAttributes.NET_PEER_PORT, (long) host.getPort());
|
||||
}
|
||||
internalSet(attributes, SemanticAttributes.SERVER_ADDRESS, host.getHostName());
|
||||
internalSet(attributes, SemanticAttributes.SERVER_PORT, (long) host.getPort());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
private static void setUrlAttribute(AttributesBuilder attributes, Response response) {
|
||||
String uri = response.getRequestLine().getUri();
|
||||
uri = uri.startsWith("/") ? uri : "/" + uri;
|
||||
String fullUrl = response.getHost().toURI() + uri;
|
||||
|
||||
if (SemconvStability.emitStableHttpSemconv()) {
|
||||
internalSet(attributes, SemanticAttributes.URL_FULL, fullUrl);
|
||||
}
|
||||
|
||||
if (SemconvStability.emitOldHttpSemconv()) {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_URL, fullUrl);
|
||||
}
|
||||
internalSet(attributes, SemanticAttributes.URL_FULL, fullUrl);
|
||||
}
|
||||
|
||||
private static void setPathPartsAttributes(
|
||||
|
|
@ -86,20 +71,14 @@ public class ElasticsearchClientAttributeExtractor
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
public void onStart(
|
||||
AttributesBuilder attributes, Context parentContext, ElasticsearchRestRequest request) {
|
||||
String method = request.getMethod();
|
||||
if (SemconvStability.emitStableHttpSemconv()) {
|
||||
if (method == null || knownMethods.contains(method)) {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method);
|
||||
} else {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER);
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method);
|
||||
}
|
||||
}
|
||||
if (SemconvStability.emitOldHttpSemconv()) {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_METHOD, method);
|
||||
if (method == null || knownMethods.contains(method)) {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method);
|
||||
} else {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER);
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method);
|
||||
}
|
||||
setPathPartsAttributes(attributes, request);
|
||||
}
|
||||
|
|
@ -111,8 +90,8 @@ public class ElasticsearchClientAttributeExtractor
|
|||
ElasticsearchRestRequest request,
|
||||
@Nullable Response response,
|
||||
@Nullable Throwable error) {
|
||||
if (response != null) {
|
||||
|
||||
if (response != null) {
|
||||
setUrlAttribute(attributes, response);
|
||||
setServerAttributes(attributes, response);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
import org.elasticsearch.client.transport.TransportClient
|
||||
import org.elasticsearch.common.io.FileSystemUtils
|
||||
|
|
@ -125,9 +126,8 @@ class Elasticsearch5TransportClientTest extends AbstractElasticsearchTransportCl
|
|||
name "ClusterHealthAction"
|
||||
kind CLIENT
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.DB_SYSTEM" "elasticsearch"
|
||||
"$SemanticAttributes.DB_OPERATION" "ClusterHealthAction"
|
||||
"elasticsearch.action" "ClusterHealthAction"
|
||||
|
|
@ -242,9 +242,8 @@ class Elasticsearch5TransportClientTest extends AbstractElasticsearchTransportCl
|
|||
name "CreateIndexAction"
|
||||
kind CLIENT
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.DB_SYSTEM" "elasticsearch"
|
||||
"$SemanticAttributes.DB_OPERATION" "CreateIndexAction"
|
||||
"elasticsearch.action" "CreateIndexAction"
|
||||
|
|
@ -258,9 +257,8 @@ class Elasticsearch5TransportClientTest extends AbstractElasticsearchTransportCl
|
|||
name "GetAction"
|
||||
kind CLIENT
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.DB_SYSTEM" "elasticsearch"
|
||||
"$SemanticAttributes.DB_OPERATION" "GetAction"
|
||||
"elasticsearch.action" "GetAction"
|
||||
|
|
@ -289,9 +287,8 @@ class Elasticsearch5TransportClientTest extends AbstractElasticsearchTransportCl
|
|||
name "IndexAction"
|
||||
kind CLIENT
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.DB_SYSTEM" "elasticsearch"
|
||||
"$SemanticAttributes.DB_OPERATION" "IndexAction"
|
||||
"elasticsearch.action" "IndexAction"
|
||||
|
|
@ -310,9 +307,8 @@ class Elasticsearch5TransportClientTest extends AbstractElasticsearchTransportCl
|
|||
name "GetAction"
|
||||
kind CLIENT
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.DB_SYSTEM" "elasticsearch"
|
||||
"$SemanticAttributes.DB_OPERATION" "GetAction"
|
||||
"elasticsearch.action" "GetAction"
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest
|
||||
import org.elasticsearch.client.transport.TransportClient
|
||||
|
|
@ -131,9 +132,8 @@ class Elasticsearch53TransportClientTest extends AbstractElasticsearchTransportC
|
|||
kind CLIENT
|
||||
childOf(span(0))
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.DB_SYSTEM" "elasticsearch"
|
||||
"$SemanticAttributes.DB_OPERATION" "ClusterHealthAction"
|
||||
"elasticsearch.action" "ClusterHealthAction"
|
||||
|
|
@ -247,9 +247,8 @@ class Elasticsearch53TransportClientTest extends AbstractElasticsearchTransportC
|
|||
name "CreateIndexAction"
|
||||
kind CLIENT
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.DB_SYSTEM" "elasticsearch"
|
||||
"$SemanticAttributes.DB_OPERATION" "CreateIndexAction"
|
||||
"elasticsearch.action" "CreateIndexAction"
|
||||
|
|
@ -263,9 +262,8 @@ class Elasticsearch53TransportClientTest extends AbstractElasticsearchTransportC
|
|||
name "GetAction"
|
||||
kind CLIENT
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.DB_SYSTEM" "elasticsearch"
|
||||
"$SemanticAttributes.DB_OPERATION" "GetAction"
|
||||
"elasticsearch.action" "GetAction"
|
||||
|
|
@ -294,9 +292,8 @@ class Elasticsearch53TransportClientTest extends AbstractElasticsearchTransportC
|
|||
name "IndexAction"
|
||||
kind CLIENT
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.DB_SYSTEM" "elasticsearch"
|
||||
"$SemanticAttributes.DB_OPERATION" "IndexAction"
|
||||
"elasticsearch.action" "IndexAction"
|
||||
|
|
@ -316,9 +313,8 @@ class Elasticsearch53TransportClientTest extends AbstractElasticsearchTransportC
|
|||
name "GetAction"
|
||||
kind CLIENT
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.DB_SYSTEM" "elasticsearch"
|
||||
"$SemanticAttributes.DB_OPERATION" "GetAction"
|
||||
"elasticsearch.action" "GetAction"
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest
|
||||
import org.elasticsearch.client.transport.TransportClient
|
||||
|
|
@ -105,10 +106,9 @@ class Elasticsearch6TransportClientTest extends AbstractElasticsearchTransportCl
|
|||
kind CLIENT
|
||||
childOf(span(0))
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address
|
||||
"$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.address().hostString
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" }
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.DB_SYSTEM" "elasticsearch"
|
||||
"$SemanticAttributes.DB_OPERATION" "ClusterHealthAction"
|
||||
"elasticsearch.action" "ClusterHealthAction"
|
||||
|
|
@ -225,10 +225,9 @@ class Elasticsearch6TransportClientTest extends AbstractElasticsearchTransportCl
|
|||
name "CreateIndexAction"
|
||||
kind CLIENT
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address
|
||||
"$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.address().hostString
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" }
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.DB_SYSTEM" "elasticsearch"
|
||||
"$SemanticAttributes.DB_OPERATION" "CreateIndexAction"
|
||||
"elasticsearch.action" "CreateIndexAction"
|
||||
|
|
@ -242,10 +241,9 @@ class Elasticsearch6TransportClientTest extends AbstractElasticsearchTransportCl
|
|||
name "GetAction"
|
||||
kind CLIENT
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address
|
||||
"$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.address().hostString
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" }
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.DB_SYSTEM" "elasticsearch"
|
||||
"$SemanticAttributes.DB_OPERATION" "GetAction"
|
||||
"elasticsearch.action" "GetAction"
|
||||
|
|
@ -274,10 +272,9 @@ class Elasticsearch6TransportClientTest extends AbstractElasticsearchTransportCl
|
|||
name "IndexAction"
|
||||
kind CLIENT
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address
|
||||
"$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.address().hostString
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" }
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.DB_SYSTEM" "elasticsearch"
|
||||
"$SemanticAttributes.DB_OPERATION" "IndexAction"
|
||||
"elasticsearch.action" "IndexAction"
|
||||
|
|
@ -297,10 +294,9 @@ class Elasticsearch6TransportClientTest extends AbstractElasticsearchTransportCl
|
|||
name "GetAction"
|
||||
kind CLIENT
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_SOCK_FAMILY" { it == SemanticAttributes.NetSockFamilyValues.INET6 || it == null }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" tcpPublishAddress.address
|
||||
"$SemanticAttributes.NET_SOCK_PEER_NAME" tcpPublishAddress.address().hostString
|
||||
"$SemanticAttributes.NET_SOCK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" }
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" tcpPublishAddress.address
|
||||
"$NetworkAttributes.NETWORK_PEER_PORT" tcpPublishAddress.port
|
||||
"$SemanticAttributes.DB_SYSTEM" "elasticsearch"
|
||||
"$SemanticAttributes.DB_OPERATION" "GetAction"
|
||||
"elasticsearch.action" "GetAction"
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ class FinatraServerLatestTest extends AbstractHttpServerTest[HttpServer] {
|
|||
override def test(endpoint: ServerEndpoint): Boolean =
|
||||
endpoint != ServerEndpoint.NOT_FOUND
|
||||
})
|
||||
options.setResponseCodeOnNonStandardHttpMethod(400)
|
||||
}
|
||||
|
||||
override protected def assertHandlerSpan(
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import com.google.api.client.util.ClassInfo;
|
|||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
||||
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,7 +87,6 @@ public abstract class AbstractGoogleHttpClientTest extends AbstractHttpClientTes
|
|||
protected abstract HttpResponse sendRequest(HttpRequest request) throws Exception;
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
void errorTracesWhenExceptionIsNotThrown() throws Exception {
|
||||
URI uri = resolveAddress("/error");
|
||||
|
||||
|
|
@ -100,22 +98,12 @@ public abstract class AbstractGoogleHttpClientTest extends AbstractHttpClientTes
|
|||
List<AttributeAssertion> attributes =
|
||||
new ArrayList<>(
|
||||
Arrays.asList(
|
||||
equalTo(getAttributeKey(SemanticAttributes.NET_PEER_NAME), "localhost"),
|
||||
satisfies(
|
||||
getAttributeKey(SemanticAttributes.NET_PEER_PORT),
|
||||
AbstractLongAssert::isPositive),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_URL), uri.toString()),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_METHOD), "GET"),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_STATUS_CODE), 500)));
|
||||
if (SemconvStability.emitOldHttpSemconv()) {
|
||||
attributes.add(
|
||||
satisfies(
|
||||
getAttributeKey(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH),
|
||||
AbstractLongAssert::isPositive));
|
||||
}
|
||||
if (SemconvStability.emitStableHttpSemconv()) {
|
||||
attributes.add(equalTo(HttpAttributes.ERROR_TYPE, "500"));
|
||||
}
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
satisfies(SemanticAttributes.SERVER_PORT, AbstractLongAssert::isPositive),
|
||||
equalTo(SemanticAttributes.URL_FULL, uri.toString()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 500),
|
||||
equalTo(HttpAttributes.ERROR_TYPE, "500")));
|
||||
|
||||
testing.waitAndAssertTraces(
|
||||
trace ->
|
||||
|
|
@ -128,7 +116,6 @@ public abstract class AbstractGoogleHttpClientTest extends AbstractHttpClientTes
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
protected void configure(HttpClientTestOptions.Builder optionsBuilder) {
|
||||
// executeAsync does not actually allow asynchronous execution since it returns a standard
|
||||
// Future which cannot have callbacks attached. We instrument execute and executeAsync
|
||||
|
|
@ -142,15 +129,12 @@ public abstract class AbstractGoogleHttpClientTest extends AbstractHttpClientTes
|
|||
// can only use supported method
|
||||
optionsBuilder.disableTestNonStandardHttpMethod();
|
||||
|
||||
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.setHttpAttributes(
|
||||
uri -> {
|
||||
Set<AttributeKey<?>> attributes =
|
||||
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
|
||||
attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION);
|
||||
return attributes;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,6 @@ class GrizzlyFilterchainServerTest extends HttpServerTest<HttpServer> implements
|
|||
Set<AttributeKey<?>> httpAttributes(ServerEndpoint endpoint) {
|
||||
def attributes = super.httpAttributes(endpoint)
|
||||
attributes.remove(SemanticAttributes.HTTP_ROUTE)
|
||||
attributes.remove(SemanticAttributes.NET_TRANSPORT)
|
||||
attributes
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@ class GrizzlyTest extends HttpServerTest<HttpServer> implements AgentTestTrait {
|
|||
Set<AttributeKey<?>> httpAttributes(ServerEndpoint endpoint) {
|
||||
def attributes = super.httpAttributes(endpoint)
|
||||
attributes.remove(SemanticAttributes.HTTP_ROUTE)
|
||||
attributes.remove(SemanticAttributes.NET_TRANSPORT)
|
||||
attributes
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import io.grpc.ServerBuilder;
|
|||
import io.grpc.Status;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||
import io.opentelemetry.instrumentation.testing.util.ThrowingRunnable;
|
||||
import io.opentelemetry.sdk.testing.assertj.EventDataAssert;
|
||||
|
|
@ -37,7 +38,6 @@ import java.util.stream.IntStream;
|
|||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junitpioneer.jupiter.cartesian.CartesianTest;
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
public abstract class AbstractGrpcStreamingTest {
|
||||
|
||||
protected abstract ServerBuilder<?> configureServer(ServerBuilder<?> server);
|
||||
|
|
@ -184,9 +184,9 @@ public abstract class AbstractGrpcStreamingTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.OK.value()),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_PORT, (long) server.getPort())))
|
||||
SemanticAttributes.SERVER_PORT, (long) server.getPort())))
|
||||
.hasEventsSatisfyingExactly(events.toArray(new Consumer[0])),
|
||||
span ->
|
||||
span.hasName("example.Greeter/Conversation")
|
||||
|
|
@ -199,14 +199,12 @@ public abstract class AbstractGrpcStreamingTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.OK.value()),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_NAME,
|
||||
val -> assertThat(val).isNotNull()),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_PORT,
|
||||
NetworkAttributes.NETWORK_PEER_PORT,
|
||||
val -> assertThat(val).isNotNull()))
|
||||
.hasEventsSatisfyingExactly(events.toArray(new Consumer[0]))));
|
||||
testing()
|
||||
|
|
@ -224,7 +222,7 @@ public abstract class AbstractGrpcStreamingTest {
|
|||
point ->
|
||||
point.hasAttributesSatisfying(
|
||||
equalTo(
|
||||
SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.RPC_METHOD, "Conversation"),
|
||||
equalTo(
|
||||
|
|
@ -249,9 +247,9 @@ public abstract class AbstractGrpcStreamingTest {
|
|||
point ->
|
||||
point.hasAttributesSatisfying(
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_PORT,
|
||||
SemanticAttributes.SERVER_PORT,
|
||||
server.getPort()),
|
||||
equalTo(
|
||||
SemanticAttributes.RPC_METHOD, "Conversation"),
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import io.grpc.stub.StreamObserver;
|
|||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
|
||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||
import io.opentelemetry.instrumentation.testing.util.ThrowingRunnable;
|
||||
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
|
||||
|
|
@ -73,7 +74,6 @@ import org.junit.jupiter.params.provider.ArgumentsSource;
|
|||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
public abstract class AbstractGrpcTest {
|
||||
protected static final String CLIENT_REQUEST_METADATA_KEY = "some-client-key";
|
||||
|
||||
|
|
@ -140,9 +140,9 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.OK.value()),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_PORT, (long) server.getPort())))
|
||||
SemanticAttributes.SERVER_PORT, (long) server.getPort())))
|
||||
.hasEventsSatisfyingExactly(
|
||||
event ->
|
||||
event
|
||||
|
|
@ -167,14 +167,12 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.OK.value()),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_NAME,
|
||||
val -> assertThat(val).isNotNull()),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_PORT,
|
||||
NetworkAttributes.NETWORK_PEER_PORT,
|
||||
val -> assertThat(val).isNotNull()))
|
||||
.hasEventsSatisfyingExactly(
|
||||
event ->
|
||||
|
|
@ -204,7 +202,7 @@ public abstract class AbstractGrpcTest {
|
|||
point ->
|
||||
point.hasAttributesSatisfying(
|
||||
equalTo(
|
||||
SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
|
||||
equalTo(
|
||||
SemanticAttributes.RPC_SERVICE,
|
||||
|
|
@ -228,9 +226,9 @@ public abstract class AbstractGrpcTest {
|
|||
point ->
|
||||
point.hasAttributesSatisfying(
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_PORT,
|
||||
SemanticAttributes.SERVER_PORT,
|
||||
server.getPort()),
|
||||
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
|
||||
equalTo(
|
||||
|
|
@ -304,9 +302,9 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.OK.value()),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_PORT, (long) server.getPort())))
|
||||
SemanticAttributes.SERVER_PORT, (long) server.getPort())))
|
||||
.hasEventsSatisfyingExactly(
|
||||
event ->
|
||||
event
|
||||
|
|
@ -331,14 +329,12 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.OK.value()),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_NAME,
|
||||
val -> assertThat(val).isNotNull()),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_PORT,
|
||||
NetworkAttributes.NETWORK_PEER_PORT,
|
||||
val -> assertThat(val).isNotNull()))
|
||||
.hasEventsSatisfyingExactly(
|
||||
event ->
|
||||
|
|
@ -372,7 +368,7 @@ public abstract class AbstractGrpcTest {
|
|||
point ->
|
||||
point.hasAttributesSatisfying(
|
||||
equalTo(
|
||||
SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
|
||||
equalTo(
|
||||
SemanticAttributes.RPC_SERVICE,
|
||||
|
|
@ -396,9 +392,9 @@ public abstract class AbstractGrpcTest {
|
|||
point ->
|
||||
point.hasAttributesSatisfying(
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_PORT,
|
||||
SemanticAttributes.SERVER_PORT,
|
||||
server.getPort()),
|
||||
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
|
||||
equalTo(
|
||||
|
|
@ -480,9 +476,9 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.OK.value()),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_PORT, (long) server.getPort())))
|
||||
SemanticAttributes.SERVER_PORT, (long) server.getPort())))
|
||||
.hasEventsSatisfyingExactly(
|
||||
event ->
|
||||
event
|
||||
|
|
@ -507,14 +503,12 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.OK.value()),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_NAME,
|
||||
val -> assertThat(val).isNotNull()),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_PORT,
|
||||
NetworkAttributes.NETWORK_PEER_PORT,
|
||||
val -> assertThat(val).isNotNull()))
|
||||
.hasEventsSatisfyingExactly(
|
||||
event ->
|
||||
|
|
@ -548,7 +542,7 @@ public abstract class AbstractGrpcTest {
|
|||
point ->
|
||||
point.hasAttributesSatisfying(
|
||||
equalTo(
|
||||
SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
|
||||
equalTo(
|
||||
SemanticAttributes.RPC_SERVICE,
|
||||
|
|
@ -572,9 +566,9 @@ public abstract class AbstractGrpcTest {
|
|||
point ->
|
||||
point.hasAttributesSatisfying(
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_PORT,
|
||||
SemanticAttributes.SERVER_PORT,
|
||||
server.getPort()),
|
||||
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
|
||||
equalTo(
|
||||
|
|
@ -631,9 +625,9 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) status.getCode().value()),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_PORT, (long) server.getPort())))
|
||||
SemanticAttributes.SERVER_PORT, (long) server.getPort())))
|
||||
.hasEventsSatisfyingExactly(
|
||||
event ->
|
||||
event
|
||||
|
|
@ -653,14 +647,12 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) status.getCode().value()),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_NAME,
|
||||
val -> assertThat(val).isNotNull()),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_PORT,
|
||||
NetworkAttributes.NETWORK_PEER_PORT,
|
||||
val -> assertThat(val).isNotNull()))
|
||||
.hasEventsSatisfying(
|
||||
events -> {
|
||||
|
|
@ -692,7 +684,7 @@ public abstract class AbstractGrpcTest {
|
|||
point ->
|
||||
point.hasAttributesSatisfying(
|
||||
equalTo(
|
||||
SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
|
||||
equalTo(
|
||||
SemanticAttributes.RPC_SERVICE,
|
||||
|
|
@ -716,9 +708,9 @@ public abstract class AbstractGrpcTest {
|
|||
point ->
|
||||
point.hasAttributesSatisfying(
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_PORT,
|
||||
SemanticAttributes.SERVER_PORT,
|
||||
server.getPort()),
|
||||
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
|
||||
equalTo(
|
||||
|
|
@ -780,9 +772,9 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.UNKNOWN.getCode().value()),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_PORT, (long) server.getPort())))
|
||||
SemanticAttributes.SERVER_PORT, (long) server.getPort())))
|
||||
.hasEventsSatisfyingExactly(
|
||||
event ->
|
||||
event
|
||||
|
|
@ -802,14 +794,12 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.UNKNOWN.value()),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_NAME,
|
||||
val -> assertThat(val).isNotNull()),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_PORT,
|
||||
NetworkAttributes.NETWORK_PEER_PORT,
|
||||
val -> assertThat(val).isNotNull()))
|
||||
.hasEventsSatisfying(
|
||||
events -> {
|
||||
|
|
@ -836,7 +826,7 @@ public abstract class AbstractGrpcTest {
|
|||
point ->
|
||||
point.hasAttributesSatisfying(
|
||||
equalTo(
|
||||
SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
|
||||
equalTo(
|
||||
SemanticAttributes.RPC_SERVICE,
|
||||
|
|
@ -860,9 +850,9 @@ public abstract class AbstractGrpcTest {
|
|||
point ->
|
||||
point.hasAttributesSatisfying(
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_PORT,
|
||||
SemanticAttributes.SERVER_PORT,
|
||||
server.getPort()),
|
||||
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
|
||||
equalTo(
|
||||
|
|
@ -1028,9 +1018,9 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.OK.value()),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_PORT, (long) server.getPort())))
|
||||
SemanticAttributes.SERVER_PORT, (long) server.getPort())))
|
||||
.hasEventsSatisfyingExactly(
|
||||
event ->
|
||||
event
|
||||
|
|
@ -1055,14 +1045,12 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.OK.value()),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_NAME,
|
||||
val -> assertThat(val).isNotNull()),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_PORT,
|
||||
NetworkAttributes.NETWORK_PEER_PORT,
|
||||
val -> assertThat(val).isNotNull()))
|
||||
.hasEventsSatisfyingExactly(
|
||||
event ->
|
||||
|
|
@ -1148,9 +1136,9 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.CANCELLED.value()),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_PORT, (long) server.getPort())))
|
||||
SemanticAttributes.SERVER_PORT, (long) server.getPort())))
|
||||
.hasEventsSatisfying(
|
||||
events -> {
|
||||
assertThat(events).hasSize(3);
|
||||
|
|
@ -1177,14 +1165,12 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.CANCELLED.value()),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_NAME,
|
||||
val -> assertThat(val).isNotNull()),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_PORT,
|
||||
NetworkAttributes.NETWORK_PEER_PORT,
|
||||
val -> assertThat(val).isNotNull()))
|
||||
.hasEventsSatisfyingExactly(
|
||||
event ->
|
||||
|
|
@ -1268,9 +1254,9 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.OK.value()),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_PORT, (long) server.getPort())))
|
||||
SemanticAttributes.SERVER_PORT, (long) server.getPort())))
|
||||
.hasEventsSatisfyingExactly(
|
||||
event ->
|
||||
event
|
||||
|
|
@ -1298,14 +1284,12 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.OK.value()),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_NAME,
|
||||
val -> assertThat(val).isNotNull()),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_PORT,
|
||||
NetworkAttributes.NETWORK_PEER_PORT,
|
||||
val -> assertThat(val).isNotNull()))
|
||||
.hasEventsSatisfyingExactly(
|
||||
event ->
|
||||
|
|
@ -1375,9 +1359,9 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.OK.value()),
|
||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(
|
||||
SemanticAttributes.NET_PEER_PORT, (long) server.getPort())))
|
||||
SemanticAttributes.SERVER_PORT, (long) server.getPort())))
|
||||
.hasEventsSatisfyingExactly(
|
||||
event ->
|
||||
event
|
||||
|
|
@ -1402,14 +1386,12 @@ public abstract class AbstractGrpcTest {
|
|||
equalTo(
|
||||
SemanticAttributes.RPC_GRPC_STATUS_CODE,
|
||||
(long) Status.Code.OK.value()),
|
||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
||||
equalTo(SemanticAttributes.NET_HOST_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, server.getPort()),
|
||||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
|
||||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_NAME,
|
||||
val -> assertThat(val).isNotNull()),
|
||||
satisfies(
|
||||
SemanticAttributes.NET_SOCK_PEER_PORT,
|
||||
NetworkAttributes.NETWORK_PEER_PORT,
|
||||
val -> assertThat(val).isNotNull()))
|
||||
.hasEventsSatisfyingExactly(
|
||||
event ->
|
||||
|
|
@ -1664,11 +1646,10 @@ public abstract class AbstractGrpcTest {
|
|||
List<AttributeAssertion> result = new ArrayList<>();
|
||||
result.addAll(Arrays.asList(assertions));
|
||||
if (Boolean.getBoolean("testLatestDeps")) {
|
||||
result.add(equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"));
|
||||
result.add(equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"));
|
||||
result.add(equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"));
|
||||
result.add(
|
||||
satisfies(SemanticAttributes.NET_SOCK_PEER_NAME, val -> assertThat(val).isNotNull()));
|
||||
result.add(
|
||||
satisfies(SemanticAttributes.NET_SOCK_PEER_PORT, val -> assertThat(val).isNotNull()));
|
||||
satisfies(NetworkAttributes.NETWORK_PEER_PORT, val -> assertThat(val).isNotNull()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import static io.opentelemetry.semconv.SemanticAttributes.DB_OPERATION;
|
|||
import static io.opentelemetry.semconv.SemanticAttributes.DB_SQL_TABLE;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.DB_STATEMENT;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.DB_USER;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NET_PEER_NAME;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NET_PEER_PORT;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.SERVER_ADDRESS;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.SERVER_PORT;
|
||||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
|
|
@ -291,7 +291,6 @@ class HibernateReactiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
private static void assertTrace() {
|
||||
testing.waitAndAssertTraces(
|
||||
trace ->
|
||||
|
|
@ -309,8 +308,8 @@ class HibernateReactiveTest {
|
|||
"select value0_.id as id1_0_0_, value0_.name as name2_0_0_ from Value value0_ where value0_.id=$?"),
|
||||
equalTo(DB_OPERATION, "SELECT"),
|
||||
equalTo(DB_SQL_TABLE, "Value"),
|
||||
equalTo(NET_PEER_NAME, "localhost"),
|
||||
equalTo(NET_PEER_PORT, port)),
|
||||
equalTo(SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SERVER_PORT, port)),
|
||||
span ->
|
||||
span.hasName("callback")
|
||||
.hasKind(SpanKind.INTERNAL)
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import static io.opentelemetry.semconv.SemanticAttributes.DB_OPERATION;
|
|||
import static io.opentelemetry.semconv.SemanticAttributes.DB_SQL_TABLE;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.DB_STATEMENT;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.DB_USER;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NET_PEER_NAME;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.NET_PEER_PORT;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.SERVER_ADDRESS;
|
||||
import static io.opentelemetry.semconv.SemanticAttributes.SERVER_PORT;
|
||||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
|
|
@ -283,7 +283,6 @@ class HibernateReactiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
private static void assertTrace() {
|
||||
testing.waitAndAssertTraces(
|
||||
trace ->
|
||||
|
|
@ -301,8 +300,8 @@ class HibernateReactiveTest {
|
|||
"select v1_0.id,v1_0.name from Value v1_0 where v1_0.id=$?"),
|
||||
equalTo(DB_OPERATION, "SELECT"),
|
||||
equalTo(DB_SQL_TABLE, "Value"),
|
||||
equalTo(NET_PEER_NAME, "localhost"),
|
||||
equalTo(NET_PEER_PORT, port)),
|
||||
equalTo(SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SERVER_PORT, port)),
|
||||
span ->
|
||||
span.hasName("callback")
|
||||
.hasKind(SpanKind.INTERNAL)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import io.opentelemetry.api.common.AttributesBuilder;
|
|||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
|
||||
import io.opentelemetry.semconv.SemanticAttributes;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.Set;
|
||||
|
|
@ -38,7 +37,6 @@ public class HttpMethodAttributeExtractor<
|
|||
AttributesBuilder attributes, Context parentContext, HttpURLConnection connection) {}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
public void onEnd(
|
||||
AttributesBuilder attributes,
|
||||
Context context,
|
||||
|
|
@ -51,17 +49,12 @@ public class HttpMethodAttributeExtractor<
|
|||
if (getOutputStreamContext.isOutputStreamMethodOfSunConnectionCalled()) {
|
||||
String method = connection.getRequestMethod();
|
||||
// The getOutputStream() has transformed "GET" into "POST"
|
||||
if (SemconvStability.emitStableHttpSemconv()) {
|
||||
if (knownMethods.contains(method)) {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method);
|
||||
attributes.remove(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL);
|
||||
} else {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER);
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method);
|
||||
}
|
||||
}
|
||||
if (SemconvStability.emitOldHttpSemconv()) {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_METHOD, method);
|
||||
if (knownMethods.contains(method)) {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, method);
|
||||
attributes.remove(SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL);
|
||||
} else {
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD, _OTHER);
|
||||
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method);
|
||||
}
|
||||
Span span = Span.fromContext(context);
|
||||
span.updateName(method);
|
||||
|
|
|
|||
|
|
@ -10,13 +10,11 @@ import static io.opentelemetry.api.trace.SpanKind.INTERNAL;
|
|||
import static io.opentelemetry.api.trace.SpanKind.SERVER;
|
||||
import static io.opentelemetry.javaagent.instrumentation.httpurlconnection.StreamUtils.readLines;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.catchThrowable;
|
||||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
||||
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
|
||||
import io.opentelemetry.instrumentation.test.utils.PortUtils;
|
||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
|
||||
|
|
@ -37,7 +35,6 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.assertj.core.api.AbstractLongAssert;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
|
|
@ -92,7 +89,6 @@ class HttpUrlConnectionTest extends AbstractHttpClientTest<HttpURLConnection> {
|
|||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {false, true})
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
public void traceRequest(boolean useCache) throws IOException {
|
||||
URL url = resolveAddress("/success").toURL();
|
||||
|
||||
|
|
@ -124,18 +120,12 @@ class HttpUrlConnectionTest extends AbstractHttpClientTest<HttpURLConnection> {
|
|||
List<AttributeAssertion> attributes =
|
||||
new ArrayList<>(
|
||||
Arrays.asList(
|
||||
equalTo(getAttributeKey(SemanticAttributes.NET_PROTOCOL_VERSION), "1.1"),
|
||||
equalTo(getAttributeKey(SemanticAttributes.NET_PEER_NAME), "localhost"),
|
||||
equalTo(getAttributeKey(SemanticAttributes.NET_PEER_PORT), url.getPort()),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_URL), url.toString()),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_METHOD), "GET"),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_STATUS_CODE), STATUS)));
|
||||
if (SemconvStability.emitOldHttpSemconv()) {
|
||||
attributes.add(equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"));
|
||||
attributes.add(
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, AbstractLongAssert::isNotNegative));
|
||||
}
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, url.getPort()),
|
||||
equalTo(SemanticAttributes.URL_FULL, url.toString()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, STATUS)));
|
||||
|
||||
testing.waitAndAssertTraces(
|
||||
trace ->
|
||||
|
|
@ -159,7 +149,6 @@ class HttpUrlConnectionTest extends AbstractHttpClientTest<HttpURLConnection> {
|
|||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
public void testBrokenApiUsage() throws IOException {
|
||||
URL url = resolveAddress("/success").toURL();
|
||||
HttpURLConnection connection =
|
||||
|
|
@ -176,18 +165,12 @@ class HttpUrlConnectionTest extends AbstractHttpClientTest<HttpURLConnection> {
|
|||
List<AttributeAssertion> attributes =
|
||||
new ArrayList<>(
|
||||
Arrays.asList(
|
||||
equalTo(getAttributeKey(SemanticAttributes.NET_PROTOCOL_VERSION), "1.1"),
|
||||
equalTo(getAttributeKey(SemanticAttributes.NET_PEER_NAME), "localhost"),
|
||||
equalTo(getAttributeKey(SemanticAttributes.NET_PEER_PORT), url.getPort()),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_URL), url.toString()),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_METHOD), "GET"),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_STATUS_CODE), STATUS)));
|
||||
if (SemconvStability.emitOldHttpSemconv()) {
|
||||
attributes.add(equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"));
|
||||
attributes.add(
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, AbstractLongAssert::isNotNegative));
|
||||
}
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, url.getPort()),
|
||||
equalTo(SemanticAttributes.URL_FULL, url.toString()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, STATUS)));
|
||||
|
||||
testing.waitAndAssertTraces(
|
||||
trace ->
|
||||
|
|
@ -205,7 +188,6 @@ class HttpUrlConnectionTest extends AbstractHttpClientTest<HttpURLConnection> {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
public void testPostRequest() throws IOException {
|
||||
URL url = resolveAddress("/success").toURL();
|
||||
testing.runWithSpan(
|
||||
|
|
@ -234,21 +216,12 @@ class HttpUrlConnectionTest extends AbstractHttpClientTest<HttpURLConnection> {
|
|||
List<AttributeAssertion> attributes =
|
||||
new ArrayList<>(
|
||||
Arrays.asList(
|
||||
equalTo(getAttributeKey(SemanticAttributes.NET_PROTOCOL_VERSION), "1.1"),
|
||||
equalTo(getAttributeKey(SemanticAttributes.NET_PEER_NAME), "localhost"),
|
||||
equalTo(getAttributeKey(SemanticAttributes.NET_PEER_PORT), url.getPort()),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_URL), url.toString()),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_METHOD), "POST"),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_STATUS_CODE), STATUS)));
|
||||
if (SemconvStability.emitOldHttpSemconv()) {
|
||||
attributes.add(equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"));
|
||||
attributes.add(
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, AbstractLongAssert::isNotNegative));
|
||||
attributes.add(
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, AbstractLongAssert::isNotNegative));
|
||||
}
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, url.getPort()),
|
||||
equalTo(SemanticAttributes.URL_FULL, url.toString()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, STATUS)));
|
||||
|
||||
testing.waitAndAssertTraces(
|
||||
trace ->
|
||||
|
|
@ -264,7 +237,6 @@ class HttpUrlConnectionTest extends AbstractHttpClientTest<HttpURLConnection> {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
public void getOutputStreamShouldTransformGetIntoPost() throws IOException {
|
||||
URL url = resolveAddress("/success").toURL();
|
||||
testing.runWithSpan(
|
||||
|
|
@ -297,21 +269,12 @@ class HttpUrlConnectionTest extends AbstractHttpClientTest<HttpURLConnection> {
|
|||
List<AttributeAssertion> attributes =
|
||||
new ArrayList<>(
|
||||
Arrays.asList(
|
||||
equalTo(getAttributeKey(SemanticAttributes.NET_PROTOCOL_VERSION), "1.1"),
|
||||
equalTo(getAttributeKey(SemanticAttributes.NET_PEER_NAME), "localhost"),
|
||||
equalTo(getAttributeKey(SemanticAttributes.NET_PEER_PORT), url.getPort()),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_URL), url.toString()),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_METHOD), "POST"),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_STATUS_CODE), STATUS)));
|
||||
if (SemconvStability.emitOldHttpSemconv()) {
|
||||
attributes.add(equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"));
|
||||
attributes.add(
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, AbstractLongAssert::isNotNegative));
|
||||
attributes.add(
|
||||
satisfies(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, AbstractLongAssert::isNotNegative));
|
||||
}
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, url.getPort()),
|
||||
equalTo(SemanticAttributes.URL_FULL, url.toString()),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "POST"),
|
||||
equalTo(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, STATUS)));
|
||||
|
||||
testing.waitAndAssertTraces(
|
||||
trace ->
|
||||
|
|
@ -328,7 +291,6 @@ class HttpUrlConnectionTest extends AbstractHttpClientTest<HttpURLConnection> {
|
|||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"http", "https"})
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
public void traceRequestWithConnectionFailure(String scheme) {
|
||||
String uri = scheme + "://localhost:" + PortUtils.UNUSABLE_PORT;
|
||||
|
||||
|
|
@ -349,17 +311,12 @@ class HttpUrlConnectionTest extends AbstractHttpClientTest<HttpURLConnection> {
|
|||
List<AttributeAssertion> attributes =
|
||||
new ArrayList<>(
|
||||
Arrays.asList(
|
||||
equalTo(getAttributeKey(SemanticAttributes.NET_PROTOCOL_VERSION), "1.1"),
|
||||
equalTo(getAttributeKey(SemanticAttributes.NET_PEER_NAME), "localhost"),
|
||||
equalTo(getAttributeKey(SemanticAttributes.NET_PEER_PORT), PortUtils.UNUSABLE_PORT),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_URL), uri),
|
||||
equalTo(getAttributeKey(SemanticAttributes.HTTP_METHOD), "GET")));
|
||||
if (SemconvStability.emitOldHttpSemconv()) {
|
||||
attributes.add(equalTo(SemanticAttributes.NET_PROTOCOL_NAME, "http"));
|
||||
}
|
||||
if (SemconvStability.emitStableHttpSemconv()) {
|
||||
attributes.add(equalTo(HttpAttributes.ERROR_TYPE, "java.net.ConnectException"));
|
||||
}
|
||||
equalTo(SemanticAttributes.NETWORK_PROTOCOL_VERSION, "1.1"),
|
||||
equalTo(SemanticAttributes.SERVER_ADDRESS, "localhost"),
|
||||
equalTo(SemanticAttributes.SERVER_PORT, PortUtils.UNUSABLE_PORT),
|
||||
equalTo(SemanticAttributes.URL_FULL, uri),
|
||||
equalTo(SemanticAttributes.HTTP_REQUEST_METHOD, "GET"),
|
||||
equalTo(HttpAttributes.ERROR_TYPE, "java.net.ConnectException")));
|
||||
|
||||
testing.waitAndAssertTraces(
|
||||
trace ->
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
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;
|
||||
|
|
@ -78,27 +77,23 @@ public abstract class AbstractJavaHttpClientTest extends AbstractHttpClientTest<
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
|
||||
protected void configure(HttpClientTestOptions.Builder optionsBuilder) {
|
||||
optionsBuilder.disableTestCircularRedirects();
|
||||
// TODO nested client span is not created, but context is still injected
|
||||
// which is not what the test expects
|
||||
optionsBuilder.disableTestWithClientParent();
|
||||
|
||||
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;
|
||||
});
|
||||
}
|
||||
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.NETWORK_PROTOCOL_VERSION);
|
||||
}
|
||||
return attributes;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,8 +79,12 @@ class JaxRsClientV1Test extends HttpClientTest<WebResource.Builder> implements A
|
|||
@Override
|
||||
Set<AttributeKey<?>> httpAttributes(URI uri) {
|
||||
def attributes = super.httpAttributes(uri)
|
||||
attributes.remove(SemanticAttributes.NET_PROTOCOL_NAME)
|
||||
attributes.remove(SemanticAttributes.NET_PROTOCOL_VERSION)
|
||||
attributes.remove(SemanticAttributes.NETWORK_PROTOCOL_VERSION)
|
||||
return attributes
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean testNonStandardHttpMethod() {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes
|
||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.base.HttpClientTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult
|
||||
|
|
@ -33,6 +35,11 @@ abstract class JaxRsClientTest extends HttpClientTest<Invocation.Builder> implem
|
|||
false
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean testNonStandardHttpMethod() {
|
||||
false
|
||||
}
|
||||
|
||||
@Override
|
||||
Invocation.Builder buildRequest(String method, URI uri, Map<String, String> headers) {
|
||||
return internalBuildRequest(uri, headers)
|
||||
|
|
@ -107,15 +114,14 @@ abstract class JaxRsClientTest extends HttpClientTest<Invocation.Builder> implem
|
|||
kind CLIENT
|
||||
status ERROR
|
||||
attributes {
|
||||
"$SemanticAttributes.NET_PROTOCOL_NAME" "http"
|
||||
"$SemanticAttributes.NET_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.NET_PEER_NAME" uri.host
|
||||
"$SemanticAttributes.NET_PEER_PORT" uri.port > 0 ? uri.port : { it == null || it == 443 }
|
||||
"$SemanticAttributes.NET_SOCK_PEER_ADDR" { it == "127.0.0.1" || it == null }
|
||||
"$SemanticAttributes.HTTP_URL" "${uri}"
|
||||
"$SemanticAttributes.HTTP_METHOD" method
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" statusCode
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
"$SemanticAttributes.NETWORK_PROTOCOL_VERSION" "1.1"
|
||||
"$SemanticAttributes.SERVER_ADDRESS" uri.host
|
||||
"$SemanticAttributes.SERVER_PORT" uri.port > 0 ? uri.port : { it == null || it == 443 }
|
||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == "127.0.0.1" || it == null }
|
||||
"$SemanticAttributes.URL_FULL" "${uri}"
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" method
|
||||
"$SemanticAttributes.HTTP_RESPONSE_STATUS_CODE" statusCode
|
||||
"$HttpAttributes.ERROR_TYPE" "$statusCode"
|
||||
}
|
||||
}
|
||||
serverSpan(it, 1, span(0))
|
||||
|
|
|
|||
|
|
@ -84,6 +84,11 @@ class ResteasyProxyClientTest extends HttpClientTest<ResteasyProxyResource> impl
|
|||
boolean testReadTimeout() {
|
||||
return false
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean testNonStandardHttpMethod() {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@Path("")
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes
|
||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
import spock.lang.Unroll
|
||||
|
|
@ -35,8 +36,9 @@ class JaxRsAnnotations1InstrumentationTest extends AgentInstrumentationSpecifica
|
|||
kind SERVER
|
||||
hasNoParent()
|
||||
attributes {
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_ROUTE" paramName
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
span(1) {
|
||||
|
|
@ -124,7 +126,8 @@ class JaxRsAnnotations1InstrumentationTest extends AgentInstrumentationSpecifica
|
|||
name "GET"
|
||||
kind SERVER
|
||||
attributes {
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "GET"
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
|
||||
import io.dropwizard.testing.junit.ResourceTestRule
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes
|
||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
import org.junit.ClassRule
|
||||
|
|
@ -40,8 +41,9 @@ class JerseyTest extends AgentInstrumentationSpecification {
|
|||
name "GET " + expectedRoute
|
||||
kind SERVER
|
||||
attributes {
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_ROUTE" expectedRoute
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -80,8 +82,9 @@ class JerseyTest extends AgentInstrumentationSpecification {
|
|||
name "GET " + expectedRoute
|
||||
kind SERVER
|
||||
attributes {
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_ROUTE" expectedRoute
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
span(1) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes
|
||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||
import io.opentelemetry.semconv.SemanticAttributes
|
||||
import spock.lang.Unroll
|
||||
|
|
@ -35,8 +36,9 @@ class JaxrsAnnotationsInstrumentationTest extends AgentInstrumentationSpecificat
|
|||
kind SERVER
|
||||
hasNoParent()
|
||||
attributes {
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_ROUTE" paramName
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
span(1) {
|
||||
|
|
@ -124,7 +126,8 @@ class JaxrsAnnotationsInstrumentationTest extends AgentInstrumentationSpecificat
|
|||
name "GET"
|
||||
kind SERVER
|
||||
attributes {
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_REQUEST_METHOD" "GET"
|
||||
"$HttpAttributes.ERROR_TYPE" "_OTHER"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.api.internal.HttpConstants
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import org.eclipse.jetty.server.Server
|
||||
import org.eclipse.jetty.webapp.WebAppContext
|
||||
|
||||
|
|
@ -38,4 +40,12 @@ abstract class JaxRsJettyHttpServerTest extends JaxRsHttpServerTest<Server> {
|
|||
String getContextPath() {
|
||||
"/rest-app"
|
||||
}
|
||||
|
||||
@Override
|
||||
String expectedHttpRoute(ServerEndpoint endpoint, String method) {
|
||||
if (method == HttpConstants._OTHER) {
|
||||
return "${getContextPath()}/*"
|
||||
}
|
||||
return super.expectedHttpRoute(endpoint, method)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ dependencies {
|
|||
}
|
||||
|
||||
tasks.withType<Test>().configureEach {
|
||||
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
|
||||
|
||||
// TODO run tests both with and without experimental span attributes
|
||||
jvmArgs("-Dotel.instrumentation.jaxrs.experimental-span-attributes=true")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,4 +40,9 @@ class CxfHttpServerTest extends JaxRsHttpServerTest<Server> {
|
|||
void stopServer(Server httpServer) {
|
||||
httpServer.stop()
|
||||
}
|
||||
|
||||
@Override
|
||||
int getResponseCodeOnNonStandardHttpMethod() {
|
||||
Boolean.getBoolean("testLatestDeps") ? 500 : 405
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,4 +4,9 @@
|
|||
*/
|
||||
|
||||
class CxfJettyHttpServerTest extends JaxRsJettyHttpServerTest {
|
||||
|
||||
@Override
|
||||
int getResponseCodeOnNonStandardHttpMethod() {
|
||||
Boolean.getBoolean("testLatestDeps") ? 500 : 405
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.api.internal.HttpConstants
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import org.eclipse.jetty.server.Server
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler
|
||||
import org.eclipse.jetty.servlet.ServletHolder
|
||||
|
|
@ -42,4 +44,17 @@ class JerseyHttpServerTest extends JaxRsHttpServerTest<Server> {
|
|||
// disables a test that jersey deems invalid
|
||||
false
|
||||
}
|
||||
|
||||
@Override
|
||||
String expectedHttpRoute(ServerEndpoint endpoint, String method) {
|
||||
if (method == HttpConstants._OTHER) {
|
||||
return "${getContextPath()}/*"
|
||||
}
|
||||
return super.expectedHttpRoute(endpoint, method)
|
||||
}
|
||||
|
||||
@Override
|
||||
int getResponseCodeOnNonStandardHttpMethod() {
|
||||
500
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,4 +15,9 @@ class JerseyJettyHttpServerTest extends JaxRsJettyHttpServerTest {
|
|||
// disables a test that jersey deems invalid
|
||||
false
|
||||
}
|
||||
|
||||
@Override
|
||||
int getResponseCodeOnNonStandardHttpMethod() {
|
||||
500
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.api.internal.HttpConstants
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.undertow.Undertow
|
||||
import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer
|
||||
import test.JaxRsTestApplication
|
||||
|
|
@ -33,4 +35,17 @@ class ResteasyHttpServerTest extends JaxRsHttpServerTest<UndertowJaxrsServer> {
|
|||
boolean shouldTestCompletableStageAsync() {
|
||||
false
|
||||
}
|
||||
|
||||
@Override
|
||||
String expectedHttpRoute(ServerEndpoint endpoint, String method) {
|
||||
if (method == HttpConstants._OTHER) {
|
||||
return "${getContextPath()}/*"
|
||||
}
|
||||
return super.expectedHttpRoute(endpoint, method)
|
||||
}
|
||||
|
||||
@Override
|
||||
int getResponseCodeOnNonStandardHttpMethod() {
|
||||
500
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,4 +9,9 @@ class ResteasyJettyHttpServerTest extends JaxRsJettyHttpServerTest {
|
|||
boolean shouldTestCompletableStageAsync() {
|
||||
false
|
||||
}
|
||||
|
||||
@Override
|
||||
int getResponseCodeOnNonStandardHttpMethod() {
|
||||
500
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue