Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ tasks.test {
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
}

tasks {
val testStableSemconv by registering(Test::class) {
testClassesDirs = sourceSets.test.get().output.classesDirs
classpath = sourceSets.test.get().runtimeClasspath
jvmArgs("-Dotel.semconv-stability.opt-in=rpc")
systemProperty("metadataConfig", "otel.semconv-stability.opt-in=rpc")
}

check {
dependsOn(testStableSemconv)
}
}

if (findProperty("denyUnsafe") as Boolean) {
tasks.withType<Test>().configureEach {
enabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@

package io.opentelemetry.javaagent.instrumentation.armeria.grpc.v1_14;

import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitOldRpcSemconv;
import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableRpcSemconv;
import static io.opentelemetry.instrumentation.testing.junit.rpc.SemconvRpcStabilityUtil.maybeStable;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
import static io.opentelemetry.semconv.incubating.MessageIncubatingAttributes.MESSAGE_ID;
import static io.opentelemetry.semconv.incubating.MessageIncubatingAttributes.MESSAGE_TYPE;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_GRPC_STATUS_CODE;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_METHOD;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_RESPONSE_STATUS_CODE;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SERVICE;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SYSTEM;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -78,10 +82,19 @@ void grpcInstrumentation() {
.hasKind(SpanKind.CLIENT)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(RPC_SYSTEM, "grpc"),
equalTo(RPC_SERVICE, "example.Greeter"),
equalTo(RPC_METHOD, "SayHello"),
equalTo(RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()),
equalTo(maybeStable(RPC_SYSTEM), "grpc"),
equalTo(RPC_SERVICE, emitOldRpcSemconv() ? "example.Greeter" : null),
equalTo(
RPC_METHOD,
emitStableRpcSemconv() ? "example.Greeter/SayHello" : "SayHello"),
equalTo(
RPC_GRPC_STATUS_CODE,
emitOldRpcSemconv() ? (long) Status.Code.OK.value() : null),
equalTo(
RPC_RESPONSE_STATUS_CODE,
emitStableRpcSemconv()
? String.valueOf(Status.Code.OK.value())
: null),
equalTo(SERVER_ADDRESS, "127.0.0.1"),
equalTo(SERVER_PORT, (long) server.httpPort()))
.hasEventsSatisfyingExactly(
Expand All @@ -101,10 +114,19 @@ void grpcInstrumentation() {
.hasKind(SpanKind.SERVER)
.hasParent(trace.getSpan(1))
.hasAttributesSatisfyingExactly(
equalTo(RPC_SYSTEM, "grpc"),
equalTo(RPC_SERVICE, "example.Greeter"),
equalTo(RPC_METHOD, "SayHello"),
equalTo(RPC_GRPC_STATUS_CODE, (long) Status.Code.OK.value()),
equalTo(maybeStable(RPC_SYSTEM), "grpc"),
equalTo(RPC_SERVICE, emitOldRpcSemconv() ? "example.Greeter" : null),
equalTo(
RPC_METHOD,
emitStableRpcSemconv() ? "example.Greeter/SayHello" : "SayHello"),
equalTo(
RPC_GRPC_STATUS_CODE,
emitOldRpcSemconv() ? (long) Status.Code.OK.value() : null),
equalTo(
RPC_RESPONSE_STATUS_CODE,
emitStableRpcSemconv()
? String.valueOf(Status.Code.OK.value())
: null),
equalTo(SERVER_ADDRESS, "127.0.0.1"),
equalTo(SERVER_PORT, server.httpPort()))
.hasEventsSatisfyingExactly(
Expand Down
26 changes: 16 additions & 10 deletions instrumentation/grpc-1.6/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
val collectMetadata = findProperty("collectMetadata")?.toString() ?: "false"

tasks {
test {
withType<Test>().configureEach {
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
// The agent context debug mechanism isn't compatible with the bridge approach which may add a
// gRPC context to the root.
Expand All @@ -56,26 +56,32 @@ tasks {
testClassesDirs = sourceSets.test.get().output.classesDirs
classpath = sourceSets.test.get().runtimeClasspath

// replicated base config from standard test task
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
jvmArgs("-Dotel.javaagent.experimental.thread-propagation-debugger.enabled=false")
jvmArgs("-Dotel.instrumentation.grpc.capture-metadata.client.request=some-client-key")
jvmArgs("-Dotel.instrumentation.grpc.capture-metadata.server.request=some-server-key")
jvmArgs("-Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true")

// exclude our grpc library instrumentation, the ContextStorageOverride contained within it
// breaks the tests
classpath = classpath.filter {
!it.absolutePath.contains("opentelemetry-grpc-1.6")
}

systemProperty("collectMetadata", collectMetadata)
systemProperty("metadataConfig", "otel.instrumentation.grpc.experimental-span-attributes=true")
jvmArgs("-Dotel.instrumentation.grpc.experimental-span-attributes=true")
}

val testStableSemconv by registering(Test::class) {
testClassesDirs = sourceSets.test.get().output.classesDirs
classpath = sourceSets.test.get().runtimeClasspath

// exclude our grpc library instrumentation, the ContextStorageOverride contained within it
// breaks the tests
classpath = classpath.filter {
!it.absolutePath.contains("opentelemetry-grpc-1.6")
}

jvmArgs("-Dotel.semconv-stability.opt-in=rpc")
systemProperty("metadataConfig", "otel.semconv-stability.opt-in=rpc")
}

check {
dependsOn(testExperimental)
dependsOn(testExperimental, testStableSemconv)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.grpc.v1_6;

import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitOldRpcSemconv;
import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableRpcSemconv;
import static io.opentelemetry.instrumentation.grpc.v1_6.CapturedGrpcMetadataUtil.lowercase;
import static io.opentelemetry.instrumentation.grpc.v1_6.CapturedGrpcMetadataUtil.requestAttributeKey;

Expand All @@ -21,6 +23,8 @@ final class GrpcAttributesExtractor implements AttributesExtractor<GrpcRequest,
// copied from RpcIncubatingAttributes
private static final AttributeKey<Long> RPC_GRPC_STATUS_CODE =
AttributeKey.longKey("rpc.grpc.status_code");
private static final AttributeKey<String> RPC_RESPONSE_STATUS_CODE =
AttributeKey.stringKey("rpc.response.status_code");

private final GrpcRpcAttributesGetter getter;
private final List<String> capturedRequestMetadata;
Expand All @@ -44,7 +48,12 @@ public void onEnd(
@Nullable Status status,
@Nullable Throwable error) {
if (status != null) {
attributes.put(RPC_GRPC_STATUS_CODE, status.getCode().value());
if (emitOldRpcSemconv()) {
attributes.put(RPC_GRPC_STATUS_CODE, status.getCode().value());
}
if (emitStableRpcSemconv()) {
attributes.put(RPC_RESPONSE_STATUS_CODE, String.valueOf(status.getCode().value()));
}
}
for (String key : capturedRequestMetadata) {
List<String> value = getter.metadataValue(request, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public String getMethod(GrpcRequest request) {
return fullMethodName.substring(slashIndex + 1);
}

@Override
public String getRpcMethod(GrpcRequest request) {
return request.getMethod().getFullMethodName();
}

@Override
@Nullable
public Long getRequestSize(GrpcRequest request) {
Expand Down
Loading
Loading