mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-05-13 21:56:48 +02:00
fallback to URL.Host if Request.Host is empty (#2661)
* fallback to URL.Host if Request.Host is empty * changelog * previous versions
This commit is contained in:
parent
0e4c1563e9
commit
68e24958ff
@ -44,6 +44,7 @@ This update is a breaking change of the unstable Metrics API. Code instrumented
|
|||||||
- Unify path cleaning functionally in the `otlpmetric` and `otlptrace` config. (#2639)
|
- Unify path cleaning functionally in the `otlpmetric` and `otlptrace` config. (#2639)
|
||||||
- Change the debug message from the `sdk/trace.BatchSpanProcessor` to reflect the count is cumulative. (#2640)
|
- Change the debug message from the `sdk/trace.BatchSpanProcessor` to reflect the count is cumulative. (#2640)
|
||||||
- Introduce new internal envconfig package for OTLP exporters (#2608)
|
- Introduce new internal envconfig package for OTLP exporters (#2608)
|
||||||
|
- If `http.Request.Host` is empty, fall back to use `URL.Host` when populating `http.host` in the `semconv` packages. (#2661)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
@ -166,6 +166,8 @@ func httpBasicAttributesFromHTTPRequest(request *http.Request) []attribute.KeyVa
|
|||||||
|
|
||||||
if request.Host != "" {
|
if request.Host != "" {
|
||||||
attrs = append(attrs, HTTPHostKey.String(request.Host))
|
attrs = append(attrs, HTTPHostKey.String(request.Host))
|
||||||
|
} else if request.URL != nil && request.URL.Host != "" {
|
||||||
|
attrs = append(attrs, HTTPHostKey.String(request.URL.Host))
|
||||||
}
|
}
|
||||||
|
|
||||||
flavor := ""
|
flavor := ""
|
||||||
|
@ -705,6 +705,31 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) {
|
|||||||
attribute.String("http.host", "example.com"),
|
attribute.String("http.host", "example.com"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "with host fallback",
|
||||||
|
serverName: "my-server-name",
|
||||||
|
route: "/user/:id",
|
||||||
|
method: "GET",
|
||||||
|
requestURI: "/user/123",
|
||||||
|
proto: "HTTP/1.0",
|
||||||
|
remoteAddr: "",
|
||||||
|
host: "",
|
||||||
|
url: &url.URL{
|
||||||
|
Host: "example.com",
|
||||||
|
Path: "/user/123",
|
||||||
|
},
|
||||||
|
header: nil,
|
||||||
|
tls: withTLS,
|
||||||
|
expected: []attribute.KeyValue{
|
||||||
|
attribute.String("http.method", "GET"),
|
||||||
|
attribute.String("http.target", "/user/123"),
|
||||||
|
attribute.String("http.scheme", "https"),
|
||||||
|
attribute.String("http.flavor", "1.0"),
|
||||||
|
attribute.String("http.server_name", "my-server-name"),
|
||||||
|
attribute.String("http.route", "/user/:id"),
|
||||||
|
attribute.String("http.host", "example.com"),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "with user agent",
|
name: "with user agent",
|
||||||
serverName: "my-server-name",
|
serverName: "my-server-name",
|
||||||
@ -1042,6 +1067,28 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) {
|
|||||||
attribute.String("http.host", "example.com"),
|
attribute.String("http.host", "example.com"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "with host fallback",
|
||||||
|
method: "GET",
|
||||||
|
requestURI: "/user/123",
|
||||||
|
proto: "HTTP/1.0",
|
||||||
|
remoteAddr: "",
|
||||||
|
host: "",
|
||||||
|
url: &url.URL{
|
||||||
|
Scheme: "https",
|
||||||
|
Host: "example.com",
|
||||||
|
Path: "/user/123",
|
||||||
|
},
|
||||||
|
header: nil,
|
||||||
|
tls: withTLS,
|
||||||
|
expected: []attribute.KeyValue{
|
||||||
|
attribute.String("http.method", "GET"),
|
||||||
|
attribute.String("http.url", "https://example.com/user/123"),
|
||||||
|
attribute.String("http.scheme", "https"),
|
||||||
|
attribute.String("http.flavor", "1.0"),
|
||||||
|
attribute.String("http.host", "example.com"),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "with user agent",
|
name: "with user agent",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
@ -166,6 +166,8 @@ func httpBasicAttributesFromHTTPRequest(request *http.Request) []attribute.KeyVa
|
|||||||
|
|
||||||
if request.Host != "" {
|
if request.Host != "" {
|
||||||
attrs = append(attrs, HTTPHostKey.String(request.Host))
|
attrs = append(attrs, HTTPHostKey.String(request.Host))
|
||||||
|
} else if request.URL != nil && request.URL.Host != "" {
|
||||||
|
attrs = append(attrs, HTTPHostKey.String(request.URL.Host))
|
||||||
}
|
}
|
||||||
|
|
||||||
flavor := ""
|
flavor := ""
|
||||||
|
@ -705,6 +705,31 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) {
|
|||||||
attribute.String("http.host", "example.com"),
|
attribute.String("http.host", "example.com"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "with host fallback",
|
||||||
|
serverName: "my-server-name",
|
||||||
|
route: "/user/:id",
|
||||||
|
method: "GET",
|
||||||
|
requestURI: "/user/123",
|
||||||
|
proto: "HTTP/1.0",
|
||||||
|
remoteAddr: "",
|
||||||
|
host: "",
|
||||||
|
url: &url.URL{
|
||||||
|
Host: "example.com",
|
||||||
|
Path: "/user/123",
|
||||||
|
},
|
||||||
|
header: nil,
|
||||||
|
tls: withTLS,
|
||||||
|
expected: []attribute.KeyValue{
|
||||||
|
attribute.String("http.method", "GET"),
|
||||||
|
attribute.String("http.target", "/user/123"),
|
||||||
|
attribute.String("http.scheme", "https"),
|
||||||
|
attribute.String("http.flavor", "1.0"),
|
||||||
|
attribute.String("http.server_name", "my-server-name"),
|
||||||
|
attribute.String("http.route", "/user/:id"),
|
||||||
|
attribute.String("http.host", "example.com"),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "with user agent",
|
name: "with user agent",
|
||||||
serverName: "my-server-name",
|
serverName: "my-server-name",
|
||||||
@ -1042,6 +1067,28 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) {
|
|||||||
attribute.String("http.host", "example.com"),
|
attribute.String("http.host", "example.com"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "with host fallback",
|
||||||
|
method: "GET",
|
||||||
|
requestURI: "/user/123",
|
||||||
|
proto: "HTTP/1.0",
|
||||||
|
remoteAddr: "",
|
||||||
|
host: "",
|
||||||
|
url: &url.URL{
|
||||||
|
Scheme: "https",
|
||||||
|
Host: "example.com",
|
||||||
|
Path: "/user/123",
|
||||||
|
},
|
||||||
|
header: nil,
|
||||||
|
tls: withTLS,
|
||||||
|
expected: []attribute.KeyValue{
|
||||||
|
attribute.String("http.method", "GET"),
|
||||||
|
attribute.String("http.url", "https://example.com/user/123"),
|
||||||
|
attribute.String("http.scheme", "https"),
|
||||||
|
attribute.String("http.flavor", "1.0"),
|
||||||
|
attribute.String("http.host", "example.com"),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "with user agent",
|
name: "with user agent",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
@ -166,6 +166,8 @@ func httpBasicAttributesFromHTTPRequest(request *http.Request) []attribute.KeyVa
|
|||||||
|
|
||||||
if request.Host != "" {
|
if request.Host != "" {
|
||||||
attrs = append(attrs, HTTPHostKey.String(request.Host))
|
attrs = append(attrs, HTTPHostKey.String(request.Host))
|
||||||
|
} else if request.URL != nil && request.URL.Host != "" {
|
||||||
|
attrs = append(attrs, HTTPHostKey.String(request.URL.Host))
|
||||||
}
|
}
|
||||||
|
|
||||||
flavor := ""
|
flavor := ""
|
||||||
|
@ -704,6 +704,31 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) {
|
|||||||
attribute.String("http.host", "example.com"),
|
attribute.String("http.host", "example.com"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "with host fallback",
|
||||||
|
serverName: "my-server-name",
|
||||||
|
route: "/user/:id",
|
||||||
|
method: "GET",
|
||||||
|
requestURI: "/user/123",
|
||||||
|
proto: "HTTP/1.0",
|
||||||
|
remoteAddr: "",
|
||||||
|
host: "",
|
||||||
|
url: &url.URL{
|
||||||
|
Host: "example.com",
|
||||||
|
Path: "/user/123",
|
||||||
|
},
|
||||||
|
header: nil,
|
||||||
|
tls: withTLS,
|
||||||
|
expected: []attribute.KeyValue{
|
||||||
|
attribute.String("http.method", "GET"),
|
||||||
|
attribute.String("http.target", "/user/123"),
|
||||||
|
attribute.String("http.scheme", "https"),
|
||||||
|
attribute.String("http.flavor", "1.0"),
|
||||||
|
attribute.String("http.server_name", "my-server-name"),
|
||||||
|
attribute.String("http.route", "/user/:id"),
|
||||||
|
attribute.String("http.host", "example.com"),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "with user agent",
|
name: "with user agent",
|
||||||
serverName: "my-server-name",
|
serverName: "my-server-name",
|
||||||
@ -1041,6 +1066,28 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) {
|
|||||||
attribute.String("http.host", "example.com"),
|
attribute.String("http.host", "example.com"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "with host fallback",
|
||||||
|
method: "GET",
|
||||||
|
requestURI: "/user/123",
|
||||||
|
proto: "HTTP/1.0",
|
||||||
|
remoteAddr: "",
|
||||||
|
host: "",
|
||||||
|
url: &url.URL{
|
||||||
|
Scheme: "https",
|
||||||
|
Host: "example.com",
|
||||||
|
Path: "/user/123",
|
||||||
|
},
|
||||||
|
header: nil,
|
||||||
|
tls: withTLS,
|
||||||
|
expected: []attribute.KeyValue{
|
||||||
|
attribute.String("http.method", "GET"),
|
||||||
|
attribute.String("http.url", "https://example.com/user/123"),
|
||||||
|
attribute.String("http.scheme", "https"),
|
||||||
|
attribute.String("http.flavor", "1.0"),
|
||||||
|
attribute.String("http.host", "example.com"),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "with user agent",
|
name: "with user agent",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
@ -167,6 +167,8 @@ func httpBasicAttributesFromHTTPRequest(request *http.Request) []attribute.KeyVa
|
|||||||
|
|
||||||
if request.Host != "" {
|
if request.Host != "" {
|
||||||
attrs = append(attrs, HTTPHostKey.String(request.Host))
|
attrs = append(attrs, HTTPHostKey.String(request.Host))
|
||||||
|
} else if request.URL != nil && request.URL.Host != "" {
|
||||||
|
attrs = append(attrs, HTTPHostKey.String(request.URL.Host))
|
||||||
}
|
}
|
||||||
|
|
||||||
flavor := ""
|
flavor := ""
|
||||||
|
@ -705,6 +705,31 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) {
|
|||||||
attribute.String("http.host", "example.com"),
|
attribute.String("http.host", "example.com"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "with host fallback",
|
||||||
|
serverName: "my-server-name",
|
||||||
|
route: "/user/:id",
|
||||||
|
method: "GET",
|
||||||
|
requestURI: "/user/123",
|
||||||
|
proto: "HTTP/1.0",
|
||||||
|
remoteAddr: "",
|
||||||
|
host: "",
|
||||||
|
url: &url.URL{
|
||||||
|
Host: "example.com",
|
||||||
|
Path: "/user/123",
|
||||||
|
},
|
||||||
|
header: nil,
|
||||||
|
tls: withTLS,
|
||||||
|
expected: []attribute.KeyValue{
|
||||||
|
attribute.String("http.method", "GET"),
|
||||||
|
attribute.String("http.target", "/user/123"),
|
||||||
|
attribute.String("http.scheme", "https"),
|
||||||
|
attribute.String("http.flavor", "1.0"),
|
||||||
|
attribute.String("http.server_name", "my-server-name"),
|
||||||
|
attribute.String("http.route", "/user/:id"),
|
||||||
|
attribute.String("http.host", "example.com"),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "with user agent",
|
name: "with user agent",
|
||||||
serverName: "my-server-name",
|
serverName: "my-server-name",
|
||||||
@ -1042,6 +1067,28 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) {
|
|||||||
attribute.String("http.host", "example.com"),
|
attribute.String("http.host", "example.com"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "with host fallback",
|
||||||
|
method: "GET",
|
||||||
|
requestURI: "/user/123",
|
||||||
|
proto: "HTTP/1.0",
|
||||||
|
remoteAddr: "",
|
||||||
|
host: "",
|
||||||
|
url: &url.URL{
|
||||||
|
Scheme: "https",
|
||||||
|
Host: "example.com",
|
||||||
|
Path: "/user/123",
|
||||||
|
},
|
||||||
|
header: nil,
|
||||||
|
tls: withTLS,
|
||||||
|
expected: []attribute.KeyValue{
|
||||||
|
attribute.String("http.method", "GET"),
|
||||||
|
attribute.String("http.url", "https://example.com/user/123"),
|
||||||
|
attribute.String("http.scheme", "https"),
|
||||||
|
attribute.String("http.flavor", "1.0"),
|
||||||
|
attribute.String("http.host", "example.com"),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "with user agent",
|
name: "with user agent",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user