gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

span_processor.go (2832B)


      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 package trace // import "go.opentelemetry.io/otel/sdk/trace"
     16 
     17 import (
     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.
     26 type SpanProcessor interface {
     27 	// DO NOT CHANGE: any modification will not be backwards compatible and
     28 	// must never be done outside of a new major release.
     29 
     30 	// OnStart is called when a span is started. It is called synchronously
     31 	// and should not block.
     32 	OnStart(parent context.Context, s ReadWriteSpan)
     33 	// DO NOT CHANGE: any modification will not be backwards compatible and
     34 	// must never be done outside of a new major release.
     35 
     36 	// OnEnd is called when span is finished. It is called synchronously and
     37 	// hence not block.
     38 	OnEnd(s ReadOnlySpan)
     39 	// DO NOT CHANGE: any modification will not be backwards compatible and
     40 	// must never be done outside of a new major release.
     41 
     42 	// Shutdown is called when the SDK shuts down. Any cleanup or release of
     43 	// resources held by the processor should be done in this call.
     44 	//
     45 	// Calls to OnStart, OnEnd, or ForceFlush after this has been called
     46 	// should be ignored.
     47 	//
     48 	// All timeouts and cancellations contained in ctx must be honored, this
     49 	// should not block indefinitely.
     50 	Shutdown(ctx context.Context) error
     51 	// DO NOT CHANGE: any modification will not be backwards compatible and
     52 	// must never be done outside of a new major release.
     53 
     54 	// ForceFlush exports all ended spans to the configured Exporter that have not yet
     55 	// been exported.  It should only be called when absolutely necessary, such as when
     56 	// using a FaaS provider that may suspend the process after an invocation, but before
     57 	// the Processor can export the completed spans.
     58 	ForceFlush(ctx context.Context) error
     59 	// DO NOT CHANGE: any modification will not be backwards compatible and
     60 	// must never be done outside of a new major release.
     61 }
     62 
     63 type spanProcessorState struct {
     64 	sp    SpanProcessor
     65 	state sync.Once
     66 }
     67 
     68 func newSpanProcessorState(sp SpanProcessor) *spanProcessorState {
     69 	return &spanProcessorState{sp: sp}
     70 }
     71 
     72 type spanProcessorStates []*spanProcessorState