github.com/matrixorigin/matrixone@v0.7.0/pkg/util/trace/impl/motrace/ptrace.go (about)

     1  // Copyright The OpenTelemetry 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  
    15  // Portions of this file are additionally subject to the following
    16  // copyright.
    17  //
    18  // Copyright (C) 2022 Matrix Origin.
    19  //
    20  // Modified the behavior and the interface of the step.
    21  
    22  package motrace
    23  
    24  import "github.com/matrixorigin/matrixone/pkg/util/trace"
    25  
    26  var _ trace.TracerProvider = &MOTracerProvider{}
    27  
    28  type MOTracerProvider struct {
    29  	tracerProviderConfig
    30  }
    31  
    32  func defaultMOTracerProvider() *MOTracerProvider {
    33  	pTracer := &MOTracerProvider{
    34  		tracerProviderConfig{
    35  			enable:           false,
    36  			resource:         trace.NewResource(),
    37  			idGenerator:      &moIDGenerator{},
    38  			batchProcessMode: FileService,
    39  			batchProcessor:   NoopBatchProcessor{},
    40  		},
    41  	}
    42  	WithNode("node_uuid", trace.NodeTypeStandalone).apply(&pTracer.tracerProviderConfig)
    43  	withMOVersion("MatrixOne").apply(&pTracer.tracerProviderConfig)
    44  	return pTracer
    45  }
    46  
    47  func newMOTracerProvider(opts ...TracerProviderOption) *MOTracerProvider {
    48  	pTracer := defaultMOTracerProvider()
    49  	for _, opt := range opts {
    50  		opt.apply(&pTracer.tracerProviderConfig)
    51  	}
    52  	return pTracer
    53  }
    54  
    55  func (p *MOTracerProvider) Tracer(instrumentationName string, opts ...trace.TracerOption) trace.Tracer {
    56  	if !p.IsEnable() {
    57  		return trace.NoopTracer{}
    58  	}
    59  
    60  	tracer := &MOTracer{
    61  		TracerConfig: trace.TracerConfig{Name: instrumentationName},
    62  		provider:     p,
    63  	}
    64  	for _, opt := range opts {
    65  		opt.Apply(&tracer.TracerConfig)
    66  	}
    67  	return tracer
    68  }