trpc.group/trpc-go/trpc-go@v1.0.3/rpcz/noopspan.go (about)

     1  //
     2  //
     3  // Tencent is pleased to support the open source community by making tRPC available.
     4  //
     5  // Copyright (C) 2023 THL A29 Limited, a Tencent company.
     6  // All rights reserved.
     7  //
     8  // If you have downloaded a copy of the tRPC source code from Tencent,
     9  // please note that tRPC source code is licensed under the  Apache 2.0 License,
    10  // A copy of the Apache 2.0 License is included in this file.
    11  //
    12  //
    13  
    14  package rpcz
    15  
    16  import "time"
    17  
    18  // noopSpan is an implementation of Span that preforms no operations.
    19  type noopSpan struct{}
    20  
    21  // AddEvent does nothing.
    22  func (s noopSpan) AddEvent(_ string) {}
    23  
    24  // Event returns nil.
    25  func (s noopSpan) Event(string) (time.Time, bool) {
    26  	return time.Time{}, false
    27  }
    28  
    29  // SetAttribute does nothing.
    30  func (s noopSpan) SetAttribute(_ string, _ interface{}) {}
    31  
    32  // Attribute always returns nil.
    33  func (s noopSpan) Attribute(_ string) (interface{}, bool) {
    34  	return nil, false
    35  }
    36  
    37  // StartTime returns the zero value of type Time.
    38  func (s noopSpan) StartTime() time.Time {
    39  	return time.Time{}
    40  }
    41  
    42  // EndTime returns the zero value of type Time.
    43  func (s noopSpan) EndTime() time.Time {
    44  	return time.Time{}
    45  }
    46  
    47  // ID return an invalid span ID.
    48  func (s noopSpan) ID() SpanID { return nilSpanID }
    49  
    50  // Name return an empty string.
    51  func (s noopSpan) Name() string { return "" }
    52  
    53  // NewChild returns a noopSpan and empty end function.
    54  func (s noopSpan) NewChild(_ string) (Span, Ender) {
    55  	ns := noopSpan{}
    56  	return ns, ns
    57  }
    58  
    59  // Child always returns nil and false.
    60  func (s noopSpan) Child(_ string) (Span, bool) {
    61  	return nil, false
    62  }
    63  
    64  // End does nothing.
    65  func (s noopSpan) End() {}