diff --git a/CHANGELOG.md b/CHANGELOG.md index 87ebe40fb4d..29aad168890 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,13 @@ migration](https://github.com/open-telemetry/semantic-conventions/blob/main/docs The `code.namespace` attribute is no longer added. (#6870) - The `code.function` attribute emitted by `go.opentelemetry.io/contrib/bridges/otelzap` now stores the package path-qualified function name instead of just the function name. The `code.namespace` attribute is no longer added. (#6870) +- Improve performance by reducing allocations for common request protocols in the modules below. (#6845) + - `go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful` + - `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin` + - `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux` + - `go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho` + - `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace` + - `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` ### Deprecated diff --git a/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/util.go b/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/util.go index b28d5ea5405..4bd0e1bc2a3 100644 --- a/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/util.go +++ b/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/util.go @@ -78,7 +78,16 @@ func serverClientIP(xForwardedFor string) string { func netProtocol(proto string) (name string, version string) { name, version, _ = strings.Cut(proto, "/") - name = strings.ToLower(name) + switch name { + case "HTTP": + name = "http" + case "QUIC": + name = "quic" + case "SPDY": + name = "spdy" + default: + name = strings.ToLower(name) + } return name, version } diff --git a/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconvutil/netconv.go b/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconvutil/netconv.go index 75a51e0de41..9dccf349c57 100644 --- a/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconvutil/netconv.go +++ b/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconvutil/netconv.go @@ -200,6 +200,15 @@ func splitHostPort(hostport string) (host string, port int) { func netProtocol(proto string) (name string, version string) { name, version, _ = strings.Cut(proto, "/") - name = strings.ToLower(name) + switch name { + case "HTTP": + name = "http" + case "QUIC": + name = "quic" + case "SPDY": + name = "spdy" + default: + name = strings.ToLower(name) + } return name, version } diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/util.go b/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/util.go index c97c1bc00fb..0ac571f7e21 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/util.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/util.go @@ -78,7 +78,16 @@ func serverClientIP(xForwardedFor string) string { func netProtocol(proto string) (name string, version string) { name, version, _ = strings.Cut(proto, "/") - name = strings.ToLower(name) + switch name { + case "HTTP": + name = "http" + case "QUIC": + name = "quic" + case "SPDY": + name = "spdy" + default: + name = strings.ToLower(name) + } return name, version } diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconvutil/netconv.go b/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconvutil/netconv.go index 7a1530a310d..f4ebbf28c8e 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconvutil/netconv.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconvutil/netconv.go @@ -200,6 +200,15 @@ func splitHostPort(hostport string) (host string, port int) { func netProtocol(proto string) (name string, version string) { name, version, _ = strings.Cut(proto, "/") - name = strings.ToLower(name) + switch name { + case "HTTP": + name = "http" + case "QUIC": + name = "quic" + case "SPDY": + name = "spdy" + default: + name = strings.ToLower(name) + } return name, version } diff --git a/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/util.go b/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/util.go index 6a4e0a93b63..5b8b64d7db8 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/util.go +++ b/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/util.go @@ -78,7 +78,16 @@ func serverClientIP(xForwardedFor string) string { func netProtocol(proto string) (name string, version string) { name, version, _ = strings.Cut(proto, "/") - name = strings.ToLower(name) + switch name { + case "HTTP": + name = "http" + case "QUIC": + name = "quic" + case "SPDY": + name = "spdy" + default: + name = strings.ToLower(name) + } return name, version } diff --git a/instrumentation/github.com/gorilla/mux/otelmux/internal/semconvutil/netconv.go b/instrumentation/github.com/gorilla/mux/otelmux/internal/semconvutil/netconv.go index 53602bacb46..020c4124537 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/internal/semconvutil/netconv.go +++ b/instrumentation/github.com/gorilla/mux/otelmux/internal/semconvutil/netconv.go @@ -200,6 +200,15 @@ func splitHostPort(hostport string) (host string, port int) { func netProtocol(proto string) (name string, version string) { name, version, _ = strings.Cut(proto, "/") - name = strings.ToLower(name) + switch name { + case "HTTP": + name = "http" + case "QUIC": + name = "quic" + case "SPDY": + name = "spdy" + default: + name = strings.ToLower(name) + } return name, version } diff --git a/instrumentation/github.com/labstack/echo/otelecho/internal/semconvutil/netconv.go b/instrumentation/github.com/labstack/echo/otelecho/internal/semconvutil/netconv.go index c4f54bdc8ec..06c8f80d5bc 100644 --- a/instrumentation/github.com/labstack/echo/otelecho/internal/semconvutil/netconv.go +++ b/instrumentation/github.com/labstack/echo/otelecho/internal/semconvutil/netconv.go @@ -200,6 +200,15 @@ func splitHostPort(hostport string) (host string, port int) { func netProtocol(proto string) (name string, version string) { name, version, _ = strings.Cut(proto, "/") - name = strings.ToLower(name) + switch name { + case "HTTP": + name = "http" + case "QUIC": + name = "quic" + case "SPDY": + name = "spdy" + default: + name = strings.ToLower(name) + } return name, version } diff --git a/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/util.go b/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/util.go index a34e0a0dc5d..78c3c374fc7 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/util.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/util.go @@ -78,7 +78,16 @@ func serverClientIP(xForwardedFor string) string { func netProtocol(proto string) (name string, version string) { name, version, _ = strings.Cut(proto, "/") - name = strings.ToLower(name) + switch name { + case "HTTP": + name = "http" + case "QUIC": + name = "quic" + case "SPDY": + name = "spdy" + default: + name = strings.ToLower(name) + } return name, version } diff --git a/instrumentation/net/http/httptrace/otelhttptrace/internal/semconvutil/netconv.go b/instrumentation/net/http/httptrace/otelhttptrace/internal/semconvutil/netconv.go index 45d8cba6710..a5cdc3b3361 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/internal/semconvutil/netconv.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/internal/semconvutil/netconv.go @@ -200,6 +200,15 @@ func splitHostPort(hostport string) (host string, port int) { func netProtocol(proto string) (name string, version string) { name, version, _ = strings.Cut(proto, "/") - name = strings.ToLower(name) + switch name { + case "HTTP": + name = "http" + case "QUIC": + name = "quic" + case "SPDY": + name = "spdy" + default: + name = strings.ToLower(name) + } return name, version } diff --git a/instrumentation/net/http/otelhttp/internal/semconv/util.go b/instrumentation/net/http/otelhttp/internal/semconv/util.go index 558efd0594b..315d3dd29cd 100644 --- a/instrumentation/net/http/otelhttp/internal/semconv/util.go +++ b/instrumentation/net/http/otelhttp/internal/semconv/util.go @@ -78,7 +78,16 @@ func serverClientIP(xForwardedFor string) string { func netProtocol(proto string) (name string, version string) { name, version, _ = strings.Cut(proto, "/") - name = strings.ToLower(name) + switch name { + case "HTTP": + name = "http" + case "QUIC": + name = "quic" + case "SPDY": + name = "spdy" + default: + name = strings.ToLower(name) + } return name, version } diff --git a/instrumentation/net/http/otelhttp/internal/semconvutil/netconv.go b/instrumentation/net/http/otelhttp/internal/semconvutil/netconv.go index b80a1db61fa..de74fa252a9 100644 --- a/instrumentation/net/http/otelhttp/internal/semconvutil/netconv.go +++ b/instrumentation/net/http/otelhttp/internal/semconvutil/netconv.go @@ -200,6 +200,15 @@ func splitHostPort(hostport string) (host string, port int) { func netProtocol(proto string) (name string, version string) { name, version, _ = strings.Cut(proto, "/") - name = strings.ToLower(name) + switch name { + case "HTTP": + name = "http" + case "QUIC": + name = "quic" + case "SPDY": + name = "spdy" + default: + name = strings.ToLower(name) + } return name, version } diff --git a/internal/shared/semconv/util.go.tmpl b/internal/shared/semconv/util.go.tmpl index 27b9fa60ccb..20daf9d30ca 100644 --- a/internal/shared/semconv/util.go.tmpl +++ b/internal/shared/semconv/util.go.tmpl @@ -78,7 +78,16 @@ func serverClientIP(xForwardedFor string) string { func netProtocol(proto string) (name string, version string) { name, version, _ = strings.Cut(proto, "/") - name = strings.ToLower(name) + switch name { + case "HTTP": + name = "http" + case "QUIC": + name = "quic" + case "SPDY": + name = "spdy" + default: + name = strings.ToLower(name) + } return name, version } diff --git a/internal/shared/semconvutil/netconv.go.tmpl b/internal/shared/semconvutil/netconv.go.tmpl index 45a96c34f78..e7a9bd81f33 100644 --- a/internal/shared/semconvutil/netconv.go.tmpl +++ b/internal/shared/semconvutil/netconv.go.tmpl @@ -200,6 +200,15 @@ func splitHostPort(hostport string) (host string, port int) { func netProtocol(proto string) (name string, version string) { name, version, _ = strings.Cut(proto, "/") - name = strings.ToLower(name) + switch name { + case "HTTP": + name = "http" + case "QUIC": + name = "quic" + case "SPDY": + name = "spdy" + default: + name = strings.ToLower(name) + } return name, version }