-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Capture net.host.name for netty (open-telemetry#6892)
This may be a regression in 1.19.0 because you can no longer reconstruct the original url for netty server spans (previously `http.host` was captured which could be used).
- Loading branch information
Showing
31 changed files
with
357 additions
and
158 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
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
95 changes: 95 additions & 0 deletions
95
...y/instrumentation/api/instrumenter/net/internal/InternalNetServerAttributesExtractor.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,95 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.instrumenter.net.internal; | ||
|
||
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet; | ||
import static java.util.logging.Level.FINE; | ||
|
||
import io.opentelemetry.api.common.AttributesBuilder; | ||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; | ||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; | ||
import java.util.logging.Logger; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
public class InternalNetServerAttributesExtractor { | ||
|
||
private static final Logger logger = | ||
Logger.getLogger(InternalNetServerAttributesExtractor.class.getName()); | ||
|
||
public static <REQUEST> void onStart( | ||
NetServerAttributesGetter<REQUEST> getter, | ||
AttributesBuilder attributes, | ||
REQUEST request, | ||
@Nullable String hostHeader) { | ||
internalSet(attributes, SemanticAttributes.NET_TRANSPORT, getter.transport(request)); | ||
|
||
boolean setSockFamily = false; | ||
|
||
String sockPeerAddr = getter.sockPeerAddr(request); | ||
if (sockPeerAddr != null) { | ||
setSockFamily = true; | ||
|
||
internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_ADDR, sockPeerAddr); | ||
|
||
Integer sockPeerPort = getter.sockPeerPort(request); | ||
if (sockPeerPort != null && sockPeerPort > 0) { | ||
internalSet(attributes, SemanticAttributes.NET_SOCK_PEER_PORT, (long) sockPeerPort); | ||
} | ||
} | ||
|
||
String hostName = getter.hostName(request); | ||
Integer hostPort = getter.hostPort(request); | ||
|
||
int hostHeaderSeparator = -1; | ||
if (hostHeader != null) { | ||
hostHeaderSeparator = hostHeader.indexOf(':'); | ||
} | ||
if (hostName == null && hostHeader != null) { | ||
hostName = | ||
hostHeaderSeparator == -1 ? hostHeader : hostHeader.substring(0, hostHeaderSeparator); | ||
} | ||
if (hostPort == null && hostHeader != null && hostHeaderSeparator != -1) { | ||
try { | ||
hostPort = Integer.parseInt(hostHeader.substring(hostHeaderSeparator + 1)); | ||
} catch (NumberFormatException e) { | ||
logger.log(FINE, e.getMessage(), e); | ||
} | ||
} | ||
|
||
if (hostName != null) { | ||
internalSet(attributes, SemanticAttributes.NET_HOST_NAME, hostName); | ||
|
||
if (hostPort != null && hostPort > 0) { | ||
internalSet(attributes, SemanticAttributes.NET_HOST_PORT, (long) hostPort); | ||
} | ||
} | ||
|
||
String sockHostAddr = getter.sockHostAddr(request); | ||
if (sockHostAddr != null && !sockHostAddr.equals(hostName)) { | ||
setSockFamily = true; | ||
|
||
internalSet(attributes, SemanticAttributes.NET_SOCK_HOST_ADDR, sockHostAddr); | ||
|
||
Integer sockHostPort = getter.sockHostPort(request); | ||
if (sockHostPort != null && sockHostPort > 0 && !sockHostPort.equals(hostPort)) { | ||
internalSet(attributes, SemanticAttributes.NET_SOCK_HOST_PORT, (long) sockHostPort); | ||
} | ||
} | ||
|
||
if (setSockFamily) { | ||
String sockFamily = getter.sockFamily(request); | ||
if (sockFamily != null && !SemanticAttributes.NetSockFamilyValues.INET.equals(sockFamily)) { | ||
internalSet(attributes, SemanticAttributes.NET_SOCK_FAMILY, sockFamily); | ||
} | ||
} | ||
} | ||
|
||
private InternalNetServerAttributesExtractor() {} | ||
} |
Oops, something went wrong.