-
Notifications
You must be signed in to change notification settings - Fork 720
add build tag to disable tracing #754
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
Merged
johanbrandhorst
merged 4 commits into
grpc-ecosystem:main
from
rashmi-tondare:build-no-trace
Mar 4, 2025
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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,29 @@ | ||
// Copyright (c) The go-grpc-middleware Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
//go:build retrynotrace | ||
|
||
package retry | ||
|
||
// retrynotrace can be used to avoid importing golang.org/x/net/trace, which in | ||
// turn enables binaries using go-grpc-middleware for dead code elimination, which can | ||
// yield improvements in binary size when tracing is not needed. | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
type notrace struct{} | ||
|
||
func (notrace) LazyLog(x fmt.Stringer, sensitive bool) {} | ||
func (notrace) LazyPrintf(format string, a ...any) {} | ||
func (notrace) SetError() {} | ||
func (notrace) SetRecycler(f func(any)) {} | ||
func (notrace) SetTraceInfo(traceID, spanID uint64) {} | ||
func (notrace) SetMaxEvents(m int) {} | ||
func (notrace) Finish() {} | ||
|
||
func traceFromCtx(ctx context.Context) (notrace, bool) { | ||
return notrace{}, true | ||
} |
This file contains hidden or 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,42 @@ | ||
// Copyright (c) The go-grpc-middleware Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
//go:build retrynotrace | ||
|
||
package retry | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_traceFromCtx(t *testing.T) { | ||
tr := notrace{} | ||
ctx := context.Background() | ||
|
||
type args struct { | ||
ctx context.Context | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want notrace | ||
want1 bool | ||
}{ | ||
{ | ||
name: "should return notrace", | ||
args: args{ctx: ctx}, | ||
want: tr, | ||
want1: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, got1 := traceFromCtx(tt.args.ctx) | ||
assert.Equalf(t, tt.want, got, "traceFromCtx(%v)", tt.args.ctx) | ||
assert.Equalf(t, tt.want1, got1, "traceFromCtx(%v)", tt.args.ctx) | ||
}) | ||
} | ||
} |
This file contains hidden or 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,16 @@ | ||
// Copyright (c) The go-grpc-middleware Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
//go:build !retrynotrace | ||
|
||
package retry | ||
|
||
import ( | ||
"context" | ||
|
||
t "golang.org/x/net/trace" | ||
) | ||
|
||
func traceFromCtx(ctx context.Context) (t.Trace, bool) { | ||
return t.FromContext(ctx) | ||
} |
This file contains hidden or 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,49 @@ | ||
// Copyright (c) The go-grpc-middleware Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
//go:build !retrynotrace | ||
|
||
package retry | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"golang.org/x/net/trace" | ||
) | ||
|
||
func Test_traceFromCtx(t *testing.T) { | ||
tr := trace.New("test", "with trace") | ||
ctx := trace.NewContext(context.Background(), tr) | ||
|
||
type args struct { | ||
ctx context.Context | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want trace.Trace | ||
want1 bool | ||
}{ | ||
{ | ||
name: "should return trace", | ||
args: args{ctx: ctx}, | ||
want: tr, | ||
want1: true, | ||
}, | ||
{ | ||
name: "should return false if trace not found in ctx", | ||
args: args{ctx: context.Background()}, | ||
want: nil, | ||
want1: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, got1 := traceFromCtx(tt.args.ctx) | ||
assert.Equalf(t, tt.want, got, "traceFromCtx(%v)", tt.args.ctx) | ||
assert.Equalf(t, tt.want1, got1, "traceFromCtx(%v)", tt.args.ctx) | ||
}) | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.