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

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

import (
	
	
	
	

	
	
	
	
	
	semconv 
	
)

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

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 &
	},
}

// simpleProcessorN is a global 0-based count of the number of simple processor created.
var simpleProcessorN atomic.Int64

// NextSimpleProcessorID returns the next unique ID for a simpleProcessor.
func () int64 {
	const  = 1
	return simpleProcessorN.Add() - 
}

// SetSimpleProcessorID sets the exporter ID counter to v and returns the previous
// value.
//
// This function is useful for testing purposes, allowing you to reset the
// counter. It should not be used in production code.
func ( int64) int64 {
	return simpleProcessorN.Swap()
}

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

// SLP is the instrumentation for an OTel SDK SimpleLogProcessor.
type SLP struct {
	processed metric.Int64Counter
	attrs     []attribute.KeyValue
	addOpts   []metric.AddOption
}

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

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

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

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

	return &SLP{
		processed: .Inst(),
		attrs:     ,
		addOpts:   ,
	}, nil
}

// LogProcessed records that a log has been processed by the SimpleLogProcessor.
// If err is non-nil, it records the processing error as an attribute.
func ( *SLP) ( context.Context,  error) {
	if .processed.Enabled() {
		.processed.Add(, 1, .addOption()...)
	}
}

func ( *SLP) ( error) []metric.AddOption {
	if  == nil {
		return .addOpts
	}
	 := measureAttrsPool.Get().(*[]attribute.KeyValue)
	defer func() {
		* = (*)[:0] // reset the slice
		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(*...))}
}