Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net.peer.ip not filled for IPv6 #2283

Closed
garthk opened this issue Oct 11, 2021 · 0 comments · Fixed by #2285
Closed

net.peer.ip not filled for IPv6 #2283

garthk opened this issue Oct 11, 2021 · 0 comments · Fixed by #2285
Assignees
Labels
bug Something isn't working
Projects

Comments

@garthk
Copy link
Contributor

garthk commented Oct 11, 2021

Description

Spec check: should net.client.ip be filled consistently for both IPv4 and IPv6?

Environment

  • OS: Any
  • Architecture: Any
  • Go Version: 1.15
  • opentelemetry-go version: 1.0.1

Steps To Reproduce

  1. Fire up any “hello, world” implementation on port 8090
  2. Make requests via HTTP and HTTPS, eg. curl -4 :8090 and curl -6 :8090
  3. Observe net.peer.ip is populated for IPv4 ("127.0.0.1") but not for IPv6
  4. Observe net.peer.name is populated for IPv6 ("[::1]") but not for IPv4

Expected behavior

I expect net.peer.ip to contain the network peer IP address for both IPv4 and IPv6.

In the IPv6 case, r.RemoteAddr is "[::1]:54321" matching RFC 5952's Notes on Combining IPv6 Addresses with Port Numbers. net.SplitHostPort splits that to {"::1", "54321"} but we're not using it. Rather, we're using strings.LastIndexOf and trusting net.ParseIP will handle [::1]. It doesn't, so we end up with net.peer.name set to [::1] and net.peer.ip absent:

peerName, peerIP, peerPort := "", "", 0
{
hostPart := request.RemoteAddr
portPart := ""
if idx := strings.LastIndex(hostPart, ":"); idx >= 0 {
hostPart = request.RemoteAddr[:idx]
portPart = request.RemoteAddr[idx+1:]
}
if hostPart != "" {
if ip := net.ParseIP(hostPart); ip != nil {
peerIP = ip.String()
} else {
peerName = hostPart
}
if portPart != "" {
numPort, err := strconv.ParseUint(portPart, 10, 16)
if err == nil {
peerPort = (int)(numPort)
} else {
peerName, peerIP = "", ""
}
}
}
}

@garthk garthk added the bug Something isn't working label Oct 11, 2021
@MrAlias MrAlias added this to Needs triage in Bugs via automation Oct 11, 2021
@MrAlias MrAlias moved this from Needs triage to Low priority in Bugs Oct 11, 2021
@MrAlias MrAlias added the help wanted Extra attention is needed label Oct 11, 2021
evantorrie added a commit to evantorrie/opentelemetry-go that referenced this issue Oct 13, 2021
@evantorrie evantorrie self-assigned this Oct 13, 2021
@evantorrie evantorrie removed the help wanted Extra attention is needed label Oct 13, 2021
Bugs automation moved this from Low priority to Closed Oct 18, 2021
MrAlias added a commit that referenced this issue Oct 18, 2021
* Fix IPv6 handling errors in semconv.NetAttributesFromHTTPRequest

fixes #2283

* Enter PR number in CHANGELOG

* Remove unnecessary creation and then assignment

Standardize order of checks for IP, Name, Port

* Assume happy path when parsing host and port

i.e. assume net.SplitHostPort(input) will succeed

* Get rid of uint64 for port

* Fix git merge of main by adding back strings import

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Bugs
  
Closed
Development

Successfully merging a pull request may close this issue.

3 participants