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

package observ

import (
	
	
	

	
	
	
	
	
	semconv 
	
)

const (
	// 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.SDKProcessorLogProcessed{}.AttrErrorType("queue_full")

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

// BLP is the instrumentation for an OTel SDK BatchLogProcessor.
type BLP struct {
	reg metric.Registration

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

// NewBLP creates new instrumentation for a BatchLogProcessor.
// It returns nil if observability is not enabled.
func ( int64,  func() int64,  int64) (*BLP, error) {
	if !x.Observability.Enabled() {
		return nil, nil
	}
	if  == nil {
		return nil, errors.New("BLP qLen must not be nil")
	}

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

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

	,  := otelconv.NewSDKProcessorLogQueueSize()
	if  != nil {
		return nil, fmt.Errorf("failed to create BLP queue size metric: %w", )
	}
	 := .Inst()

	 := semconv.OTelComponentTypeBatchingLogProcessor
	 := BLPComponentName()
	 := attribute.NewSet(, )

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

	,  := otelconv.NewSDKProcessorLogProcessed()
	if  != nil {
		_ = .Unregister()
		return nil, fmt.Errorf("failed to create BLP processed logs metric: %w", )
	}

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

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

// Shutdown unregisters the callbacks registered by NewBLP.
func ( *BLP) () error {
	if  == nil || .reg == nil {
		return nil
	}
	return .reg.Unregister()
}

// Processed records n log records as having finished processing
// successfully.
func ( *BLP) ( context.Context,  int64) {
	if .processed.Enabled() {
		.processed.Add(, , .processedOpts...)
	}
}

// ProcessedQueueFull records n log records as having finished processing
// with a queue-full error.
func ( *BLP) ( context.Context,  int64) {
	if .processed.Enabled() {
		.processed.Add(, , .processedQueueFullOpts...)
	}
}