-
Notifications
You must be signed in to change notification settings - Fork 576
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 Part1 Server Metrics - v1.20.0 support #5818
Merged
MadVikingGod
merged 7 commits into
open-telemetry:main
from
MadVikingGod:mvg/semconv/metrics-server/old
Aug 2, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6b4d80c
Enable metrics in semconv
MadVikingGod de9ff50
Fixed lint issues
MadVikingGod 8c20713
Merge remote-tracking branch 'upstream/main' into mvg/semconv/metrics…
MadVikingGod dcdc4c2
Update instrumentation/net/http/otelhttp/internal/semconv/env.go
MadVikingGod 1749252
Merge remote-tracking branch 'upstream/main' into mvg/semconv/metrics…
MadVikingGod 3f304d0
fix missing nil
MadVikingGod 88156b3
Merge remote-tracking branch 'upstream/main' into mvg/semconv/metrics…
MadVikingGod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
instrumentation/net/http/otelhttp/internal/semconv/env_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package semconv | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/metric" | ||
"go.opentelemetry.io/otel/metric/embedded" | ||
"go.opentelemetry.io/otel/metric/noop" | ||
) | ||
|
||
func TestHTTPServerDoesNotPanic(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
server HTTPServer | ||
}{ | ||
{ | ||
name: "empty", | ||
server: HTTPServer{}, | ||
}, | ||
{ | ||
name: "nil meter", | ||
server: NewHTTPServer(nil), | ||
}, | ||
{ | ||
name: "with Meter", | ||
server: NewHTTPServer(noop.Meter{}), | ||
}, | ||
} | ||
for _, tt := range testCases { | ||
t.Run(tt.name, func(t *testing.T) { | ||
require.NotPanics(t, func() { | ||
req, err := http.NewRequest("GET", "http://example.com", nil) | ||
require.NoError(t, err) | ||
|
||
_ = tt.server.RequestTraceAttrs("stuff", req) | ||
_ = tt.server.ResponseTraceAttrs(ResponseTelemetry{StatusCode: 200}) | ||
tt.server.RecordMetrics(context.Background(), MetricData{ | ||
ServerName: "stuff", | ||
Req: req, | ||
}) | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
type testInst struct { | ||
embedded.Int64Counter | ||
embedded.Float64Histogram | ||
|
||
intValue int64 | ||
floatValue float64 | ||
attributes []attribute.KeyValue | ||
} | ||
|
||
func (t *testInst) Add(ctx context.Context, incr int64, options ...metric.AddOption) { | ||
t.intValue = incr | ||
cfg := metric.NewAddConfig(options) | ||
attr := cfg.Attributes() | ||
t.attributes = attr.ToSlice() | ||
} | ||
|
||
func (t *testInst) Record(ctx context.Context, value float64, options ...metric.RecordOption) { | ||
t.floatValue = value | ||
cfg := metric.NewRecordConfig(options) | ||
attr := cfg.Attributes() | ||
t.attributes = attr.ToSlice() | ||
} | ||
|
||
func NewTestHTTPServer() HTTPServer { | ||
return HTTPServer{ | ||
requestBytesCounter: &testInst{}, | ||
responseBytesCounter: &testInst{}, | ||
serverLatencyMeasure: &testInst{}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we track that these should be pooled?
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.
I made #5968 to track this