From d3a11269fc3fd6bf010e02e693cf9d816a482f60 Mon Sep 17 00:00:00 2001
From: Kason Braley <kbraley9@gmail.com>
Date: Thu, 10 Oct 2024 16:00:19 -0700
Subject: [PATCH 1/2] Use non-deprecated span attributes

- `net.peer.name` -> replaced with `server.address` on client spans and `client.address` on server spans.
- `net.peer.port` -> replaced with `server.port` on client spans and `client.port` on server spans.
- `http.status_code` -> replaced with `http.response.status_code`.

Signed-off-by: Kason Braley <kbraley9@gmail.com>
---
 attributes.go | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/attributes.go b/attributes.go
index f284821..d617049 100644
--- a/attributes.go
+++ b/attributes.go
@@ -74,7 +74,7 @@ func procedureAttributes(procedure string) []attribute.KeyValue {
 func requestAttributes(spec connect.Spec, peer connect.Peer) []attribute.KeyValue {
 	var attrs []attribute.KeyValue
 	if addr := peer.Addr; addr != "" {
-		attrs = append(attrs, addressAttributes(addr)...)
+		attrs = append(attrs, addressAttributes(spec, addr)...)
 	}
 	name := strings.TrimLeft(spec.Procedure, "/")
 	protocol := protocolToSemConv(peer.Protocol)
@@ -83,17 +83,26 @@ func requestAttributes(spec connect.Spec, peer connect.Peer) []attribute.KeyValu
 	return attrs
 }
 
-func addressAttributes(address string) []attribute.KeyValue {
+func addressAttributes(spec connect.Spec, address string) []attribute.KeyValue {
 	if host, port, err := net.SplitHostPort(address); err == nil {
 		portInt, err := strconv.Atoi(port)
 		if err == nil {
+			if spec.IsClient {
+				return []attribute.KeyValue{
+					semconv.ServerAddressKey.String(host),
+					semconv.ServerPortKey.Int(portInt),
+				}
+			}
 			return []attribute.KeyValue{
-				semconv.NetPeerNameKey.String(host),
-				semconv.NetPeerPortKey.Int(portInt),
+				semconv.ClientAddressKey.String(host),
+				semconv.ClientPortKey.Int(portInt),
 			}
 		}
 	}
-	return []attribute.KeyValue{semconv.NetPeerNameKey.String(address)}
+	if spec.IsClient {
+		return []attribute.KeyValue{semconv.ServerAddressKey.String(address)}
+	}
+	return []attribute.KeyValue{semconv.ClientAddressKey.String(address)}
 }
 
 func statusCodeAttribute(protocol string, serverErr error) (attribute.KeyValue, bool) {
@@ -111,7 +120,7 @@ func statusCodeAttribute(protocol string, serverErr error) (attribute.KeyValue,
 			// A "not modified" error is special: it's code is technically "unknown" but
 			// it would be misleading to label it as an unknown error since it's not really
 			// an error, but rather a sentinel to trigger a "304 Not Modified" HTTP status.
-			return semconv.HTTPStatusCodeKey.Int(http.StatusNotModified), true
+			return semconv.HTTPResponseStatusCodeKey.Int(http.StatusNotModified), true
 		}
 		codeKey := attribute.Key("rpc." + protocol + ".error_code")
 		if serverErr != nil {

From 9805b2c96c3bc4ac78c8ac73e968de09ee37d316 Mon Sep 17 00:00:00 2001
From: Kason Braley <kbraley9@gmail.com>
Date: Fri, 11 Oct 2024 10:26:32 -0700
Subject: [PATCH 2/2] Keep deprecated NetPeer attributes for backwards compat

---
 attributes.go | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/attributes.go b/attributes.go
index d617049..edc1bc5 100644
--- a/attributes.go
+++ b/attributes.go
@@ -91,18 +91,32 @@ func addressAttributes(spec connect.Spec, address string) []attribute.KeyValue {
 				return []attribute.KeyValue{
 					semconv.ServerAddressKey.String(host),
 					semconv.ServerPortKey.Int(portInt),
+					// Deprecated, but kept for backwards compatibility.
+					semconv.NetPeerNameKey.String(host),
+					semconv.NetPeerPortKey.Int(portInt),
 				}
 			}
 			return []attribute.KeyValue{
 				semconv.ClientAddressKey.String(host),
 				semconv.ClientPortKey.Int(portInt),
+				// Deprecated, but kept for backwards compatibility.
+				semconv.NetPeerNameKey.String(host),
+				semconv.NetPeerPortKey.Int(portInt),
 			}
 		}
 	}
 	if spec.IsClient {
-		return []attribute.KeyValue{semconv.ServerAddressKey.String(address)}
+		return []attribute.KeyValue{
+			semconv.ServerAddressKey.String(address),
+			// Deprecated, but kept for backwards compatibility.
+			semconv.NetPeerNameKey.String(address),
+		}
+	}
+	return []attribute.KeyValue{
+		semconv.ClientAddressKey.String(address),
+		// Deprecated, but kept for backwards compatibility.
+		semconv.NetPeerNameKey.String(address),
 	}
-	return []attribute.KeyValue{semconv.ClientAddressKey.String(address)}
 }
 
 func statusCodeAttribute(protocol string, serverErr error) (attribute.KeyValue, bool) {