Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MadVikingGod
Copy link
Contributor

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

Copy link

codecov bot commented Apr 17, 2024

Codecov Report

Attention: Patch coverage is 78.78788% with 21 lines in your changes are missing coverage. Please review.

Project coverage is 62.5%. Comparing base (30ed923) to head (5049d91).

Additional details and impacted files

Impacted file tree graph

@@           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     
Files Coverage Δ
...entation/net/http/otelhttp/internal/semconv/env.go 84.6% <100.0%> (+9.6%) ⬆️
...ntation/net/http/otelhttp/internal/semconv/util.go 83.3% <62.5%> (-16.7%) ⬇️
...tion/net/http/otelhttp/internal/semconv/v1.24.0.go 80.5% <80.5%> (ø)

... and 1 file with indirect coverage changes

@MadVikingGod MadVikingGod added the Skip Changelog Allow PR to succeed without requiring an addition to the CHANGELOG label Apr 18, 2024
@MadVikingGod
Copy link
Contributor Author

Changelog will be part of follow on PR as part of #5331

Copy link
Contributor

@dashpole dashpole left a 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

Copy link
Contributor

@MrAlias MrAlias left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const MaxAttributes = 11
const maxAttributes = 11

Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

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
Copy link
Contributor

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{}
Copy link
Contributor

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ReadError: fmt.Errorf("read error"),
ReadError: errors.New("read error"),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog Allow PR to succeed without requiring an addition to the CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants