github.com/matrixorigin/matrixone@v1.2.0/pkg/util/trace/type.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 trace 23 24 import ( 25 "context" 26 "go.uber.org/zap" 27 ) 28 29 type TracerProvider interface { 30 Tracer(instrumentationName string, opts ...TracerOption) Tracer 31 } 32 33 type Tracer interface { 34 // Start creates a span and a context.Context containing the newly-created span. 35 // 36 // If the context.Context provided in `ctx` contains a Span then the newly-created 37 // Span will be a child of that span, otherwise it will be a root span. This behavior 38 // can be overridden by providing `WithNewRoot()` as a SpanOption, causing the 39 // newly-created Span to be a root span even if `ctx` contains a Span. 40 // 41 // Any Span that is created MUST also be ended. This is the responsibility of the user. 42 // Implementations of this API may leak memory or other resources if Spans are not ended. 43 Start(ctx context.Context, spanName string, opts ...SpanStartOption) (context.Context, Span) 44 // Debug creates a span only with DebugMode 45 Debug(ctx context.Context, spanName string, opts ...SpanStartOption) (context.Context, Span) 46 // IsEnable return true, means do record 47 IsEnable(opts ...SpanStartOption) bool 48 } 49 50 type Span interface { 51 // End completes the Span. The Span is considered complete and ready to be 52 // delivered through the rest of the telemetry pipeline after this method 53 // is called. Therefore, updates to the Span are not allowed after this 54 // method has been called. 55 End(options ...SpanEndOption) 56 57 // AddExtraFields inject more details for span. 58 AddExtraFields(fields ...zap.Field) 59 60 // SpanContext returns the SpanContext of the Span. The returned SpanContext 61 // is usable even after the End method has been called for the Span. 62 SpanContext() SpanContext 63 64 ParentSpanContext() SpanContext 65 } 66 67 type SpanProcessor interface { 68 OnStart(ctx context.Context, s Span) 69 OnEnd(s Span) 70 Shutdown(ctx context.Context) error 71 } 72 73 type IDGenerator interface { 74 NewIDs() (TraceID, SpanID) 75 NewSpanID() SpanID 76 }