Debian Codegraph @

sdk/trace/span_processor.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package trace // import "go.opentelemetry.io/otel/sdk/trace"
5
6 import (
7 "context"
8 "sync"
9 )
10
11 // SpanProcessor is a processing pipeline for spans in the trace signal.
12 // SpanProcessors registered with a TracerProvider and are called at the start
13 // and end of a Span's lifecycle, and are called in the order they are
14 // registered.
15 type SpanProcessor interface {
16 // DO NOT CHANGE: any modification will not be backwards compatible and
17 // must never be done outside of a new major release.
18
19 // OnStart is called when a span is started. It is called synchronously
20 // and should not block.
21 OnStart(parent context.Context, s ReadWriteSpan)
22 // DO NOT CHANGE: any modification will not be backwards compatible and
23 // must never be done outside of a new major release.
24
25 // OnEnd is called when span is finished. It is called synchronously and
26 // hence not block.
27 OnEnd(s ReadOnlySpan)
28 // DO NOT CHANGE: any modification will not be backwards compatible and
29 // must never be done outside of a new major release.
30
31 // Shutdown is called when the SDK shuts down. Any cleanup or release of
32 // resources held by the processor should be done in this call.
33 //
34 // Calls to OnStart, OnEnd, or ForceFlush after this has been called
35 // should be ignored.
36 //
37 // All timeouts and cancellations contained in ctx must be honored, this
38 // should not block indefinitely.
39 Shutdown(ctx context.Context) error
40 // DO NOT CHANGE: any modification will not be backwards compatible and
41 // must never be done outside of a new major release.
42
43 // ForceFlush exports all ended spans to the configured Exporter that have not yet
44 // been exported. It should only be called when absolutely necessary, such as when
45 // using a FaaS provider that may suspend the process after an invocation, but before
46 // the Processor can export the completed spans.
47 ForceFlush(ctx context.Context) error
48 // DO NOT CHANGE: any modification will not be backwards compatible and
49 // must never be done outside of a new major release.
50 }
51
52 type spanProcessorState struct {
53 sp SpanProcessor
54 state sync.Once
55 }
56
57 func newSpanProcessorState(sp SpanProcessor) *spanProcessorState {
58 return &spanProcessorState{sp: sp}
59 }
60
61 type spanProcessorStates []*spanProcessorState