Deprecate `NetServerAttributesExtractor` (#9156)
This commit is contained in:
parent
16f4281d08
commit
42f07eedd8
|
@ -10,7 +10,6 @@ import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorU
|
||||||
import io.opentelemetry.api.common.AttributesBuilder;
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
import io.opentelemetry.context.Context;
|
import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetServerAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetServerAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalClientAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalClientAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
|
||||||
|
@ -52,7 +51,9 @@ public final class HttpServerAttributesExtractor<REQUEST, RESPONSE>
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
|
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
|
||||||
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
|
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
|
||||||
NetServerAttributesGetter<REQUEST, RESPONSE> netAttributesGetter) {
|
io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter<
|
||||||
|
REQUEST, RESPONSE>
|
||||||
|
netAttributesGetter) {
|
||||||
return builder(httpAttributesGetter, netAttributesGetter).build();
|
return builder(httpAttributesGetter, netAttributesGetter).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +77,9 @@ public final class HttpServerAttributesExtractor<REQUEST, RESPONSE>
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static <REQUEST, RESPONSE> HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> builder(
|
public static <REQUEST, RESPONSE> HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> builder(
|
||||||
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
|
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
|
||||||
NetServerAttributesGetter<REQUEST, RESPONSE> netAttributesGetter) {
|
io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter<
|
||||||
|
REQUEST, RESPONSE>
|
||||||
|
netAttributesGetter) {
|
||||||
return new HttpServerAttributesExtractorBuilder<>(httpAttributesGetter, netAttributesGetter);
|
return new HttpServerAttributesExtractorBuilder<>(httpAttributesGetter, netAttributesGetter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ import static java.util.Collections.emptyList;
|
||||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||||
import io.opentelemetry.context.Context;
|
import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetServerAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.internal.InternalNetServerAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalClientAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalClientAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
|
||||||
|
@ -28,7 +27,12 @@ import java.util.function.Function;
|
||||||
public final class HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> {
|
public final class HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> {
|
||||||
|
|
||||||
final HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter;
|
final HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter;
|
||||||
final NetServerAttributesGetter<REQUEST, RESPONSE> netAttributesGetter;
|
|
||||||
|
@SuppressWarnings("deprecation") // using the net extractor for the old->stable semconv story
|
||||||
|
final io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter<
|
||||||
|
REQUEST, RESPONSE>
|
||||||
|
netAttributesGetter;
|
||||||
|
|
||||||
final HttpAddressPortExtractor<REQUEST> addressPortExtractor;
|
final HttpAddressPortExtractor<REQUEST> addressPortExtractor;
|
||||||
List<String> capturedRequestHeaders = emptyList();
|
List<String> capturedRequestHeaders = emptyList();
|
||||||
List<String> capturedResponseHeaders = emptyList();
|
List<String> capturedResponseHeaders = emptyList();
|
||||||
|
@ -37,7 +41,10 @@ public final class HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> {
|
||||||
|
|
||||||
HttpServerAttributesExtractorBuilder(
|
HttpServerAttributesExtractorBuilder(
|
||||||
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
|
HttpServerAttributesGetter<REQUEST, RESPONSE> httpAttributesGetter,
|
||||||
NetServerAttributesGetter<REQUEST, RESPONSE> netAttributesGetter) {
|
@SuppressWarnings("deprecation") // using the net extractor for the old->stable semconv story
|
||||||
|
io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter<
|
||||||
|
REQUEST, RESPONSE>
|
||||||
|
netAttributesGetter) {
|
||||||
this.httpAttributesGetter = httpAttributesGetter;
|
this.httpAttributesGetter = httpAttributesGetter;
|
||||||
this.netAttributesGetter = netAttributesGetter;
|
this.netAttributesGetter = netAttributesGetter;
|
||||||
addressPortExtractor = new HttpAddressPortExtractor<>(httpAttributesGetter);
|
addressPortExtractor = new HttpAddressPortExtractor<>(httpAttributesGetter);
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
package io.opentelemetry.instrumentation.api.instrumenter.http;
|
package io.opentelemetry.instrumentation.api.instrumenter.http;
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
|
||||||
|
@ -19,10 +18,14 @@ import javax.annotation.Nullable;
|
||||||
* library/framework. It will be used by the {@link HttpServerAttributesExtractor} to obtain the
|
* library/framework. It will be used by the {@link HttpServerAttributesExtractor} to obtain the
|
||||||
* various HTTP server attributes in a type-generic way.
|
* various HTTP server attributes in a type-generic way.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings(
|
||||||
|
"deprecation") // implementing the NetServerAttributesGetter for the old->stable semconv story;
|
||||||
|
// will be removed in 2.0
|
||||||
public interface HttpServerAttributesGetter<REQUEST, RESPONSE>
|
public interface HttpServerAttributesGetter<REQUEST, RESPONSE>
|
||||||
extends HttpCommonAttributesGetter<REQUEST, RESPONSE>,
|
extends HttpCommonAttributesGetter<REQUEST, RESPONSE>,
|
||||||
UrlAttributesGetter<REQUEST>,
|
UrlAttributesGetter<REQUEST>,
|
||||||
NetServerAttributesGetter<REQUEST, RESPONSE>,
|
io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter<
|
||||||
|
REQUEST, RESPONSE>,
|
||||||
NetworkAttributesGetter<REQUEST, RESPONSE>,
|
NetworkAttributesGetter<REQUEST, RESPONSE>,
|
||||||
ServerAttributesGetter<REQUEST, RESPONSE>,
|
ServerAttributesGetter<REQUEST, RESPONSE>,
|
||||||
ClientAttributesGetter<REQUEST, RESPONSE> {
|
ClientAttributesGetter<REQUEST, RESPONSE> {
|
||||||
|
|
|
@ -21,7 +21,11 @@ import javax.annotation.Nullable;
|
||||||
* Extractor of <a
|
* Extractor of <a
|
||||||
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/span-general.md#general-network-connection-attributes">Network
|
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/span-general.md#general-network-connection-attributes">Network
|
||||||
* attributes</a>.
|
* attributes</a>.
|
||||||
|
*
|
||||||
|
* @deprecated Make sure that your instrumentation uses the extractors from the {@code ...network}
|
||||||
|
* package instead. This class will be removed in the 2.0 release.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public final class NetServerAttributesExtractor<REQUEST, RESPONSE>
|
public final class NetServerAttributesExtractor<REQUEST, RESPONSE>
|
||||||
implements AttributesExtractor<REQUEST, RESPONSE> {
|
implements AttributesExtractor<REQUEST, RESPONSE> {
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,11 @@ import javax.annotation.Nullable;
|
||||||
* <p>Instrumentation authors will create implementations of this interface for their specific
|
* <p>Instrumentation authors will create implementations of this interface for their specific
|
||||||
* server library/framework. It will be used by the {@link NetServerAttributesExtractor} to obtain
|
* server library/framework. It will be used by the {@link NetServerAttributesExtractor} to obtain
|
||||||
* the various network attributes in a type-generic way.
|
* the various network attributes in a type-generic way.
|
||||||
|
*
|
||||||
|
* @deprecated Make sure that your instrumentation implements the getters from the {@code
|
||||||
|
* ...network} package instead. This class will be removed in the 2.0 release.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public interface NetServerAttributesGetter<REQUEST, RESPONSE>
|
public interface NetServerAttributesGetter<REQUEST, RESPONSE>
|
||||||
extends NetworkAttributesGetter<REQUEST, RESPONSE>,
|
extends NetworkAttributesGetter<REQUEST, RESPONSE>,
|
||||||
ServerAttributesGetter<REQUEST, RESPONSE>,
|
ServerAttributesGetter<REQUEST, RESPONSE>,
|
||||||
|
|
|
@ -8,7 +8,6 @@ package io.opentelemetry.instrumentation.api.instrumenter.net.internal;
|
||||||
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
|
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
|
||||||
|
|
||||||
import io.opentelemetry.api.common.AttributesBuilder;
|
import io.opentelemetry.api.common.AttributesBuilder;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPort;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.AddressAndPort;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor;
|
||||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||||
|
@ -17,14 +16,19 @@ import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
||||||
* any time.
|
* any time.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation") // this class will be removed in the 2.0 version
|
||||||
public final class InternalNetServerAttributesExtractor<REQUEST, RESPONSE> {
|
public final class InternalNetServerAttributesExtractor<REQUEST, RESPONSE> {
|
||||||
|
|
||||||
private final NetServerAttributesGetter<REQUEST, RESPONSE> getter;
|
private final io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter<
|
||||||
|
REQUEST, RESPONSE>
|
||||||
|
getter;
|
||||||
private final FallbackAddressPortExtractor<REQUEST> fallbackAddressPortExtractor;
|
private final FallbackAddressPortExtractor<REQUEST> fallbackAddressPortExtractor;
|
||||||
private final boolean emitOldHttpAttributes;
|
private final boolean emitOldHttpAttributes;
|
||||||
|
|
||||||
public InternalNetServerAttributesExtractor(
|
public InternalNetServerAttributesExtractor(
|
||||||
NetServerAttributesGetter<REQUEST, RESPONSE> getter,
|
io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter<
|
||||||
|
REQUEST, RESPONSE>
|
||||||
|
getter,
|
||||||
FallbackAddressPortExtractor<REQUEST> fallbackAddressPortExtractor,
|
FallbackAddressPortExtractor<REQUEST> fallbackAddressPortExtractor,
|
||||||
boolean emitOldHttpAttributes) {
|
boolean emitOldHttpAttributes) {
|
||||||
this.getter = getter;
|
this.getter = getter;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalClientAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalClientAttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,13 +33,12 @@ public final class ClientAttributesExtractor<REQUEST, RESPONSE>
|
||||||
private final InternalClientAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
|
private final InternalClientAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
|
||||||
|
|
||||||
ClientAttributesExtractor(ClientAttributesGetter<REQUEST, RESPONSE> getter) {
|
ClientAttributesExtractor(ClientAttributesGetter<REQUEST, RESPONSE> getter) {
|
||||||
// the ClientAttributesExtractor will always emit new semconv
|
|
||||||
internalExtractor =
|
internalExtractor =
|
||||||
new InternalClientAttributesExtractor<>(
|
new InternalClientAttributesExtractor<>(
|
||||||
getter,
|
getter,
|
||||||
FallbackAddressPortExtractor.noop(),
|
FallbackAddressPortExtractor.noop(),
|
||||||
/* emitStableUrlAttributes= */ true,
|
SemconvStability.emitStableHttpSemconv(),
|
||||||
/* emitOldHttpAttributes= */ false);
|
SemconvStability.emitOldHttpSemconv());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,6 +10,7 @@ import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalNetworkAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkTransportFilter;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.NetworkTransportFilter;
|
||||||
|
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,13 +33,12 @@ public final class NetworkAttributesExtractor<REQUEST, RESPONSE>
|
||||||
private final InternalNetworkAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
|
private final InternalNetworkAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
|
||||||
|
|
||||||
NetworkAttributesExtractor(NetworkAttributesGetter<REQUEST, RESPONSE> getter) {
|
NetworkAttributesExtractor(NetworkAttributesGetter<REQUEST, RESPONSE> getter) {
|
||||||
// the NetworkAttributesExtractor will always emit new semconv
|
|
||||||
internalExtractor =
|
internalExtractor =
|
||||||
new InternalNetworkAttributesExtractor<>(
|
new InternalNetworkAttributesExtractor<>(
|
||||||
getter,
|
getter,
|
||||||
NetworkTransportFilter.alwaysTrue(),
|
NetworkTransportFilter.alwaysTrue(),
|
||||||
/* emitStableUrlAttributes= */ true,
|
SemconvStability.emitStableHttpSemconv(),
|
||||||
/* emitOldHttpAttributes= */ false);
|
SemconvStability.emitOldHttpSemconv());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,6 +10,7 @@ import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,22 +27,38 @@ public final class ServerAttributesExtractor<REQUEST, RESPONSE>
|
||||||
*/
|
*/
|
||||||
public static <REQUEST, RESPONSE> ServerAttributesExtractor<REQUEST, RESPONSE> create(
|
public static <REQUEST, RESPONSE> ServerAttributesExtractor<REQUEST, RESPONSE> create(
|
||||||
ServerAttributesGetter<REQUEST, RESPONSE> getter) {
|
ServerAttributesGetter<REQUEST, RESPONSE> getter) {
|
||||||
return new ServerAttributesExtractor<>(getter);
|
return new ServerAttributesExtractor<>(getter, InternalServerAttributesExtractor.Mode.PEER);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new {@link ServerAttributesExtractor} that will use the passed {@link
|
||||||
|
* ServerAttributesGetter}.
|
||||||
|
*
|
||||||
|
* @deprecated This method will be removed in the 2.0 release. It was only introduced to ease the
|
||||||
|
* transition from using the old {@code NetServerAttributesGetter} to the new {@code
|
||||||
|
* ...network} attribute getter classes.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static <REQUEST, RESPONSE>
|
||||||
|
ServerAttributesExtractor<REQUEST, RESPONSE> createForServerSide(
|
||||||
|
ServerAttributesGetter<REQUEST, RESPONSE> getter) {
|
||||||
|
return new ServerAttributesExtractor<>(getter, InternalServerAttributesExtractor.Mode.HOST);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final InternalServerAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
|
private final InternalServerAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
|
||||||
|
|
||||||
ServerAttributesExtractor(ServerAttributesGetter<REQUEST, RESPONSE> getter) {
|
ServerAttributesExtractor(
|
||||||
|
ServerAttributesGetter<REQUEST, RESPONSE> getter,
|
||||||
|
InternalServerAttributesExtractor.Mode mode) {
|
||||||
// the ServerAttributesExtractor will always emit new semconv
|
// the ServerAttributesExtractor will always emit new semconv
|
||||||
internalExtractor =
|
internalExtractor =
|
||||||
new InternalServerAttributesExtractor<>(
|
new InternalServerAttributesExtractor<>(
|
||||||
getter,
|
getter,
|
||||||
(port, request) -> true,
|
(port, request) -> true,
|
||||||
FallbackAddressPortExtractor.noop(),
|
FallbackAddressPortExtractor.noop(),
|
||||||
/* emitStableUrlAttributes= */ true,
|
SemconvStability.emitStableHttpSemconv(),
|
||||||
/* emitOldHttpAttributes= */ false,
|
SemconvStability.emitOldHttpSemconv(),
|
||||||
// this param does not matter when old semconv is off
|
mode,
|
||||||
InternalServerAttributesExtractor.Mode.HOST,
|
|
||||||
/* captureServerSocketAttributes= */ true);
|
/* captureServerSocketAttributes= */ true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation") // testing deprecated class
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
class InetSocketAddressNetServerAttributesGetterTest {
|
class InetSocketAddressNetServerAttributesGetterTest {
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import javax.annotation.Nullable;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation") // testing deprecated class
|
||||||
class NetServerAttributesExtractorTest {
|
class NetServerAttributesExtractorTest {
|
||||||
|
|
||||||
static class TestNetServerAttributesGetter
|
static class TestNetServerAttributesGetter
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
/*
|
||||||
|
* 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.trace.attributes.SemanticAttributes;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getClientSocketAddress(Map<String, String> request, @Nullable Void response) {
|
||||||
|
return request.get("socketAddress");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Integer getClientSocketPort(Map<String, String> request, @Nullable Void response) {
|
||||||
|
String value = request.get("socketPort");
|
||||||
|
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");
|
||||||
|
request.put("socketAddress", "1.2.3.4");
|
||||||
|
request.put("socketPort", "8080");
|
||||||
|
|
||||||
|
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())
|
||||||
|
.containsOnly(
|
||||||
|
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4"),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_PEER_PORT, 8080L));
|
||||||
|
}
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,89 @@
|
||||||
|
/*
|
||||||
|
* 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.trace.attributes.SemanticAttributes;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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");
|
||||||
|
|
||||||
|
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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,129 @@
|
||||||
|
/*
|
||||||
|
* 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.trace.attributes.SemanticAttributes;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getServerSocketDomain(Map<String, String> request, @Nullable Void response) {
|
||||||
|
return request.get("socketDomain");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getServerSocketAddress(Map<String, String> request, @Nullable Void response) {
|
||||||
|
return request.get("socketAddress");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Integer getServerSocketPort(Map<String, String> request, @Nullable Void response) {
|
||||||
|
String port = request.get("socketPort");
|
||||||
|
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");
|
||||||
|
request.put("socketDomain", "proxy.opentelemetry.io");
|
||||||
|
request.put("socketAddress", "1.2.3.4");
|
||||||
|
request.put("socketPort", "8080");
|
||||||
|
|
||||||
|
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())
|
||||||
|
.containsOnly(
|
||||||
|
entry(SemanticAttributes.NET_SOCK_PEER_NAME, "proxy.opentelemetry.io"),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_PEER_ADDR, "1.2.3.4"),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_PEER_PORT, 8080L));
|
||||||
|
}
|
||||||
|
|
||||||
|
@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");
|
||||||
|
request.put("socketDomain", "proxy.opentelemetry.io");
|
||||||
|
request.put("socketAddress", "1.2.3.4");
|
||||||
|
request.put("socketPort", "8080");
|
||||||
|
|
||||||
|
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())
|
||||||
|
.containsOnly(
|
||||||
|
entry(SemanticAttributes.NET_SOCK_HOST_ADDR, "1.2.3.4"),
|
||||||
|
entry(SemanticAttributes.NET_SOCK_HOST_PORT, 8080L));
|
||||||
|
}
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ import java.util.Map;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation") // testing deprecated class
|
||||||
class NetServerAttributesExtractorBothSemconvTest {
|
class NetServerAttributesExtractorBothSemconvTest {
|
||||||
|
|
||||||
static class TestNetServerAttributesGetter
|
static class TestNetServerAttributesGetter
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.util.Map;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation") // testing deprecated class
|
||||||
class NetServerAttributesExtractorStableSemconvTest {
|
class NetServerAttributesExtractorStableSemconvTest {
|
||||||
|
|
||||||
static class TestNetServerAttributesGetter
|
static class TestNetServerAttributesGetter
|
||||||
|
|
|
@ -3,20 +3,17 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.instrumentation.apachedubbo.v2_7.internal;
|
package io.opentelemetry.instrumentation.apachedubbo.v2_7;
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboRequest;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.apache.dubbo.rpc.Result;
|
import org.apache.dubbo.rpc.Result;
|
||||||
|
|
||||||
/**
|
final class DubboNetworkServerAttributesGetter
|
||||||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
implements ServerAttributesGetter<DubboRequest, Result>,
|
||||||
* any time.
|
ClientAttributesGetter<DubboRequest, Result> {
|
||||||
*/
|
|
||||||
public final class DubboNetServerAttributesGetter
|
|
||||||
implements NetServerAttributesGetter<DubboRequest, Result> {
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
|
@ -30,17 +27,17 @@ public final class DubboNetServerAttributesGetter
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public InetSocketAddress getClientInetSocketAddress(
|
|
||||||
DubboRequest request, @Nullable Result result) {
|
|
||||||
return request.remoteAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public InetSocketAddress getServerInetSocketAddress(
|
public InetSocketAddress getServerInetSocketAddress(
|
||||||
DubboRequest request, @Nullable Result result) {
|
DubboRequest request, @Nullable Result result) {
|
||||||
return request.localAddress();
|
return request.localAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public InetSocketAddress getClientInetSocketAddress(
|
||||||
|
DubboRequest request, @Nullable Result result) {
|
||||||
|
return request.remoteAddress();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -8,13 +8,13 @@ package io.opentelemetry.instrumentation.apachedubbo.v2_7;
|
||||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
import io.opentelemetry.instrumentation.apachedubbo.v2_7.internal.DubboNetClientAttributesGetter;
|
import io.opentelemetry.instrumentation.apachedubbo.v2_7.internal.DubboNetClientAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.apachedubbo.v2_7.internal.DubboNetServerAttributesGetter;
|
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
|
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcServerAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcServerAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcSpanNameExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcSpanNameExtractor;
|
||||||
|
@ -57,18 +57,22 @@ public final class DubboTelemetryBuilder {
|
||||||
/**
|
/**
|
||||||
* Returns a new {@link DubboTelemetry} with the settings of this {@link DubboTelemetryBuilder}.
|
* Returns a new {@link DubboTelemetry} with the settings of this {@link DubboTelemetryBuilder}.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation") // using createForServerSide() for the old->stable semconv story
|
||||||
public DubboTelemetry build() {
|
public DubboTelemetry build() {
|
||||||
DubboRpcAttributesGetter rpcAttributesGetter = DubboRpcAttributesGetter.INSTANCE;
|
DubboRpcAttributesGetter rpcAttributesGetter = DubboRpcAttributesGetter.INSTANCE;
|
||||||
SpanNameExtractor<DubboRequest> spanNameExtractor =
|
SpanNameExtractor<DubboRequest> spanNameExtractor =
|
||||||
RpcSpanNameExtractor.create(rpcAttributesGetter);
|
RpcSpanNameExtractor.create(rpcAttributesGetter);
|
||||||
DubboNetClientAttributesGetter netClientAttributesGetter = new DubboNetClientAttributesGetter();
|
DubboNetClientAttributesGetter netClientAttributesGetter = new DubboNetClientAttributesGetter();
|
||||||
|
DubboNetworkServerAttributesGetter netServerAttributesGetter =
|
||||||
|
new DubboNetworkServerAttributesGetter();
|
||||||
|
|
||||||
InstrumenterBuilder<DubboRequest, Result> serverInstrumenterBuilder =
|
InstrumenterBuilder<DubboRequest, Result> serverInstrumenterBuilder =
|
||||||
Instrumenter.<DubboRequest, Result>builder(
|
Instrumenter.<DubboRequest, Result>builder(
|
||||||
openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor)
|
openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor)
|
||||||
.addAttributesExtractor(RpcServerAttributesExtractor.create(rpcAttributesGetter))
|
.addAttributesExtractor(RpcServerAttributesExtractor.create(rpcAttributesGetter))
|
||||||
.addAttributesExtractor(
|
.addAttributesExtractor(
|
||||||
NetServerAttributesExtractor.create(new DubboNetServerAttributesGetter()))
|
ServerAttributesExtractor.createForServerSide(netServerAttributesGetter))
|
||||||
|
.addAttributesExtractor(ClientAttributesExtractor.create(netServerAttributesGetter))
|
||||||
.addAttributesExtractors(attributesExtractors);
|
.addAttributesExtractors(attributesExtractors);
|
||||||
|
|
||||||
InstrumenterBuilder<DubboRequest, Result> clientInstrumenterBuilder =
|
InstrumenterBuilder<DubboRequest, Result> clientInstrumenterBuilder =
|
||||||
|
|
|
@ -3,21 +3,18 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.opentelemetry.instrumentation.grpc.v1_6.internal;
|
package io.opentelemetry.instrumentation.grpc.v1_6;
|
||||||
|
|
||||||
import io.grpc.Status;
|
import io.grpc.Status;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.grpc.v1_6.GrpcRequest;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
final class GrpcNetworkServerAttributesGetter
|
||||||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
|
implements ServerAttributesGetter<GrpcRequest, Status>,
|
||||||
* any time.
|
ClientAttributesGetter<GrpcRequest, Status> {
|
||||||
*/
|
|
||||||
public final class GrpcNetServerAttributesGetter
|
|
||||||
implements NetServerAttributesGetter<GrpcRequest, Status> {
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
|
@ -30,6 +27,14 @@ public final class GrpcNetServerAttributesGetter
|
||||||
return grpcRequest.getLogicalPort();
|
return grpcRequest.getLogicalPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public InetSocketAddress getServerInetSocketAddress(
|
||||||
|
GrpcRequest grpcRequest, @Nullable Status status) {
|
||||||
|
// TODO: later version introduces TRANSPORT_ATTR_LOCAL_ADDR, might be a good idea to use it
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public InetSocketAddress getClientInetSocketAddress(
|
public InetSocketAddress getClientInetSocketAddress(
|
||||||
|
@ -40,12 +45,4 @@ public final class GrpcNetServerAttributesGetter
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public InetSocketAddress getServerInetSocketAddress(
|
|
||||||
GrpcRequest grpcRequest, @Nullable Status status) {
|
|
||||||
// TODO: later version introduces TRANSPORT_ATTR_LOCAL_ADDR, might be a good idea to use it
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -14,13 +14,13 @@ import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.network.ClientAttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientMetrics;
|
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientMetrics;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcServerAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcServerAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcServerMetrics;
|
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcServerMetrics;
|
||||||
import io.opentelemetry.instrumentation.grpc.v1_6.internal.GrpcNetClientAttributesGetter;
|
import io.opentelemetry.instrumentation.grpc.v1_6.internal.GrpcNetClientAttributesGetter;
|
||||||
import io.opentelemetry.instrumentation.grpc.v1_6.internal.GrpcNetServerAttributesGetter;
|
|
||||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -149,6 +149,7 @@ public final class GrpcTelemetryBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a new {@link GrpcTelemetry} with the settings of this {@link GrpcTelemetryBuilder}. */
|
/** Returns a new {@link GrpcTelemetry} with the settings of this {@link GrpcTelemetryBuilder}. */
|
||||||
|
@SuppressWarnings("deprecation") // using createForServerSide() for the old->stable semconv story
|
||||||
public GrpcTelemetry build() {
|
public GrpcTelemetry build() {
|
||||||
SpanNameExtractor<GrpcRequest> originalSpanNameExtractor = new GrpcSpanNameExtractor();
|
SpanNameExtractor<GrpcRequest> originalSpanNameExtractor = new GrpcSpanNameExtractor();
|
||||||
|
|
||||||
|
@ -175,6 +176,8 @@ public final class GrpcTelemetryBuilder {
|
||||||
.addAttributesExtractors(additionalExtractors));
|
.addAttributesExtractors(additionalExtractors));
|
||||||
|
|
||||||
GrpcNetClientAttributesGetter netClientAttributesGetter = new GrpcNetClientAttributesGetter();
|
GrpcNetClientAttributesGetter netClientAttributesGetter = new GrpcNetClientAttributesGetter();
|
||||||
|
GrpcNetworkServerAttributesGetter netServerAttributesGetter =
|
||||||
|
new GrpcNetworkServerAttributesGetter();
|
||||||
GrpcRpcAttributesGetter rpcAttributesGetter = GrpcRpcAttributesGetter.INSTANCE;
|
GrpcRpcAttributesGetter rpcAttributesGetter = GrpcRpcAttributesGetter.INSTANCE;
|
||||||
|
|
||||||
clientInstrumenterBuilder
|
clientInstrumenterBuilder
|
||||||
|
@ -188,7 +191,8 @@ public final class GrpcTelemetryBuilder {
|
||||||
serverInstrumenterBuilder
|
serverInstrumenterBuilder
|
||||||
.addAttributesExtractor(RpcServerAttributesExtractor.create(rpcAttributesGetter))
|
.addAttributesExtractor(RpcServerAttributesExtractor.create(rpcAttributesGetter))
|
||||||
.addAttributesExtractor(
|
.addAttributesExtractor(
|
||||||
NetServerAttributesExtractor.create(new GrpcNetServerAttributesGetter()))
|
ServerAttributesExtractor.createForServerSide(netServerAttributesGetter))
|
||||||
|
.addAttributesExtractor(ClientAttributesExtractor.create(netServerAttributesGetter))
|
||||||
.addAttributesExtractor(
|
.addAttributesExtractor(
|
||||||
new GrpcAttributesExtractor(
|
new GrpcAttributesExtractor(
|
||||||
GrpcRpcAttributesGetter.INSTANCE, capturedServerRequestMetadata))
|
GrpcRpcAttributesGetter.INSTANCE, capturedServerRequestMetadata))
|
||||||
|
|
|
@ -10,11 +10,6 @@ import javax.annotation.Nullable;
|
||||||
|
|
||||||
public final class PulsarNetClientAttributesGetter
|
public final class PulsarNetClientAttributesGetter
|
||||||
implements NetClientAttributesGetter<BasePulsarRequest, Void> {
|
implements NetClientAttributesGetter<BasePulsarRequest, Void> {
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public String getTransport(BasePulsarRequest request, @Nullable Void unused) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -12,12 +12,6 @@ public enum VertxSqlClientNetAttributesGetter
|
||||||
implements NetClientAttributesGetter<VertxSqlClientRequest, Void> {
|
implements NetClientAttributesGetter<VertxSqlClientRequest, Void> {
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public String getTransport(VertxSqlClientRequest request, @Nullable Void unused) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getServerAddress(VertxSqlClientRequest request) {
|
public String getServerAddress(VertxSqlClientRequest request) {
|
||||||
|
|
Loading…
Reference in New Issue