2024-03-13 17:47:07 +01:00
|
|
|
// Copyright The OpenTelemetry Authors
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package log // import "go.opentelemetry.io/otel/sdk/log"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Compile-time check SimpleProcessor implements Processor.
|
|
|
|
var _ Processor = (*SimpleProcessor)(nil)
|
|
|
|
|
|
|
|
// SimpleProcessor is an processor that synchronously exports log records.
|
2024-03-17 07:47:05 -07:00
|
|
|
type SimpleProcessor struct {
|
2024-04-09 10:22:50 +02:00
|
|
|
exporter Exporter
|
2024-03-17 07:47:05 -07:00
|
|
|
}
|
2024-03-13 17:47:07 +01:00
|
|
|
|
|
|
|
// NewSimpleProcessor is a simple Processor adapter.
|
|
|
|
//
|
|
|
|
// This Processor is not recommended for production use. The synchronous
|
|
|
|
// nature of this Processor make it good for testing, debugging, or
|
|
|
|
// showing examples of other features, but it can be slow and have a high
|
2024-04-19 08:34:30 +02:00
|
|
|
// computation resource usage overhead. [NewBatchProcessor] is recommended
|
2024-03-13 17:47:07 +01:00
|
|
|
// for production use instead.
|
2024-04-10 19:47:40 +02:00
|
|
|
func NewSimpleProcessor(exporter Exporter, _ ...SimpleProcessorOption) *SimpleProcessor {
|
2024-03-17 07:47:05 -07:00
|
|
|
if exporter == nil {
|
|
|
|
// Do not panic on nil exporter.
|
2024-03-19 10:33:57 -07:00
|
|
|
exporter = defaultNoopExporter
|
2024-03-17 07:47:05 -07:00
|
|
|
}
|
|
|
|
return &SimpleProcessor{exporter: exporter}
|
2024-03-13 17:47:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnEmit batches provided log record.
|
|
|
|
func (s *SimpleProcessor) OnEmit(ctx context.Context, r Record) error {
|
2024-03-17 07:47:05 -07:00
|
|
|
return s.exporter.Export(ctx, []Record{r})
|
2024-03-13 17:47:07 +01:00
|
|
|
}
|
|
|
|
|
2024-03-15 08:15:44 -07:00
|
|
|
// Enabled returns true.
|
|
|
|
func (s *SimpleProcessor) Enabled(context.Context, Record) bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-03-13 17:47:07 +01:00
|
|
|
// Shutdown shuts down the expoter.
|
|
|
|
func (s *SimpleProcessor) Shutdown(ctx context.Context) error {
|
2024-03-17 07:47:05 -07:00
|
|
|
return s.exporter.Shutdown(ctx)
|
2024-03-13 17:47:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ForceFlush flushes the exporter.
|
|
|
|
func (s *SimpleProcessor) ForceFlush(ctx context.Context) error {
|
2024-03-17 07:47:05 -07:00
|
|
|
return s.exporter.ForceFlush(ctx)
|
2024-03-13 17:47:07 +01:00
|
|
|
}
|
2024-04-10 19:47:40 +02:00
|
|
|
|
|
|
|
// SimpleProcessorOption applies a configuration to a [SimpleProcessor].
|
|
|
|
type SimpleProcessorOption interface {
|
|
|
|
apply()
|
|
|
|
}
|