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

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

import (
	
	
	

	
	
	
	
	
	semconv 
	
)

const (
	// ScopeName is the name of the instrumentation scope.
	ScopeName = "go.opentelemetry.io/otel/sdk/trace/internal/observ"

	// SchemaURL is the schema URL of the instrumentation.
	SchemaURL = semconv.SchemaURL
)

// ErrQueueFull is the attribute value for the "queue_full" error type.
var ErrQueueFull = otelconv.SDKProcessorSpanProcessed{}.AttrErrorType(
	otelconv.ErrorTypeAttr("queue_full"),
)

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

// BSP is the instrumentation for an OTel SDK BatchSpanProcessor.
type BSP struct {
	reg metric.Registration

	processed              metric.Int64Counter
	processedOpts          []metric.AddOption
	processedQueueFullOpts []metric.AddOption
}

func ( int64,  func() int64,  int64) (*BSP, error) {
	if !x.Observability.Enabled() {
		return nil, nil
	}

	 := otel.GetMeterProvider().Meter(
		ScopeName,
		metric.WithInstrumentationVersion(sdk.Version()),
		metric.WithSchemaURL(SchemaURL),
	)

	,  := otelconv.NewSDKProcessorSpanQueueCapacity()
	if  != nil {
		 = fmt.Errorf("failed to create BSP queue capacity metric: %w", )
	}
	 := .Inst()

	,  := otelconv.NewSDKProcessorSpanQueueSize()
	if  != nil {
		 := fmt.Errorf("failed to create BSP queue size metric: %w", )
		 = errors.Join(, )
	}
	 := .Inst()

	 := semconv.OTelComponentTypeBatchingSpanProcessor
	 := BSPComponentName()
	 := attribute.NewSet(, )

	 := []metric.ObserveOption{metric.WithAttributeSet()}
	,  := .RegisterCallback(
		func( context.Context,  metric.Observer) error {
			.ObserveInt64(, (), ...)
			.ObserveInt64(, , ...)
			return nil
		},
		,
		,
	)
	if  != nil {
		 := fmt.Errorf("failed to register BSP queue size/capacity callback: %w", )
		 = errors.Join(, )
	}

	,  := otelconv.NewSDKProcessorSpanProcessed()
	if  != nil {
		 := fmt.Errorf("failed to create BSP processed spans metric: %w", )
		 = errors.Join(, )
	}
	 := []metric.AddOption{metric.WithAttributeSet()}

	 = attribute.NewSet(, , ErrQueueFull)
	 := []metric.AddOption{metric.WithAttributeSet()}

	return &BSP{
		reg:                    ,
		processed:              .Inst(),
		processedOpts:          ,
		processedQueueFullOpts: ,
	}, 
}

func ( *BSP) () error { return .reg.Unregister() }

func ( *BSP) ( context.Context,  int64) {
	.processed.Add(, , .processedOpts...)
}

func ( *BSP) ( context.Context,  int64) {
	.processed.Add(, , .processedQueueFullOpts...)
}