Source File
simple.go
Belonging Package
go.opentelemetry.io/otel/sdk/log
// Copyright The OpenTelemetry Authors// SPDX-License-Identifier: Apache-2.0package logimport ()// This is a compile-time check that SimpleProcessor implements Processor.var _ Processor = (*SimpleProcessor)(nil)// SimpleProcessor is a processor that synchronously exports log records.//// Use [NewSimpleProcessor] to create a SimpleProcessor.type SimpleProcessor struct {mu sync.Mutexexporter Exporterinst *observ.SLPnoCmp [0]func() //nolint: unused // This is indeed used.}// NewSimpleProcessor is a simple Processor adapter.//// This Processor is not recommended for production use due to its synchronous// nature, which makes it suitable for testing, debugging, or demonstrating// other features, but can lead to slow performance and high computational// overhead. For production environments, use [NewBatchProcessor] instead.// However, there may be exceptions in which certain// [Exporter] implementations perform better with this Processor.func ( Exporter, ...SimpleProcessorOption) *SimpleProcessor {:= &SimpleProcessor{exporter: ,}var error.inst, = observ.NewSLP(observ.NextSimpleProcessorID())if != nil {otel.Handle()}return}var simpleProcRecordsPool = sync.Pool{New: func() any {:= make([]Record, 1)return &},}// Enabled returns true, indicating this Processor will process all records.func (*SimpleProcessor) (context.Context, EnabledParameters) bool {return true}// OnEmit synchronously exports the provided log record.func ( *SimpleProcessor) ( context.Context, *Record) error {if .exporter == nil {return nil}.mu.Lock()defer .mu.Unlock():= simpleProcRecordsPool.Get().(*[]Record)defer func() {clear(*)simpleProcRecordsPool.Put()}()(*)[0] = *if .inst != nil {// Record the log record as processed at the point it is submitted to// the exporter, independent of the export outcome..inst.LogProcessed()}return .exporter.Export(, *)}// Shutdown flushes the exporter before shutting it down.func ( *SimpleProcessor) ( context.Context) error {if .exporter == nil {return nil}return shutdownExporter(, .exporter)}// ForceFlush flushes the exporter.func ( *SimpleProcessor) ( context.Context) error {if .exporter == nil {return nil}return .exporter.ForceFlush()}// SimpleProcessorOption applies a configuration to a [SimpleProcessor].type SimpleProcessorOption interface {apply()}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |