trace_notrace.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //go:build grpcnotrace
  2. /*
  3. *
  4. * Copyright 2024 gRPC authors.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. */
  19. package grpc
  20. // grpcnotrace can be used to avoid importing golang.org/x/net/trace, which in
  21. // turn enables binaries using gRPC-Go for dead code elimination, which can
  22. // yield 10-15% improvements in binary size when tracing is not needed.
  23. import (
  24. "context"
  25. "fmt"
  26. )
  27. type notrace struct{}
  28. func (notrace) LazyLog(x fmt.Stringer, sensitive bool) {}
  29. func (notrace) LazyPrintf(format string, a ...any) {}
  30. func (notrace) SetError() {}
  31. func (notrace) SetRecycler(f func(any)) {}
  32. func (notrace) SetTraceInfo(traceID, spanID uint64) {}
  33. func (notrace) SetMaxEvents(m int) {}
  34. func (notrace) Finish() {}
  35. func newTrace(family, title string) traceLog {
  36. return notrace{}
  37. }
  38. func newTraceContext(ctx context.Context, tr traceLog) context.Context {
  39. return ctx
  40. }
  41. func newTraceEventLog(family, title string) traceEventLog {
  42. return nil
  43. }