-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Use OpenTelemetry SDK in HotROD 🚗 #4187
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8c352db
Issue 3362:
rbroggi 4e1495c
Update examples/hotrod/pkg/tracing/init.go
rbroggi e19907d
Issue 3362:
rbroggi 3e8f1e5
go mod tidy
yurishkuro 88f2bad
make it work
yurishkuro 91816c6
add favicon
yurishkuro 7a030fa
implement rpc metrics
yurishkuro 70887b1
imports
yurishkuro 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
go.work | ||
go.work.sum | ||
|
||
*.out | ||
*.test | ||
*.xml | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Package rpcmetrics implements an OpenTelemetry SpanProcessor that can be used to emit RPC metrics. | ||
|
||
This package is copied from jaeger-client-go and adapted to work with OpenTelemtery SDK. |
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,63 @@ | ||
// Copyright (c) 2023 The Jaeger Authors. | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package rpcmetrics | ||
|
||
import "sync" | ||
|
||
// normalizedEndpoints is a cache for endpointName -> safeName mappings. | ||
type normalizedEndpoints struct { | ||
names map[string]string | ||
maxSize int | ||
normalizer NameNormalizer | ||
mux sync.RWMutex | ||
} | ||
|
||
func newNormalizedEndpoints(maxSize int, normalizer NameNormalizer) *normalizedEndpoints { | ||
return &normalizedEndpoints{ | ||
maxSize: maxSize, | ||
normalizer: normalizer, | ||
names: make(map[string]string, maxSize), | ||
} | ||
} | ||
|
||
// normalize looks up the name in the cache, if not found it uses normalizer | ||
// to convert the name to a safe name. If called with more than maxSize unique | ||
// names it returns "" for all other names beyond those already cached. | ||
func (n *normalizedEndpoints) normalize(name string) string { | ||
n.mux.RLock() | ||
norm, ok := n.names[name] | ||
l := len(n.names) | ||
n.mux.RUnlock() | ||
if ok { | ||
return norm | ||
} | ||
if l >= n.maxSize { | ||
return "" | ||
} | ||
return n.normalizeWithLock(name) | ||
} | ||
|
||
func (n *normalizedEndpoints) normalizeWithLock(name string) string { | ||
norm := n.normalizer.Normalize(name) | ||
n.mux.Lock() | ||
defer n.mux.Unlock() | ||
// cache may have grown while we were not holding the lock | ||
if len(n.names) >= n.maxSize { | ||
return "" | ||
} | ||
n.names[name] = norm | ||
return norm | ||
} |
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,44 @@ | ||
// Copyright (c) 2023 The Jaeger Authors. | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package rpcmetrics | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNormalizedEndpoints(t *testing.T) { | ||
n := newNormalizedEndpoints(1, DefaultNameNormalizer) | ||
|
||
assertLen := func(l int) { | ||
n.mux.RLock() | ||
defer n.mux.RUnlock() | ||
assert.Len(t, n.names, l) | ||
} | ||
|
||
assert.Equal(t, "ab_cd", n.normalize("ab^cd"), "one translation") | ||
assert.Equal(t, "ab_cd", n.normalize("ab^cd"), "cache hit") | ||
assertLen(1) | ||
assert.Equal(t, "", n.normalize("xys"), "cache overflow") | ||
assertLen(1) | ||
} | ||
|
||
func TestNormalizedEndpointsDoubleLocking(t *testing.T) { | ||
n := newNormalizedEndpoints(1, DefaultNameNormalizer) | ||
assert.Equal(t, "ab_cd", n.normalize("ab^cd"), "fill out the cache") | ||
assert.Equal(t, "", n.normalizeWithLock("xys"), "cache overflow") | ||
} |
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.
@rbroggi your PR was mostly spot-on, this was the only thing missing, so traces did not continue across services.
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.
Thx for reaching out. I have been quite in the shadows lately. Hope to come back to some contributions soon.