github.com/matrixorigin/matrixone@v1.2.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 batchProcessor: NoopBatchProcessor{}, 39 }, 40 } 41 WithNode("node_uuid", trace.NodeTypeStandalone).apply(&pTracer.tracerProviderConfig) 42 withMOVersion("MatrixOne").apply(&pTracer.tracerProviderConfig) 43 return pTracer 44 } 45 46 func newMOTracerProvider(opts ...TracerProviderOption) *MOTracerProvider { 47 pTracer := defaultMOTracerProvider() 48 for _, opt := range opts { 49 opt.apply(&pTracer.tracerProviderConfig) 50 } 51 return pTracer 52 } 53 54 func (p *MOTracerProvider) Tracer(instrumentationName string, opts ...trace.TracerOption) trace.Tracer { 55 if !p.IsEnable() { 56 return trace.NoopTracer{} 57 } 58 59 tracer := &MOTracer{ 60 TracerConfig: trace.TracerConfig{Name: instrumentationName}, 61 provider: p, 62 } 63 for _, opt := range opts { 64 opt.Apply(&tracer.TracerConfig) 65 } 66 return tracer 67 }