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 @@ -6,6 +6,7 @@
package io.opentelemetry.instrumentation.apachedubbo.v2_7.internal;

import static io.opentelemetry.instrumentation.apachedubbo.v2_7.internal.DubboRegistryUtil.buildServiceTarget;
import static io.opentelemetry.instrumentation.api.internal.SemconvStability.emitStableRpcSemconv;

import io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboRequest;
import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter;
Expand All @@ -24,8 +25,10 @@ public final class DubboClientNetworkAttributesGetter
@Nullable
@Override
public String getServerAddress(DubboRequest request) {
// the registry address is the logical target only under the stable rpc semconv; keep the
// resolved provider host under the old semconv to avoid changing already-emitted attributes
String registryAddress = request.registryAddress();
if (registryAddress != null) {
if (registryAddress != null && emitStableRpcSemconv()) {
return registryAddress + "/" + buildServiceTarget(request.url());
}
return request.url().getHost();
Expand All @@ -34,7 +37,7 @@ public String getServerAddress(DubboRequest request) {
@Nullable
@Override
public Integer getServerPort(DubboRequest request) {
if (request.registryAddress() != null) {
if (request.registryAddress() != null && emitStableRpcSemconv()) {
return null;
}
int port = request.url().getPort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@

/**
* Integration test that verifies the registry-mode end-to-end flow: provider registers to
* ZooKeeper, consumer discovers via ZooKeeper, and the {@code SERVER_ADDRESS} span attribute
* contains the registry address (with service interface, version, and group) instead of the
* provider host.
* ZooKeeper, consumer discovers via ZooKeeper, and, under the stable rpc semconv, the {@code
* SERVER_ADDRESS} span attribute contains the registry address (with service interface, version,
* and group) instead of the provider host. Under the old rpc semconv the resolved provider host is
* kept.
*/
@SuppressWarnings("deprecation") // using deprecated semconv
public abstract class AbstractDubboRegistryTest {
Expand Down Expand Up @@ -149,8 +150,9 @@ void testRegistryModeServerAddress() throws Exception {

assertThat(response).isEqualTo("hello");

// In registry mode, SERVER_ADDRESS = "registryProtocol://host:port/interface:version:group"
// and SERVER_PORT is absent (null).
// Under the stable rpc semconv, SERVER_ADDRESS =
// "registryProtocol://host:port/interface:version:group" and SERVER_PORT is absent (null).
// Under the old rpc semconv the resolved provider host/port are kept.
// See https://github.com/open-telemetry/semantic-conventions/pull/3317
String expectedServiceTarget =
HelloService.class.getName() + ":" + SERVICE_VERSION + ":" + SERVICE_GROUP;
Expand Down Expand Up @@ -178,8 +180,19 @@ void testRegistryModeServerAddress() throws Exception {
emitStableRpcSemconv()
? "org.apache.dubbo.rpc.service.GenericService/$invoke"
: "$invoke"),
equalTo(SERVER_ADDRESS, expectedServerAddress),
equalTo(SERVER_PORT, null),
satisfies(
SERVER_ADDRESS,
val -> {
if (emitStableRpcSemconv()) {
val.isEqualTo(expectedServerAddress);
} else {
// registry override is gated behind the stable rpc semconv;
// under the old semconv the resolved provider host is used
val.isInstanceOf(String.class)
.isNotEqualTo(expectedServerAddress);
Comment thread
trask marked this conversation as resolved.
Outdated
}
}),
equalTo(SERVER_PORT, emitStableRpcSemconv() ? null : (long) port),
satisfies(
NETWORK_PEER_ADDRESS,
val ->
Expand Down
Loading