logs

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2024 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultMaxQueueSize       = 2048
	DefaultScheduleDelay      = 5000
	DefaultExportTimeout      = 30000
	DefaultMaxExportBatchSize = 512
)

Defaults for BatchLogRecordProcessorOptions.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchLogRecordProcessorOption

type BatchLogRecordProcessorOption func(o *BatchLogRecordProcessorOptions)

BatchLogRecordProcessorOption configures a BatchLogsProcessor.

func WithBatchTimeout

func WithBatchTimeout(delay time.Duration) BatchLogRecordProcessorOption

WithBatchTimeout returns a BatchLogRecordProcessorOption that configures the maximum delay allowed for a BatchLogRecordProcessor before it will export any held log (whether the queue is full or not).

func WithBlocking

func WithBlocking() BatchLogRecordProcessorOption

WithBlocking returns a BatchLogRecordProcessorOption that configures a BatchLogRecordProcessor to wait for enqueue operations to succeed instead of dropping data when the queue is full.

func WithExportTimeout

func WithExportTimeout(timeout time.Duration) BatchLogRecordProcessorOption

WithExportTimeout returns a BatchLogRecordProcessorOption that configures the amount of time a BatchLogRecordProcessor waits for an exporter to export before abandoning the export.

func WithMaxExportBatchSize

func WithMaxExportBatchSize(size int) BatchLogRecordProcessorOption

WithMaxExportBatchSize returns a BatchLogRecordProcessorOption that configures the maximum export batch size allowed for a BatchLogRecordProcessor.

func WithMaxQueueSize

func WithMaxQueueSize(size int) BatchLogRecordProcessorOption

WithMaxQueueSize returns a BatchLogRecordProcessorOption that configures the maximum queue size allowed for a BatchLogRecordProcessor.

type BatchLogRecordProcessorOptions

type BatchLogRecordProcessorOptions struct {
	// MaxQueueSize is the maximum queue size to buffer logs for delayed processing. If the
	// queue gets full it drops the logs. Use BlockOnQueueFull to change this behavior.
	// The default value of MaxQueueSize is 2048.
	MaxQueueSize int

	// BatchTimeout is the maximum duration for constructing a batch. Processor
	// forcefully sends available logs when timeout is reached.
	// The default value of BatchTimeout is 5000 msec.
	BatchTimeout time.Duration

	// ExportTimeout specifies the maximum duration for exporting logs. If the timeout
	// is reached, the export will be cancelled.
	// The default value of ExportTimeout is 30000 msec.
	ExportTimeout time.Duration

	// MaxExportBatchSize is the maximum number of logs to process in a single batch.
	// If there are more than one batch worth of logs then it processes multiple batches
	// of logs one batch after the other without any delay.
	// The default value of MaxExportBatchSize is 512.
	MaxExportBatchSize int

	// BlockOnQueueFull blocks onEnd() and onStart() method if the queue is full
	// AND if BlockOnQueueFull is set to true.
	// Blocking option should be used carefully as it can severely affect the performance of an
	// application.
	BlockOnQueueFull bool
}

BatchLogRecordProcessorOptions is configuration settings for a BatchLogsProcessor.

type LogRecordExporter

type LogRecordExporter interface {

	// Export exports a batch of logs.
	//
	// This function is called synchronously, so there is no concurrency
	// safety requirement. However, due to the synchronous calling pattern,
	// it is critical that all timeouts and cancellations contained in the
	// passed context must be honored.
	//
	// Any retry logic must be contained in this function. The SDK that
	// calls this function will not implement any retry logic. All errors
	// returned by this function are considered unrecoverable and will be
	// reported to a configured error Handler.
	Export(ctx context.Context, batch []ReadableLogRecord) error

	// Shutdown notifies the exporter of a pending halt to operations. The
	// exporter is expected to perform any cleanup or synchronization it
	// requires while honoring all timeouts and cancellations contained in
	// the passed context.
	Shutdown(ctx context.Context) error
}

LogRecordExporter Interface for various logs exporters see https://opentelemetry.io/docs/specs/otel/logs/sdk/#logrecordexporter

type LogRecordProcessor

type LogRecordProcessor interface {

	// OnEmit is called when logs sent. It is called synchronously and
	// hence not block.
	OnEmit(rol ReadableLogRecord)

	// Shutdown is called when the SDK shuts down. Any cleanup or release of
	// resources held by the processor should be done in this call.
	//
	// Calls to Process, or ForceFlush after this has been called
	// should be ignored.
	//
	// All timeouts and cancellations contained in ctx must be honored, this
	// should not block indefinitely.
	Shutdown(ctx context.Context) error

	// ForceFlush exports all ended logs to the configured Exporter that have not yet
	// been exported.  It should only be called when absolutely necessary, such as when
	// using a FaaS provider that may suspend the process after an invocation, but before
	// the Processor can export the completed logs.
	ForceFlush(ctx context.Context) error
}

LogRecordProcessor is an interface which allows hooks for LogRecord emitting. see https://opentelemetry.io/docs/specs/otel/logs/sdk/#logrecordprocessor

func NewBatchLogRecordProcessor

func NewBatchLogRecordProcessor(exporter LogRecordExporter, options ...BatchLogRecordProcessorOption) LogRecordProcessor

NewBatchLogRecordProcessor creates a new LogRecordProcessor that will send completed log batches to the exporter with the supplied options.

If the exporter is nil, the logs processor will perform no action. see https://opentelemetry.io/docs/specs/otel/logs/sdk/#batching-processor

func NewSimpleLogRecordProcessor

func NewSimpleLogRecordProcessor(exporter LogRecordExporter) LogRecordProcessor

NewSimpleLogRecordProcessor returns a new LogRecordProcessor that will synchronously send completed logs to the exporter immediately.

This LogRecordProcessor is not recommended for production use. The synchronous nature of this LogRecordProcessor make it good for testing, debugging, or showing examples of other feature, but it will be slow and have a high computation resource usage overhead. The BatchLogsProcessor is recommended for production use instead.

type LoggerProvider

type LoggerProvider struct {
	// contains filtered or unexported fields
}

LoggerProvider provide access to Logger. The API is not intended to be called by application developers directly. see https://opentelemetry.io/docs/specs/otel/logs/bridge-api/#loggerprovider

func NewLoggerProvider

func NewLoggerProvider(opts ...LoggerProviderOption) *LoggerProvider

func (*LoggerProvider) ForceFlush

func (p *LoggerProvider) ForceFlush(ctx context.Context) error

ForceFlush immediately exports all logs that have not yet been exported for all the registered log processors.

func (*LoggerProvider) Logger

func (lp *LoggerProvider) Logger(name string, opts ...logs.LoggerOption) logs.Logger

func (LoggerProvider) Shutdown

func (p LoggerProvider) Shutdown(ctx context.Context) error

type LoggerProviderOption

type LoggerProviderOption interface {
	// contains filtered or unexported methods
}

LoggerProviderOption configures a LoggerProvider.

func WithBatcher

WithBatcher registers the exporter with the LoggerProvider using a BatchLogRecordProcessor configured with the passed opts.

func WithLogRecordProcessor

func WithLogRecordProcessor(logsProcessor LogRecordProcessor) LoggerProviderOption

WithLogRecordProcessor will configure processor to process logs

func WithResource

func WithResource(r *resource.Resource) LoggerProviderOption

WithResource will configure OTLP logger with common resource attributes.

Parameters: r (*resource.Resource) list of resources will be added to every log as resource level tags

func WithSyncer

WithSyncer registers the exporter with the LoggerProvider using a SimpleLogRecordProcessor.

This is not recommended for production use. The synchronous nature of the SimpleLogRecordProcessor that will wrap the exporter make it good for testing, debugging, or showing examples of other feature, but it will be slow and have a high computation resource usage overhead. The WithBatcher option is recommended for production use instead.

type ReadWriteLogRecord

type ReadWriteLogRecord interface {
	SetResource(resource *resource.Resource)
	// RecordException message, stacktrace, type
	RecordException(*string, *string, *string)
	ReadableLogRecord
}

type ReadableLogRecord

type ReadableLogRecord interface {
	// Timestamp Time when the event occurred.
	Timestamp() *time.Time
	// ObservedTimestamp	Time when the event was observed.
	ObservedTimestamp() time.Time
	// TraceId Request trace id.
	TraceId() *trace.TraceID
	// SpanId Request span id.
	SpanId() *trace.SpanID
	// TraceFlags W3C trace flag.
	TraceFlags() *trace.TraceFlags
	// SeverityText This is the original string representation of the severityNumber as it is known at the source
	SeverityText() *string
	// SeverityNumber	Numerical value of the severityNumber.
	SeverityNumber() *logs.SeverityNumber
	// Body The body of the log record.
	Body() any
	// Resource 	Describes the source of the log.
	Resource() *resource.Resource
	// InstrumentationScope returns information about the instrumentation
	// scope that created the log.
	InstrumentationScope() *instrumentation.Scope
	// Attributes describe the aspects of the event.
	Attributes() *[]attribute.KeyValue
	// contains filtered or unexported methods
}

ReadableLogRecord Log structure see https://opentelemetry.io/docs/specs/otel/logs/data-model/#log-and-event-record-definition see https://opentelemetry.io/docs/specs/otel/logs/sdk/#readablelogrecord

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL