Skip to content

Commit 7b74959

Browse files
authored
Remove http.target attr from ServerRequest (#3687)
* Remove http.target attr from ServerRequest * Update changelog * Remove trailing space in changelog
1 parent 0446207 commit 7b74959

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1313
- Attribute `KeyValue` creations functions to `go.opentelemetry.io/otel/semconv/v1.17.0` for all non-enum semantic conventions.
1414
These functions ensure semantic convention type correctness.
1515

16+
### Fixed
17+
18+
- Removed the `http.target` attribute from being added by `ServerRequest` in the following packages. (#3687)
19+
- `go.opentelemetry.io/otel/semconv/v1.13.0/httpconv`
20+
- `go.opentelemetry.io/otel/semconv/v1.14.0/httpconv`
21+
- `go.opentelemetry.io/otel/semconv/v1.15.0/httpconv`
22+
- `go.opentelemetry.io/otel/semconv/v1.16.0/httpconv`
23+
- `go.opentelemetry.io/otel/semconv/v1.17.0/httpconv`
24+
1625
### Removed
1726

1827
- The deprecated `go.opentelemetry.io/otel/metric/instrument/asyncfloat64` package is removed. (#3631)

semconv/internal/v2/http.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,14 @@ func (c *HTTPConv) ClientRequest(req *http.Request) []attribute.KeyValue {
157157
// "net.sock.peer.addr", "net.sock.peer.port", "http.user_agent", "enduser.id",
158158
// "http.client_ip".
159159
func (c *HTTPConv) ServerRequest(server string, req *http.Request) []attribute.KeyValue {
160-
n := 5 // Method, scheme, target, proto, and host name.
160+
// TODO: This currently does not add the specification required
161+
// `http.target` attribute. It has too high of a cardinality to safely be
162+
// added. An alternate should be added, or this comment removed, when it is
163+
// addressed by the specification. If it is ultimately decided to continue
164+
// not including the attribute, the HTTPTargetKey field of the HTTPConv
165+
// should be removed as well.
166+
167+
n := 4 // Method, scheme, proto, and host name.
161168
var host string
162169
var p int
163170
if server == "" {
@@ -199,14 +206,6 @@ func (c *HTTPConv) ServerRequest(server string, req *http.Request) []attribute.K
199206
attrs = append(attrs, c.proto(req.Proto))
200207
attrs = append(attrs, c.NetConv.HostName(host))
201208

202-
if req.URL != nil {
203-
attrs = append(attrs, c.HTTPTargetKey.String(req.URL.RequestURI()))
204-
} else {
205-
// This should never occur if the request was generated by the net/http
206-
// package. Fail gracefully, if it does though.
207-
attrs = append(attrs, c.HTTPTargetKey.String(req.RequestURI))
208-
}
209-
210209
if hostPort > 0 {
211210
attrs = append(attrs, c.NetConv.HostPort(hostPort))
212211
}

semconv/internal/v2/http_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ func TestHTTPServerRequest(t *testing.T) {
167167
assert.ElementsMatch(t,
168168
[]attribute.KeyValue{
169169
attribute.String("http.method", "GET"),
170-
attribute.String("http.target", "/"),
171170
attribute.String("http.scheme", "http"),
172171
attribute.String("http.flavor", "1.1"),
173172
attribute.String("net.host.name", srvURL.Hostname()),
@@ -208,7 +207,6 @@ func TestHTTPServerRequestFailsGracefully(t *testing.T) {
208207
assert.NotPanics(t, func() { got = hc.ServerRequest("", req) })
209208
want := []attribute.KeyValue{
210209
attribute.String("http.method", "GET"),
211-
attribute.String("http.target", ""),
212210
attribute.String("http.scheme", "http"),
213211
attribute.String("http.flavor", ""),
214212
attribute.String("net.host.name", ""),

0 commit comments

Comments
 (0)