2020-03-24 07:41:10 +02:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2024-02-29 08:05:28 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2019-09-16 22:58:15 +02:00
|
|
|
|
2020-11-04 19:10:58 +02:00
|
|
|
package trace // import "go.opentelemetry.io/otel/sdk/trace"
|
2019-09-16 22:58:15 +02:00
|
|
|
|
|
|
|
import (
|
2020-10-27 04:06:55 +02:00
|
|
|
"context"
|
2019-09-16 22:58:15 +02:00
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
2021-03-02 17:20:13 +02:00
|
|
|
// SpanProcessor is a processing pipeline for spans in the trace signal.
|
|
|
|
// SpanProcessors registered with a TracerProvider and are called at the start
|
|
|
|
// and end of a Span's lifecycle, and are called in the order they are
|
|
|
|
// registered.
|
2019-09-16 22:58:15 +02:00
|
|
|
type SpanProcessor interface {
|
2021-06-18 16:56:11 +02:00
|
|
|
// DO NOT CHANGE: any modification will not be backwards compatible and
|
|
|
|
// must never be done outside of a new major release.
|
|
|
|
|
2021-03-02 17:20:13 +02:00
|
|
|
// OnStart is called when a span is started. It is called synchronously
|
|
|
|
// and should not block.
|
2020-12-11 07:15:44 +02:00
|
|
|
OnStart(parent context.Context, s ReadWriteSpan)
|
2021-06-18 16:56:11 +02:00
|
|
|
// DO NOT CHANGE: any modification will not be backwards compatible and
|
|
|
|
// must never be done outside of a new major release.
|
2019-09-16 22:58:15 +02:00
|
|
|
|
2021-03-02 17:20:13 +02:00
|
|
|
// OnEnd is called when span is finished. It is called synchronously and
|
|
|
|
// hence not block.
|
2020-12-11 07:15:44 +02:00
|
|
|
OnEnd(s ReadOnlySpan)
|
2021-06-18 16:56:11 +02:00
|
|
|
// DO NOT CHANGE: any modification will not be backwards compatible and
|
|
|
|
// must never be done outside of a new major release.
|
2019-09-16 22:58:15 +02:00
|
|
|
|
2021-03-02 17:20:13 +02:00
|
|
|
// Shutdown is called when the SDK shuts down. Any cleanup or release of
|
|
|
|
// resources held by the processor should be done in this call.
|
|
|
|
//
|
|
|
|
// Calls to OnStart, OnEnd, or ForceFlush after this has been called
|
|
|
|
// should be ignored.
|
|
|
|
//
|
|
|
|
// All timeouts and cancellations contained in ctx must be honored, this
|
|
|
|
// should not block indefinitely.
|
2020-10-27 04:06:55 +02:00
|
|
|
Shutdown(ctx context.Context) error
|
2021-06-18 16:56:11 +02:00
|
|
|
// DO NOT CHANGE: any modification will not be backwards compatible and
|
|
|
|
// must never be done outside of a new major release.
|
2020-09-20 19:35:44 +02:00
|
|
|
|
|
|
|
// ForceFlush exports all ended spans to the configured Exporter that have not yet
|
|
|
|
// been exported. It should only be called when absolutely necessary, such as when
|
|
|
|
// using a FaaS provider that may suspend the process after an invocation, but before
|
|
|
|
// the Processor can export the completed spans.
|
2021-03-08 21:12:13 +02:00
|
|
|
ForceFlush(ctx context.Context) error
|
2021-06-18 16:56:11 +02:00
|
|
|
// DO NOT CHANGE: any modification will not be backwards compatible and
|
|
|
|
// must never be done outside of a new major release.
|
2019-09-16 22:58:15 +02:00
|
|
|
}
|
|
|
|
|
2020-09-24 20:43:23 +02:00
|
|
|
type spanProcessorState struct {
|
|
|
|
sp SpanProcessor
|
2023-04-01 16:57:35 +02:00
|
|
|
state sync.Once
|
2020-09-24 20:43:23 +02:00
|
|
|
}
|
2022-10-12 22:44:18 +02:00
|
|
|
|
|
|
|
func newSpanProcessorState(sp SpanProcessor) *spanProcessorState {
|
2023-04-01 16:57:35 +02:00
|
|
|
return &spanProcessorState{sp: sp}
|
2022-10-12 22:44:18 +02:00
|
|
|
}
|
|
|
|
|
2020-09-24 20:43:23 +02:00
|
|
|
type spanProcessorStates []*spanProcessorState
|