New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP Semconv migration Part3 Server - v1.24.0 support #5401
base: main
Are you sure you want to change the base?
HTTP Semconv migration Part3 Server - v1.24.0 support #5401
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5401 +/- ##
=======================================
+ Coverage 62.3% 62.5% +0.1%
=======================================
Files 189 190 +1
Lines 11575 11673 +98
=======================================
+ Hits 7221 7296 +75
- Misses 4145 4161 +16
- Partials 209 216 +7
|
Changelog will be part of follow on PR as part of #5331 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use a few more test cases, but LGTM otherwise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is missing test coverage.
// If the primary server name is not known, server should be an empty string. | ||
// The req Host will be used to determine the server instead. | ||
func (n newHTTPServer) RequestTraceAttrs(server string, req *http.Request) []attribute.KeyValue { | ||
const MaxAttributes = 11 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const MaxAttributes = 11 | |
const maxAttributes = 11 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is likely going to over allocate. Can we pre-determine the correct size or have an issue to track doing so later?
} else { | ||
// Prioritize the primary server name. | ||
host, p = splitHostPort(server) | ||
if p < 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if p < 0 { | |
if host == "" && p < 0 { |
// The req Host will be used to determine the server instead. | ||
func (n newHTTPServer) RequestTraceAttrs(server string, req *http.Request) []attribute.KeyValue { | ||
const MaxAttributes = 11 | ||
attrs := make([]attribute.KeyValue, MaxAttributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attrs := make([]attribute.KeyValue, MaxAttributes) | |
attrs := make([]attribute.KeyValue, 0, MaxAttributes) |
Tracking append position could then be replaced with append
attrs[0] = semconvNew.HTTPRequestMethodGet | ||
} | ||
attrs[1] = semconvNew.HTTPRequestMethodOriginal(method) | ||
return 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The index state is not tracked with a variable. This is going to be brittle and tough to evolve.
|
||
func (n newHTTPServer) method(method string, attrs []attribute.KeyValue) int { | ||
if method == "" { | ||
attrs[0] = semconvNew.HTTPRequestMethodGet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not obvious that attrs
passed here has to be pre-allocated.
Using an append
approach would avoid the panic if len(attrs) <= 0
.
// | ||
// If any of the fields in the ResponseTelemetry are not set the attribute will be omitted. | ||
func (n newHTTPServer) ResponseTraceAttrs(resp ResponseTelemetry) []attribute.KeyValue { | ||
attributes := []attribute.KeyValue{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The allocation strategy is not the same as RequestTraceAttrs
.
if attr, ok := methodLookup[strings.ToUpper(method)]; ok { | ||
attrs[0] = attr | ||
} else { | ||
// If the Original methos is not a standard HTTP method fallback to GET |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// If the Original methos is not a standard HTTP method fallback to GET | |
// If the Original method is not a standard HTTP method fallback to GET |
resp: ResponseTelemetry{ | ||
StatusCode: 200, | ||
ReadBytes: 701, | ||
ReadError: fmt.Errorf("read error"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReadError: fmt.Errorf("read error"), | |
ReadError: errors.New("read error"), |
This change adds the new semantic version (v1.24.0) attribute producer to the semconv of otlehttp.
The full PR is #5092
Part of #5331