// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package observ // import "go.opentelemetry.io/otel/sdk/trace/internal/observ"

import (
	
	
	

	
	
	
	
	
	semconv 
	
)

var measureAttrsPool = sync.Pool{
	New: func() any {
		// "component.name" + "component.type" + "error.type"
		const  = 1 + 1 + 1
		 := make([]attribute.KeyValue, 0, )
		// Return a pointer to a slice instead of a slice itself
		// to avoid allocations on every call.
		return &
	},
}

// SSP is the instrumentation for an OTel SDK SimpleSpanProcessor.
type SSP struct {
	spansProcessedCounter metric.Int64Counter
	addOpts               []metric.AddOption
	attrs                 []attribute.KeyValue
}

// SSPComponentName returns the component name attribute for a
// SimpleSpanProcessor with the given ID.
func ( int64) attribute.KeyValue {
	 := otelconv.ComponentTypeSimpleSpanProcessor
	 := fmt.Sprintf("%s/%d", , )
	return semconv.OTelComponentName()
}

// NewSSP returns instrumentation for an OTel SDK SimpleSpanProcessor with the
// provided ID.
//
// If the experimental observability is disabled, nil is returned.
func ( int64) (*SSP, error) {
	if !x.Observability.Enabled() {
		return nil, nil
	}

	 := otel.GetMeterProvider().Meter(
		ScopeName,
		metric.WithInstrumentationVersion(sdk.Version()),
		metric.WithSchemaURL(SchemaURL),
	)
	,  := otelconv.NewSDKProcessorSpanProcessed()
	if  != nil {
		 = fmt.Errorf("failed to create SSP processed spans metric: %w", )
	}

	 := SSPComponentName()
	 := .AttrComponentType(otelconv.ComponentTypeSimpleSpanProcessor)
	 := []attribute.KeyValue{, }
	 := []metric.AddOption{metric.WithAttributeSet(attribute.NewSet(...))}

	return &SSP{
		spansProcessedCounter: .Inst(),
		addOpts:               ,
		attrs:                 ,
	}, 
}

// SpanProcessed records that a span has been processed by the SimpleSpanProcessor.
// If err is non-nil, it records the processing error as an attribute.
func ( *SSP) ( context.Context,  error) {
	.spansProcessedCounter.Add(, 1, .addOption()...)
}

func ( *SSP) ( error) []metric.AddOption {
	if  == nil {
		return .addOpts
	}
	 := measureAttrsPool.Get().(*[]attribute.KeyValue)
	defer func() {
		* = (*)[:0] // reset the slice for reuse
		measureAttrsPool.Put()
	}()
	* = append(*, .attrs...)
	* = append(*, semconv.ErrorType())
	// Do not inefficiently make a copy of attrs by using
	// WithAttributes instead of WithAttributeSet.
	return []metric.AddOption{metric.WithAttributeSet(attribute.NewSet(*...))}
}