noop.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2022 The OpenZipkin Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package zipkin
  15. import (
  16. "time"
  17. "github.com/openzipkin/zipkin-go/model"
  18. )
  19. type noopSpan struct {
  20. model.SpanContext
  21. }
  22. func (n *noopSpan) Context() model.SpanContext { return n.SpanContext }
  23. func (n *noopSpan) SetName(string) {}
  24. func (*noopSpan) SetRemoteEndpoint(*model.Endpoint) {}
  25. func (*noopSpan) Annotate(time.Time, string) {}
  26. func (*noopSpan) Tag(string, string) {}
  27. func (*noopSpan) Finish() {}
  28. func (*noopSpan) FinishedWithDuration(_ time.Duration) {}
  29. func (*noopSpan) Flush() {}
  30. // IsNoop tells whether the span is noop or not. Usually used to avoid resource misusage
  31. // when customizing a span as data won't be recorded
  32. func IsNoop(s Span) bool {
  33. _, ok := s.(*noopSpan)
  34. return ok
  35. }