-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split NetAttributesExtractor into NetClientAttributesExtractor and Ne…
…tServerAttributesExtractor (#4287) * Net Extractors * Either request or response but not both * Fix merge conflicts * Separate by OnStart/OnEnd * PeerServiceAttributes * Fix test * Restructure to client/server * Fix merge conflict in main * more * peer.service * Feedback * peer.service is only for clients * Fix merge conflict * rename * Armeria * peer.service is only for clients * rename * WIP * Sync Dubbo with Armeria * More Dubbo and Armeria * gRPC * Revert some Dubbo changes * more peer.service * Fix test * Fix merge * Fixes
- Loading branch information
Showing
77 changed files
with
835 additions
and
407 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...n/java/io/opentelemetry/instrumentation/api/instrumenter/ConstantAttributesExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.instrumenter; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.api.common.AttributesBuilder; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
final class ConstantAttributesExtractor<REQUEST, RESPONSE, T> | ||
extends AttributesExtractor<REQUEST, RESPONSE> { | ||
|
||
private final AttributeKey<T> attributeKey; | ||
private final T attributeValue; | ||
|
||
ConstantAttributesExtractor(AttributeKey<T> attributeKey, T attributeValue) { | ||
this.attributeKey = attributeKey; | ||
this.attributeValue = attributeValue; | ||
} | ||
|
||
@Override | ||
protected void onStart(AttributesBuilder attributes, REQUEST request) { | ||
attributes.put(attributeKey, attributeValue); | ||
} | ||
|
||
@Override | ||
protected void onEnd( | ||
AttributesBuilder attributes, | ||
REQUEST request, | ||
@Nullable RESPONSE response, | ||
@Nullable Throwable error) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...y/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.instrumenter.net; | ||
|
||
import java.net.InetAddress; | ||
import java.net.InetSocketAddress; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
/** | ||
* 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 | ||
* attributes</a> from a {@link InetSocketAddress}. Most network libraries will provide access to a | ||
* {@link InetSocketAddress} so this is a convenient alternative to {@link | ||
* NetServerAttributesExtractor}. There is no meaning to implement both in the same instrumentation. | ||
*/ | ||
public abstract class InetSocketAddressNetServerAttributesExtractor<REQUEST, RESPONSE> | ||
extends NetServerAttributesExtractor<REQUEST, RESPONSE> { | ||
|
||
@Nullable | ||
public abstract InetSocketAddress getAddress(REQUEST request); | ||
|
||
@Override | ||
@Nullable | ||
public final String peerName(REQUEST request) { | ||
InetSocketAddress address = getAddress(request); | ||
if (address == null) { | ||
return null; | ||
} | ||
if (address.getAddress() != null) { | ||
return address.getAddress().getHostName(); | ||
} | ||
return address.getHostString(); | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public final Integer peerPort(REQUEST request) { | ||
InetSocketAddress address = getAddress(request); | ||
if (address == null) { | ||
return null; | ||
} | ||
return address.getPort(); | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public final String peerIp(REQUEST request) { | ||
InetSocketAddress address = getAddress(request); | ||
if (address == null) { | ||
return null; | ||
} | ||
InetAddress remoteAddress = address.getAddress(); | ||
if (remoteAddress != null) { | ||
return remoteAddress.getHostAddress(); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...a/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.instrumenter.net; | ||
|
||
import io.opentelemetry.api.common.AttributesBuilder; | ||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; | ||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
/** | ||
* 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 | ||
* attributes</a>. It is common to have access to {@link java.net.InetSocketAddress}, in which case | ||
* it is more convenient to use {@link InetSocketAddressNetServerAttributesExtractor}. | ||
*/ | ||
public abstract class NetServerAttributesExtractor<REQUEST, RESPONSE> | ||
extends AttributesExtractor<REQUEST, RESPONSE> { | ||
|
||
@Override | ||
protected final void onStart(AttributesBuilder attributes, REQUEST request) { | ||
set(attributes, SemanticAttributes.NET_TRANSPORT, transport(request)); | ||
|
||
String peerIp = peerIp(request); | ||
String peerName = peerName(request); | ||
|
||
if (peerName != null && !peerName.equals(peerIp)) { | ||
set(attributes, SemanticAttributes.NET_PEER_NAME, peerName); | ||
} | ||
set(attributes, SemanticAttributes.NET_PEER_IP, peerIp); | ||
|
||
Integer peerPort = peerPort(request); | ||
if (peerPort != null) { | ||
set(attributes, SemanticAttributes.NET_PEER_PORT, (long) peerPort); | ||
} | ||
} | ||
|
||
@Override | ||
protected final void onEnd( | ||
AttributesBuilder attributes, | ||
REQUEST request, | ||
@Nullable RESPONSE response, | ||
@Nullable Throwable error) {} | ||
|
||
@Nullable | ||
public abstract String transport(REQUEST request); | ||
|
||
@Nullable | ||
public abstract String peerName(REQUEST request); | ||
|
||
@Nullable | ||
public abstract Integer peerPort(REQUEST request); | ||
|
||
@Nullable | ||
public abstract String peerIp(REQUEST request); | ||
} |
Oops, something went wrong.