mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: github.com/moby/buildkit c9ee8491d74f (master)
full diff:
- https://github.com/containerd/containerd/compare/v1.7.8...v1.7.9
- 5ae9b23c40...c9ee8491d7
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
70
vendor/go.opentelemetry.io/otel/sdk/trace/batch_span_processor.go
generated
vendored
70
vendor/go.opentelemetry.io/otel/sdk/trace/batch_span_processor.go
generated
vendored
@ -16,7 +16,6 @@ package trace // import "go.opentelemetry.io/otel/sdk/trace"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@ -84,6 +83,7 @@ type batchSpanProcessor struct {
|
||||
stopWait sync.WaitGroup
|
||||
stopOnce sync.Once
|
||||
stopCh chan struct{}
|
||||
stopped atomic.Bool
|
||||
}
|
||||
|
||||
var _ SpanProcessor = (*batchSpanProcessor)(nil)
|
||||
@ -91,7 +91,7 @@ var _ SpanProcessor = (*batchSpanProcessor)(nil)
|
||||
// NewBatchSpanProcessor creates a new SpanProcessor that will send completed
|
||||
// span batches to the exporter with the supplied options.
|
||||
//
|
||||
// If the exporter is nil, the span processor will preform no action.
|
||||
// If the exporter is nil, the span processor will perform no action.
|
||||
func NewBatchSpanProcessor(exporter SpanExporter, options ...BatchSpanProcessorOption) SpanProcessor {
|
||||
maxQueueSize := env.BatchSpanProcessorMaxQueueSize(DefaultMaxQueueSize)
|
||||
maxExportBatchSize := env.BatchSpanProcessorMaxExportBatchSize(DefaultMaxExportBatchSize)
|
||||
@ -137,6 +137,11 @@ func (bsp *batchSpanProcessor) OnStart(parent context.Context, s ReadWriteSpan)
|
||||
|
||||
// OnEnd method enqueues a ReadOnlySpan for later processing.
|
||||
func (bsp *batchSpanProcessor) OnEnd(s ReadOnlySpan) {
|
||||
// Do not enqueue spans after Shutdown.
|
||||
if bsp.stopped.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
// Do not enqueue spans if we are just going to drop them.
|
||||
if bsp.e == nil {
|
||||
return
|
||||
@ -149,6 +154,7 @@ func (bsp *batchSpanProcessor) OnEnd(s ReadOnlySpan) {
|
||||
func (bsp *batchSpanProcessor) Shutdown(ctx context.Context) error {
|
||||
var err error
|
||||
bsp.stopOnce.Do(func() {
|
||||
bsp.stopped.Store(true)
|
||||
wait := make(chan struct{})
|
||||
go func() {
|
||||
close(bsp.stopCh)
|
||||
@ -181,11 +187,24 @@ func (f forceFlushSpan) SpanContext() trace.SpanContext {
|
||||
|
||||
// ForceFlush exports all ended spans that have not yet been exported.
|
||||
func (bsp *batchSpanProcessor) ForceFlush(ctx context.Context) error {
|
||||
// Interrupt if context is already canceled.
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Do nothing after Shutdown.
|
||||
if bsp.stopped.Load() {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
if bsp.e != nil {
|
||||
flushCh := make(chan struct{})
|
||||
if bsp.enqueueBlockOnQueueFull(ctx, forceFlushSpan{flushed: flushCh}) {
|
||||
select {
|
||||
case <-bsp.stopCh:
|
||||
// The batchSpanProcessor is Shutdown.
|
||||
return nil
|
||||
case <-flushCh:
|
||||
// Processed any items in queue prior to ForceFlush being called
|
||||
case <-ctx.Done():
|
||||
@ -326,11 +345,9 @@ func (bsp *batchSpanProcessor) drainQueue() {
|
||||
for {
|
||||
select {
|
||||
case sd := <-bsp.queue:
|
||||
if sd == nil {
|
||||
if err := bsp.exportSpans(ctx); err != nil {
|
||||
otel.Handle(err)
|
||||
}
|
||||
return
|
||||
if _, ok := sd.(forceFlushSpan); ok {
|
||||
// Ignore flush requests as they are not valid spans.
|
||||
continue
|
||||
}
|
||||
|
||||
bsp.batchMutex.Lock()
|
||||
@ -344,7 +361,11 @@ func (bsp *batchSpanProcessor) drainQueue() {
|
||||
}
|
||||
}
|
||||
default:
|
||||
close(bsp.queue)
|
||||
// There are no more enqueued spans. Make final export.
|
||||
if err := bsp.exportSpans(ctx); err != nil {
|
||||
otel.Handle(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -358,34 +379,11 @@ func (bsp *batchSpanProcessor) enqueue(sd ReadOnlySpan) {
|
||||
}
|
||||
}
|
||||
|
||||
func recoverSendOnClosedChan() {
|
||||
x := recover()
|
||||
switch err := x.(type) {
|
||||
case nil:
|
||||
return
|
||||
case runtime.Error:
|
||||
if err.Error() == "send on closed channel" {
|
||||
return
|
||||
}
|
||||
}
|
||||
panic(x)
|
||||
}
|
||||
|
||||
func (bsp *batchSpanProcessor) enqueueBlockOnQueueFull(ctx context.Context, sd ReadOnlySpan) bool {
|
||||
if !sd.SpanContext().IsSampled() {
|
||||
return false
|
||||
}
|
||||
|
||||
// This ensures the bsp.queue<- below does not panic as the
|
||||
// processor shuts down.
|
||||
defer recoverSendOnClosedChan()
|
||||
|
||||
select {
|
||||
case <-bsp.stopCh:
|
||||
return false
|
||||
default:
|
||||
}
|
||||
|
||||
select {
|
||||
case bsp.queue <- sd:
|
||||
return true
|
||||
@ -399,16 +397,6 @@ func (bsp *batchSpanProcessor) enqueueDrop(ctx context.Context, sd ReadOnlySpan)
|
||||
return false
|
||||
}
|
||||
|
||||
// This ensures the bsp.queue<- below does not panic as the
|
||||
// processor shuts down.
|
||||
defer recoverSendOnClosedChan()
|
||||
|
||||
select {
|
||||
case <-bsp.stopCh:
|
||||
return false
|
||||
default:
|
||||
}
|
||||
|
||||
select {
|
||||
case bsp.queue <- sd:
|
||||
return true
|
||||
|
111
vendor/go.opentelemetry.io/otel/sdk/trace/provider.go
generated
vendored
111
vendor/go.opentelemetry.io/otel/sdk/trace/provider.go
generated
vendored
@ -75,8 +75,9 @@ func (cfg tracerProviderConfig) MarshalLog() interface{} {
|
||||
type TracerProvider struct {
|
||||
mu sync.Mutex
|
||||
namedTracer map[instrumentation.Scope]*tracer
|
||||
spanProcessors atomic.Value
|
||||
isShutdown bool
|
||||
spanProcessors atomic.Pointer[spanProcessorStates]
|
||||
|
||||
isShutdown atomic.Bool
|
||||
|
||||
// These fields are not protected by the lock mu. They are assumed to be
|
||||
// immutable after creation of the TracerProvider.
|
||||
@ -119,11 +120,11 @@ func NewTracerProvider(opts ...TracerProviderOption) *TracerProvider {
|
||||
}
|
||||
global.Info("TracerProvider created", "config", o)
|
||||
|
||||
spss := spanProcessorStates{}
|
||||
spss := make(spanProcessorStates, 0, len(o.processors))
|
||||
for _, sp := range o.processors {
|
||||
spss = append(spss, newSpanProcessorState(sp))
|
||||
}
|
||||
tp.spanProcessors.Store(spss)
|
||||
tp.spanProcessors.Store(&spss)
|
||||
|
||||
return tp
|
||||
}
|
||||
@ -136,10 +137,11 @@ func NewTracerProvider(opts ...TracerProviderOption) *TracerProvider {
|
||||
//
|
||||
// This method is safe to be called concurrently.
|
||||
func (p *TracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.Tracer {
|
||||
// This check happens before the mutex is acquired to avoid deadlocking if Tracer() is called from within Shutdown().
|
||||
if p.isShutdown.Load() {
|
||||
return trace.NewNoopTracerProvider().Tracer(name, opts...)
|
||||
}
|
||||
c := trace.NewTracerConfig(opts...)
|
||||
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
if name == "" {
|
||||
name = defaultTracerName
|
||||
}
|
||||
@ -148,44 +150,74 @@ func (p *TracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.T
|
||||
Version: c.InstrumentationVersion(),
|
||||
SchemaURL: c.SchemaURL(),
|
||||
}
|
||||
t, ok := p.namedTracer[is]
|
||||
if !ok {
|
||||
t = &tracer{
|
||||
provider: p,
|
||||
instrumentationScope: is,
|
||||
|
||||
t, ok := func() (trace.Tracer, bool) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
// Must check the flag after acquiring the mutex to avoid returning a valid tracer if Shutdown() ran
|
||||
// after the first check above but before we acquired the mutex.
|
||||
if p.isShutdown.Load() {
|
||||
return trace.NewNoopTracerProvider().Tracer(name, opts...), true
|
||||
}
|
||||
p.namedTracer[is] = t
|
||||
global.Info("Tracer created", "name", name, "version", c.InstrumentationVersion(), "schemaURL", c.SchemaURL())
|
||||
t, ok := p.namedTracer[is]
|
||||
if !ok {
|
||||
t = &tracer{
|
||||
provider: p,
|
||||
instrumentationScope: is,
|
||||
}
|
||||
p.namedTracer[is] = t
|
||||
}
|
||||
return t, ok
|
||||
}()
|
||||
if !ok {
|
||||
// This code is outside the mutex to not hold the lock while calling third party logging code:
|
||||
// - That code may do slow things like I/O, which would prolong the duration the lock is held,
|
||||
// slowing down all tracing consumers.
|
||||
// - Logging code may be instrumented with tracing and deadlock because it could try
|
||||
// acquiring the same non-reentrant mutex.
|
||||
global.Info("Tracer created", "name", name, "version", is.Version, "schemaURL", is.SchemaURL)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// RegisterSpanProcessor adds the given SpanProcessor to the list of SpanProcessors.
|
||||
func (p *TracerProvider) RegisterSpanProcessor(sp SpanProcessor) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
if p.isShutdown {
|
||||
// This check prevents calls during a shutdown.
|
||||
if p.isShutdown.Load() {
|
||||
return
|
||||
}
|
||||
newSPS := spanProcessorStates{}
|
||||
newSPS = append(newSPS, p.spanProcessors.Load().(spanProcessorStates)...)
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
// This check prevents calls after a shutdown.
|
||||
if p.isShutdown.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
current := p.getSpanProcessors()
|
||||
newSPS := make(spanProcessorStates, 0, len(current)+1)
|
||||
newSPS = append(newSPS, current...)
|
||||
newSPS = append(newSPS, newSpanProcessorState(sp))
|
||||
p.spanProcessors.Store(newSPS)
|
||||
p.spanProcessors.Store(&newSPS)
|
||||
}
|
||||
|
||||
// UnregisterSpanProcessor removes the given SpanProcessor from the list of SpanProcessors.
|
||||
func (p *TracerProvider) UnregisterSpanProcessor(sp SpanProcessor) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
if p.isShutdown {
|
||||
// This check prevents calls during a shutdown.
|
||||
if p.isShutdown.Load() {
|
||||
return
|
||||
}
|
||||
old := p.spanProcessors.Load().(spanProcessorStates)
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
// This check prevents calls after a shutdown.
|
||||
if p.isShutdown.Load() {
|
||||
return
|
||||
}
|
||||
old := p.getSpanProcessors()
|
||||
if len(old) == 0 {
|
||||
return
|
||||
}
|
||||
spss := spanProcessorStates{}
|
||||
spss = append(spss, old...)
|
||||
spss := make(spanProcessorStates, len(old))
|
||||
copy(spss, old)
|
||||
|
||||
// stop the span processor if it is started and remove it from the list
|
||||
var stopOnce *spanProcessorState
|
||||
@ -209,13 +241,13 @@ func (p *TracerProvider) UnregisterSpanProcessor(sp SpanProcessor) {
|
||||
spss[len(spss)-1] = nil
|
||||
spss = spss[:len(spss)-1]
|
||||
|
||||
p.spanProcessors.Store(spss)
|
||||
p.spanProcessors.Store(&spss)
|
||||
}
|
||||
|
||||
// ForceFlush immediately exports all spans that have not yet been exported for
|
||||
// all the registered span processors.
|
||||
func (p *TracerProvider) ForceFlush(ctx context.Context) error {
|
||||
spss := p.spanProcessors.Load().(spanProcessorStates)
|
||||
spss := p.getSpanProcessors()
|
||||
if len(spss) == 0 {
|
||||
return nil
|
||||
}
|
||||
@ -236,18 +268,21 @@ func (p *TracerProvider) ForceFlush(ctx context.Context) error {
|
||||
|
||||
// Shutdown shuts down TracerProvider. All registered span processors are shut down
|
||||
// in the order they were registered and any held computational resources are released.
|
||||
// After Shutdown is called, all methods are no-ops.
|
||||
func (p *TracerProvider) Shutdown(ctx context.Context) error {
|
||||
spss := p.spanProcessors.Load().(spanProcessorStates)
|
||||
if len(spss) == 0 {
|
||||
// This check prevents deadlocks in case of recursive shutdown.
|
||||
if p.isShutdown.Load() {
|
||||
return nil
|
||||
}
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
// This check prevents calls after a shutdown has already been done concurrently.
|
||||
if !p.isShutdown.CompareAndSwap(false, true) { // did toggle?
|
||||
return nil
|
||||
}
|
||||
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
p.isShutdown = true
|
||||
|
||||
var retErr error
|
||||
for _, sps := range spss {
|
||||
for _, sps := range p.getSpanProcessors() {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
@ -267,10 +302,14 @@ func (p *TracerProvider) Shutdown(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
p.spanProcessors.Store(spanProcessorStates{})
|
||||
p.spanProcessors.Store(&spanProcessorStates{})
|
||||
return retErr
|
||||
}
|
||||
|
||||
func (p *TracerProvider) getSpanProcessors() spanProcessorStates {
|
||||
return *(p.spanProcessors.Load())
|
||||
}
|
||||
|
||||
// TracerProviderOption configures a TracerProvider.
|
||||
type TracerProviderOption interface {
|
||||
apply(tracerProviderConfig) tracerProviderConfig
|
||||
|
9
vendor/go.opentelemetry.io/otel/sdk/trace/simple_span_processor.go
generated
vendored
9
vendor/go.opentelemetry.io/otel/sdk/trace/simple_span_processor.go
generated
vendored
@ -19,12 +19,13 @@ import (
|
||||
"sync"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/internal/global"
|
||||
)
|
||||
|
||||
// simpleSpanProcessor is a SpanProcessor that synchronously sends all
|
||||
// completed Spans to a trace.Exporter immediately.
|
||||
type simpleSpanProcessor struct {
|
||||
exporterMu sync.RWMutex
|
||||
exporterMu sync.Mutex
|
||||
exporter SpanExporter
|
||||
stopOnce sync.Once
|
||||
}
|
||||
@ -43,6 +44,8 @@ func NewSimpleSpanProcessor(exporter SpanExporter) SpanProcessor {
|
||||
ssp := &simpleSpanProcessor{
|
||||
exporter: exporter,
|
||||
}
|
||||
global.Warn("SimpleSpanProcessor is not recommended for production use, consider using BatchSpanProcessor instead.")
|
||||
|
||||
return ssp
|
||||
}
|
||||
|
||||
@ -51,8 +54,8 @@ func (ssp *simpleSpanProcessor) OnStart(context.Context, ReadWriteSpan) {}
|
||||
|
||||
// OnEnd immediately exports a ReadOnlySpan.
|
||||
func (ssp *simpleSpanProcessor) OnEnd(s ReadOnlySpan) {
|
||||
ssp.exporterMu.RLock()
|
||||
defer ssp.exporterMu.RUnlock()
|
||||
ssp.exporterMu.Lock()
|
||||
defer ssp.exporterMu.Unlock()
|
||||
|
||||
if ssp.exporter != nil && s.SpanContext().TraceFlags().IsSampled() {
|
||||
if err := ssp.exporter.ExportSpans(context.Background(), []ReadOnlySpan{s}); err != nil {
|
||||
|
6
vendor/go.opentelemetry.io/otel/sdk/trace/span.go
generated
vendored
6
vendor/go.opentelemetry.io/otel/sdk/trace/span.go
generated
vendored
@ -30,7 +30,7 @@ import (
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
"go.opentelemetry.io/otel/sdk/internal"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
@ -302,7 +302,7 @@ func (s *recordingSpan) addOverCapAttrs(limit int, attrs []attribute.KeyValue) {
|
||||
// most a length of limit. Each string slice value is truncated in this fashion
|
||||
// (the slice length itself is unaffected).
|
||||
//
|
||||
// No truncation is perfromed for a negative limit.
|
||||
// No truncation is performed for a negative limit.
|
||||
func truncateAttr(limit int, attr attribute.KeyValue) attribute.KeyValue {
|
||||
if limit < 0 {
|
||||
return attr
|
||||
@ -410,7 +410,7 @@ func (s *recordingSpan) End(options ...trace.SpanEndOption) {
|
||||
}
|
||||
s.mu.Unlock()
|
||||
|
||||
sps := s.tracer.provider.spanProcessors.Load().(spanProcessorStates)
|
||||
sps := s.tracer.provider.getSpanProcessors()
|
||||
if len(sps) == 0 {
|
||||
return
|
||||
}
|
||||
|
2
vendor/go.opentelemetry.io/otel/sdk/trace/span_exporter.go
generated
vendored
2
vendor/go.opentelemetry.io/otel/sdk/trace/span_exporter.go
generated
vendored
@ -38,7 +38,7 @@ type SpanExporter interface {
|
||||
// must never be done outside of a new major release.
|
||||
|
||||
// Shutdown notifies the exporter of a pending halt to operations. The
|
||||
// exporter is expected to preform any cleanup or synchronization it
|
||||
// exporter is expected to perform any cleanup or synchronization it
|
||||
// requires while honoring all timeouts and cancellations contained in
|
||||
// the passed context.
|
||||
Shutdown(ctx context.Context) error
|
||||
|
4
vendor/go.opentelemetry.io/otel/sdk/trace/span_processor.go
generated
vendored
4
vendor/go.opentelemetry.io/otel/sdk/trace/span_processor.go
generated
vendored
@ -62,11 +62,11 @@ type SpanProcessor interface {
|
||||
|
||||
type spanProcessorState struct {
|
||||
sp SpanProcessor
|
||||
state *sync.Once
|
||||
state sync.Once
|
||||
}
|
||||
|
||||
func newSpanProcessorState(sp SpanProcessor) *spanProcessorState {
|
||||
return &spanProcessorState{sp: sp, state: &sync.Once{}}
|
||||
return &spanProcessorState{sp: sp}
|
||||
}
|
||||
|
||||
type spanProcessorStates []*spanProcessorState
|
||||
|
2
vendor/go.opentelemetry.io/otel/sdk/trace/tracer.go
generated
vendored
2
vendor/go.opentelemetry.io/otel/sdk/trace/tracer.go
generated
vendored
@ -51,7 +51,7 @@ func (tr *tracer) Start(ctx context.Context, name string, options ...trace.SpanS
|
||||
|
||||
s := tr.newSpan(ctx, name, &config)
|
||||
if rw, ok := s.(ReadWriteSpan); ok && s.IsRecording() {
|
||||
sps := tr.provider.spanProcessors.Load().(spanProcessorStates)
|
||||
sps := tr.provider.getSpanProcessors()
|
||||
for _, sp := range sps {
|
||||
sp.sp.OnStart(ctx, rw)
|
||||
}
|
||||
|
20
vendor/go.opentelemetry.io/otel/sdk/trace/version.go
generated
vendored
Normal file
20
vendor/go.opentelemetry.io/otel/sdk/trace/version.go
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package trace // import "go.opentelemetry.io/otel/sdk/trace"
|
||||
|
||||
// version is the current release version of the metric SDK in use.
|
||||
func version() string {
|
||||
return "1.16.0-rc.1"
|
||||
}
|
Reference in New Issue
Block a user