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 15package trace // import "go.opentelemetry.io/otel/sdk/trace" 16 17import ( 18 "context" 19 "sync" 20) 21 22// SpanProcessor is a processing pipeline for spans in the trace signal. 23// SpanProcessors registered with a TracerProvider and are called at the start 24// and end of a Span's lifecycle, and are called in the order they are 25// registered. 26type SpanProcessor interface { 27 // OnStart is called when a span is started. It is called synchronously 28 // and should not block. 29 OnStart(parent context.Context, s ReadWriteSpan) 30 31 // OnEnd is called when span is finished. It is called synchronously and 32 // hence not block. 33 OnEnd(s ReadOnlySpan) 34 35 // Shutdown is called when the SDK shuts down. Any cleanup or release of 36 // resources held by the processor should be done in this call. 37 // 38 // Calls to OnStart, OnEnd, or ForceFlush after this has been called 39 // should be ignored. 40 // 41 // All timeouts and cancellations contained in ctx must be honored, this 42 // should not block indefinitely. 43 Shutdown(ctx context.Context) error 44 45 // ForceFlush exports all ended spans to the configured Exporter that have not yet 46 // been exported. It should only be called when absolutely necessary, such as when 47 // using a FaaS provider that may suspend the process after an invocation, but before 48 // the Processor can export the completed spans. 49 ForceFlush() 50} 51 52type spanProcessorState struct { 53 sp SpanProcessor 54 state *sync.Once 55} 56type spanProcessorStates []*spanProcessorState 57