Skip to content

Commit

Permalink
Test http client stable semconv (#9178)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Aug 13, 2023
1 parent 8be80b1 commit b9e459d
Show file tree
Hide file tree
Showing 49 changed files with 626 additions and 202 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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.internal.SemconvStability;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.HashSet;
Expand Down Expand Up @@ -50,7 +51,7 @@ abstract class HttpCommonAttributesExtractor<
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
String method = getter.getHttpRequestMethod(request);
if (SemconvStability.emitStableHttpSemconv()) {
if (knownMethods.contains(method)) {
if (method == null || knownMethods.contains(method)) {
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, method);
} else {
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, _OTHER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.api.instrumenter.http.internal;

import static io.opentelemetry.api.common.AttributeKey.longKey;
import static io.opentelemetry.api.common.AttributeKey.stringKey;

import io.opentelemetry.api.common.AttributeKey;

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class HttpAttributes {

// FIXME: remove this class and replace its usages with SemanticAttributes once schema 1.21 is
// released

public static final AttributeKey<String> HTTP_REQUEST_METHOD = stringKey("http.request.method");

public static final AttributeKey<String> HTTP_REQUEST_METHOD_ORIGINAL =
stringKey("http.request.method_original");

public static final AttributeKey<Long> HTTP_REQUEST_BODY_SIZE = longKey("http.request.body.size");

public static final AttributeKey<Long> HTTP_RESPONSE_BODY_SIZE =
longKey("http.response.body.size");

public static final AttributeKey<Long> HTTP_RESPONSE_STATUS_CODE =
longKey("http.response.status_code");

private HttpAttributes() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static org.assertj.core.api.Assertions.entry;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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.instrumentation.api.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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.instrumentation.api.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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.instrumentation.api.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
Expand Down
27 changes: 21 additions & 6 deletions instrumentation/akka/akka-http-10.0/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,29 @@ dependencies {
latestDepTestLibrary("com.typesafe.akka:akka-stream_2.13:+")
}

tasks.withType<Test>().configureEach {
// required on jdk17
jvmArgs("--add-exports=java.base/sun.security.util=ALL-UNNAMED")
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
tasks {
val testStableSemconv by registering(Test::class) {
filter {
includeTestsMatching("AkkaHttpClientInstrumentationTest")
}
include("**/AkkaHttpClientInstrumentationTest.*")

jvmArgs("-Dotel.semconv-stability.opt-in=http")
}

withType<Test>().configureEach {
// required on jdk17
jvmArgs("--add-exports=java.base/sun.security.util=ALL-UNNAMED")
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")

jvmArgs("-Dio.opentelemetry.javaagent.shaded.io.opentelemetry.context.enableStrictContext=false")
jvmArgs("-Dio.opentelemetry.javaagent.shaded.io.opentelemetry.context.enableStrictContext=false")

systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
}

check {
dependsOn(testStableSemconv)
}
}

if (findProperty("testLatestDeps") as Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ muzzle {
dependencies {
library("org.apache.httpcomponents:httpasyncclient:4.1")
}

tasks {
val testStableSemconv by registering(Test::class) {
jvmArgs("-Dotel.semconv-stability.opt-in=http")
}

check {
dependsOn(testStableSemconv)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ dependencies {
}

tasks {
val testStableSemconv by registering(Test::class) {
jvmArgs("-Dotel.semconv-stability.opt-in=http")
}

withType<Test>().configureEach {
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
}

check {
dependsOn(testStableSemconv)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ dependencies {
library("org.apache.httpcomponents:httpclient:4.0")
testCompileOnly("net.jcip:jcip-annotations:1.0")
}

tasks {
val testStableSemconv by registering(Test::class) {
jvmArgs("-Dotel.semconv-stability.opt-in=http")
}

check {
dependsOn(testStableSemconv)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ dependencies {

latestDepTestLibrary("org.apache.httpcomponents:httpclient:4.+") // see apache-httpclient-5.0 module
}

tasks {
val testStableSemconv by registering(Test::class) {
jvmArgs("-Dotel.semconv-stability.opt-in=http")
}

check {
dependsOn(testStableSemconv)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ muzzle {
dependencies {
library("org.apache.httpcomponents.client5:httpclient5:5.0")
}

tasks {
val testStableSemconv by registering(Test::class) {
jvmArgs("-Dotel.semconv-stability.opt-in=http")
}

check {
dependsOn(testStableSemconv)
}
}
15 changes: 14 additions & 1 deletion instrumentation/armeria-1.3/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,20 @@ dependencies {
}

tasks {
test {
val testStableSemconv by registering(Test::class) {
filter {
includeTestsMatching("ArmeriaHttpClientTest")
}
include("**/ArmeriaHttpClientTest.*")

jvmArgs("-Dotel.semconv-stability.opt-in=http")
}

withType<Test>().configureEach {
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
}

check {
dependsOn(testStableSemconv)
}
}
15 changes: 14 additions & 1 deletion instrumentation/armeria-1.3/library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@ dependencies {
}

tasks {
test {
val testStableSemconv by registering(Test::class) {
filter {
includeTestsMatching("ArmeriaHttpClientTest")
}
include("**/ArmeriaHttpClientTest.*")

jvmArgs("-Dotel.semconv-stability.opt-in=http")
}

withType<Test>().configureEach {
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
}

check {
dependsOn(testStableSemconv)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,20 @@ dependencies {
testInstrumentation(project(":instrumentation:netty:netty-3.8:javaagent"))
}

tasks.withType<Test>().configureEach {
// required on jdk17
jvmArgs("--add-exports=java.base/sun.security.util=ALL-UNNAMED")
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
tasks {
val testStableSemconv by registering(Test::class) {
jvmArgs("-Dotel.semconv-stability.opt-in=http")
}

withType<Test>().configureEach {
// required on jdk17
jvmArgs("--add-exports=java.base/sun.security.util=ALL-UNNAMED")
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")

systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
}

check {
dependsOn(testStableSemconv)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ otelJava {
maxJavaVersionForTests.set(JavaVersion.VERSION_1_8)
}

tasks {
val testStableSemconv by registering(Test::class) {
jvmArgs("-Dotel.semconv-stability.opt-in=http")
}

check {
dependsOn(testStableSemconv)
}
}

// async-http-client 2.0.0 does not work with Netty versions newer than this due to referencing an
// internal file.
if (!(findProperty("testLatestDeps") as Boolean)) {
Expand Down
10 changes: 10 additions & 0 deletions instrumentation/google-http-client-1.19/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ muzzle {
dependencies {
library("com.google.http-client:google-http-client:1.19.0")
}

tasks {
val testStableSemconv by registering(Test::class) {
jvmArgs("-Dotel.semconv-stability.opt-in=http")
}

check {
dependsOn(testStableSemconv)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ void errorTracesWhenExceptionIsNotThrown() throws Exception {
span.hasKind(SpanKind.CLIENT)
.hasStatus(StatusData.error())
.hasAttributesSatisfyingExactly(
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
satisfies(SemanticAttributes.NET_PEER_PORT, port -> port.isPositive()),
equalTo(SemanticAttributes.HTTP_URL, uri.toString()),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 500),
equalTo(getAttributeKey(SemanticAttributes.NET_PEER_NAME), "localhost"),
satisfies(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
getAttributeKey(SemanticAttributes.NET_PEER_PORT),
port -> port.isPositive()),
equalTo(getAttributeKey(SemanticAttributes.HTTP_URL), uri.toString()),
equalTo(getAttributeKey(SemanticAttributes.HTTP_METHOD), "GET"),
equalTo(getAttributeKey(SemanticAttributes.HTTP_STATUS_CODE), 500),
satisfies(
getAttributeKey(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH),
length -> length.isPositive())),
span -> span.hasKind(SpanKind.SERVER).hasParent(trace.getSpan(0))));
}
Expand Down
Loading

0 comments on commit b9e459d

Please sign in to comment.