Skip to content

Commit 70317b5

Browse files
improve netProtocol performance for well-known protocols (open-telemetry#6845)
Co-authored-by: Robert Pająk <pellared@hotmail.com>
1 parent ed30671 commit 70317b5

File tree

14 files changed

+137
-13
lines changed

14 files changed

+137
-13
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ migration](https://github.com/open-telemetry/semantic-conventions/blob/main/docs
4848
The `code.namespace` attribute is no longer added. (#6870)
4949
- 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.
5050
The `code.namespace` attribute is no longer added. (#6870)
51+
- Improve performance by reducing allocations for common request protocols in the modules below. (#6845)
52+
- `go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful`
53+
- `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin`
54+
- `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux`
55+
- `go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho`
56+
- `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace`
57+
- `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`
5158

5259
### Deprecated
5360

instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/util.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,16 @@ func serverClientIP(xForwardedFor string) string {
7878

7979
func netProtocol(proto string) (name string, version string) {
8080
name, version, _ = strings.Cut(proto, "/")
81-
name = strings.ToLower(name)
81+
switch name {
82+
case "HTTP":
83+
name = "http"
84+
case "QUIC":
85+
name = "quic"
86+
case "SPDY":
87+
name = "spdy"
88+
default:
89+
name = strings.ToLower(name)
90+
}
8291
return name, version
8392
}
8493

instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconvutil/netconv.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ func splitHostPort(hostport string) (host string, port int) {
200200

201201
func netProtocol(proto string) (name string, version string) {
202202
name, version, _ = strings.Cut(proto, "/")
203-
name = strings.ToLower(name)
203+
switch name {
204+
case "HTTP":
205+
name = "http"
206+
case "QUIC":
207+
name = "quic"
208+
case "SPDY":
209+
name = "spdy"
210+
default:
211+
name = strings.ToLower(name)
212+
}
204213
return name, version
205214
}

instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/util.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,16 @@ func serverClientIP(xForwardedFor string) string {
7878

7979
func netProtocol(proto string) (name string, version string) {
8080
name, version, _ = strings.Cut(proto, "/")
81-
name = strings.ToLower(name)
81+
switch name {
82+
case "HTTP":
83+
name = "http"
84+
case "QUIC":
85+
name = "quic"
86+
case "SPDY":
87+
name = "spdy"
88+
default:
89+
name = strings.ToLower(name)
90+
}
8291
return name, version
8392
}
8493

instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconvutil/netconv.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ func splitHostPort(hostport string) (host string, port int) {
200200

201201
func netProtocol(proto string) (name string, version string) {
202202
name, version, _ = strings.Cut(proto, "/")
203-
name = strings.ToLower(name)
203+
switch name {
204+
case "HTTP":
205+
name = "http"
206+
case "QUIC":
207+
name = "quic"
208+
case "SPDY":
209+
name = "spdy"
210+
default:
211+
name = strings.ToLower(name)
212+
}
204213
return name, version
205214
}

instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/util.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,16 @@ func serverClientIP(xForwardedFor string) string {
7878

7979
func netProtocol(proto string) (name string, version string) {
8080
name, version, _ = strings.Cut(proto, "/")
81-
name = strings.ToLower(name)
81+
switch name {
82+
case "HTTP":
83+
name = "http"
84+
case "QUIC":
85+
name = "quic"
86+
case "SPDY":
87+
name = "spdy"
88+
default:
89+
name = strings.ToLower(name)
90+
}
8291
return name, version
8392
}
8493

instrumentation/github.com/gorilla/mux/otelmux/internal/semconvutil/netconv.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ func splitHostPort(hostport string) (host string, port int) {
200200

201201
func netProtocol(proto string) (name string, version string) {
202202
name, version, _ = strings.Cut(proto, "/")
203-
name = strings.ToLower(name)
203+
switch name {
204+
case "HTTP":
205+
name = "http"
206+
case "QUIC":
207+
name = "quic"
208+
case "SPDY":
209+
name = "spdy"
210+
default:
211+
name = strings.ToLower(name)
212+
}
204213
return name, version
205214
}

instrumentation/github.com/labstack/echo/otelecho/internal/semconvutil/netconv.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ func splitHostPort(hostport string) (host string, port int) {
200200

201201
func netProtocol(proto string) (name string, version string) {
202202
name, version, _ = strings.Cut(proto, "/")
203-
name = strings.ToLower(name)
203+
switch name {
204+
case "HTTP":
205+
name = "http"
206+
case "QUIC":
207+
name = "quic"
208+
case "SPDY":
209+
name = "spdy"
210+
default:
211+
name = strings.ToLower(name)
212+
}
204213
return name, version
205214
}

instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/util.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,16 @@ func serverClientIP(xForwardedFor string) string {
7878

7979
func netProtocol(proto string) (name string, version string) {
8080
name, version, _ = strings.Cut(proto, "/")
81-
name = strings.ToLower(name)
81+
switch name {
82+
case "HTTP":
83+
name = "http"
84+
case "QUIC":
85+
name = "quic"
86+
case "SPDY":
87+
name = "spdy"
88+
default:
89+
name = strings.ToLower(name)
90+
}
8291
return name, version
8392
}
8493

instrumentation/net/http/httptrace/otelhttptrace/internal/semconvutil/netconv.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ func splitHostPort(hostport string) (host string, port int) {
200200

201201
func netProtocol(proto string) (name string, version string) {
202202
name, version, _ = strings.Cut(proto, "/")
203-
name = strings.ToLower(name)
203+
switch name {
204+
case "HTTP":
205+
name = "http"
206+
case "QUIC":
207+
name = "quic"
208+
case "SPDY":
209+
name = "spdy"
210+
default:
211+
name = strings.ToLower(name)
212+
}
204213
return name, version
205214
}

0 commit comments

Comments
 (0)