vitess.io/vitess@v0.16.2/go/trace/fake.go (about)

     1  /*
     2  Copyright 2019 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package trace
    18  
    19  import (
    20  	"context"
    21  	"io"
    22  
    23  	"google.golang.org/grpc"
    24  )
    25  
    26  type noopTracingServer struct{}
    27  
    28  func (noopTracingServer) New(Span, string) Span { return NoopSpan{} }
    29  func (noopTracingServer) NewClientSpan(parent Span, serviceName, label string) Span {
    30  	return NoopSpan{}
    31  }
    32  func (noopTracingServer) FromContext(context.Context) (Span, bool)                  { return nil, false }
    33  func (noopTracingServer) NewFromString(parent, label string) (Span, error)          { return NoopSpan{}, nil }
    34  func (noopTracingServer) NewContext(parent context.Context, _ Span) context.Context { return parent }
    35  func (noopTracingServer) AddGrpcServerOptions(addInterceptors func(s grpc.StreamServerInterceptor, u grpc.UnaryServerInterceptor)) {
    36  }
    37  func (noopTracingServer) AddGrpcClientOptions(addInterceptors func(s grpc.StreamClientInterceptor, u grpc.UnaryClientInterceptor)) {
    38  }
    39  
    40  // NoopSpan implements Span with no-op methods.
    41  type NoopSpan struct{}
    42  
    43  func (NoopSpan) Finish()              {}
    44  func (NoopSpan) Annotate(string, any) {}
    45  
    46  func init() {
    47  	tracingBackendFactories["noop"] = func(_ string) (tracingService, io.Closer, error) {
    48  		return noopTracingServer{}, &nilCloser{}, nil
    49  	}
    50  }