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
4 changes: 2 additions & 2 deletions instrumentation-api-incubator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ tasks {
val testStableSemconv by registering(Test::class) {
testClassesDirs = sourceSets.test.get().output.classesDirs
classpath = sourceSets.test.get().runtimeClasspath
jvmArgs("-Dotel.semconv-stability.opt-in=database,code,service.peer")
jvmArgs("-Dotel.semconv-stability.opt-in=database,code,service.peer,rpc")
inputs.dir(jflexOutputDir)
}

val testBothSemconv by registering(Test::class) {
testClassesDirs = sourceSets.test.get().output.classesDirs
classpath = sourceSets.test.get().runtimeClasspath
jvmArgs("-Dotel.semconv-stability.opt-in=database/dup,code/dup,service.peer/dup")
jvmArgs("-Dotel.semconv-stability.opt-in=database/dup,code/dup,service.peer/dup,rpc/dup")
inputs.dir(jflexOutputDir)
}

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

import static java.util.Arrays.asList;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -18,6 +20,13 @@
*/
public final class SemconvStability {

// copied from RpcIncubatingAttributes
private static final AttributeKey<String> RPC_METHOD = AttributeKey.stringKey("rpc.method");

// virtual key to avoid clash with stable rpc.method
private static final AttributeKey<String> RPC_METHOD_OLD =
AttributeKey.stringKey("rpc.method.deprecated");

private static final boolean emitOldDatabaseSemconv;
private static final boolean emitStableDatabaseSemconv;

Expand All @@ -27,6 +36,9 @@ public final class SemconvStability {
private static final boolean emitOldServicePeerSemconv;
private static final boolean emitStableServicePeerSemconv;

private static final boolean emitOldRpcSemconv;
private static final boolean emitStableRpcSemconv;

static {
boolean oldDatabase = true;
boolean stableDatabase = false;
Expand All @@ -37,6 +49,9 @@ public final class SemconvStability {
boolean oldServicePeer = true;
boolean stableServicePeer = false;

boolean oldRpc = true;
boolean stableRpc = false;

String value = System.getProperty("otel.semconv-stability.opt-in");
if (value == null) {
value = System.getenv("OTEL_SEMCONV_STABILITY_OPT_IN");
Expand Down Expand Up @@ -73,6 +88,15 @@ public final class SemconvStability {
oldServicePeer = true;
stableServicePeer = true;
}

if (values.contains("rpc")) {
oldRpc = false;
stableRpc = true;
}
if (values.contains("rpc/dup")) {
oldRpc = true;
stableRpc = true;
}
}

emitOldDatabaseSemconv = oldDatabase;
Expand All @@ -83,6 +107,9 @@ public final class SemconvStability {

emitOldServicePeerSemconv = oldServicePeer;
emitStableServicePeerSemconv = stableServicePeer;

emitOldRpcSemconv = oldRpc;
emitStableRpcSemconv = stableRpc;
}

public static boolean emitOldDatabaseSemconv() {
Expand Down Expand Up @@ -134,5 +161,41 @@ public static boolean isEmitStableCodeSemconv() {
return emitStableCodeSemconv;
}

public static boolean emitOldRpcSemconv() {
return emitOldRpcSemconv;
}

public static boolean emitStableRpcSemconv() {
return emitStableRpcSemconv;
}

private static final Map<String, String> rpcSystemNameMap = new HashMap<>();

static {
rpcSystemNameMap.put("apache_dubbo", "dubbo");
rpcSystemNameMap.put("connect_rpc", "connectrpc");
}

public static String stableRpcSystemName(String oldRpcSystem) {
String rpcSystemName = rpcSystemNameMap.get(oldRpcSystem);
return rpcSystemName != null ? rpcSystemName : oldRpcSystem;
}

public static AttributeKey<String> getOldRpcMethodAttributeKey() {
if (emitStableRpcSemconv()) {
// to avoid clash when both semconv are emitted
return RPC_METHOD_OLD;
}
return RPC_METHOD;
}

public static Attributes getOldRpcMetricAttributes(Attributes attributes) {
if (emitStableRpcSemconv()) {
// need to copy attributes
return attributes.toBuilder().put(RPC_METHOD, attributes.get(RPC_METHOD_OLD)).build();
}
return attributes;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these two methods needed? doesn't look like db semconv needed them?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when we emit both semantic conventions we want to keep track of both method styles - so they can be added to the corresponding metrics. Spans will get new method in that case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not following, let's just remove for now and you can add them back when you need them, then I can understand the context better and whether there's better option or not

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


private SemconvStability() {}
}
Loading