Skip to content

Commit

Permalink
previous versions
Browse files Browse the repository at this point in the history
  • Loading branch information
nelzkiddom committed Mar 8, 2022
1 parent 7447e10 commit 08f1656
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 0 deletions.
2 changes: 2 additions & 0 deletions semconv/v1.4.0/http.go
Expand Up @@ -166,6 +166,8 @@ func httpBasicAttributesFromHTTPRequest(request *http.Request) []attribute.KeyVa

if 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 := ""
Expand Down
47 changes: 47 additions & 0 deletions semconv/v1.4.0/http_test.go
Expand Up @@ -705,6 +705,31 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) {
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",
serverName: "my-server-name",
Expand Down Expand Up @@ -1042,6 +1067,28 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) {
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",
method: "GET",
Expand Down
2 changes: 2 additions & 0 deletions semconv/v1.5.0/http.go
Expand Up @@ -166,6 +166,8 @@ func httpBasicAttributesFromHTTPRequest(request *http.Request) []attribute.KeyVa

if 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 := ""
Expand Down
47 changes: 47 additions & 0 deletions semconv/v1.5.0/http_test.go
Expand Up @@ -705,6 +705,31 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) {
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",
serverName: "my-server-name",
Expand Down Expand Up @@ -1042,6 +1067,28 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) {
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",
method: "GET",
Expand Down
2 changes: 2 additions & 0 deletions semconv/v1.6.1/http.go
Expand Up @@ -166,6 +166,8 @@ func httpBasicAttributesFromHTTPRequest(request *http.Request) []attribute.KeyVa

if 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 := ""
Expand Down
47 changes: 47 additions & 0 deletions semconv/v1.6.1/http_test.go
Expand Up @@ -704,6 +704,31 @@ func TestHTTPServerAttributesFromHTTPRequest(t *testing.T) {
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",
serverName: "my-server-name",
Expand Down Expand Up @@ -1041,6 +1066,28 @@ func TestHTTPClientAttributesFromHTTPRequest(t *testing.T) {
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",
method: "GET",
Expand Down

0 comments on commit 08f1656

Please sign in to comment.