Documentation
¶
Overview ¶
Package log provides the OpenTelemetry Logs SDK.
See https://opentelemetry.io/docs/concepts/signals/logs/ for information about OpenTelemetry Logs and https://opentelemetry.io/docs/concepts/components/ for more information about OpenTelemetry SDKs.
The entry point for the log package is NewLoggerProvider. LoggerProvider is the object that all Bridge API calls use to create Loggers and ultimately emit log records. It should also be used to control the lifecycle (start, flush, and shutdown) of the Logs SDK.
A LoggerProvider needs to be configured to process log records. This is done by configuring it with a Processor implementation using WithProcessor. The log package provides BatchProcessor and SimpleProcessor, which are configured with an Exporter implementation that exports log records to a given destination. See go.opentelemetry.io/otel/exporters for exporters that can be used with these Processors.
A LoggerProvider needs to include information about the origin of the data it generates. It needs to be configured with a Resource by using WithResource to include this information. This Resource should describe the unique runtime environment in which the instrumented code runs. That way, when telemetry from multiple instances of the code is collected at a single endpoint, the origin of each instance is decipherable.
See go.opentelemetry.io/otel/sdk/log/internal/x for information about the experimental features.
See go.opentelemetry.io/otel/log for more information about the OpenTelemetry Logs API.
Example ¶
Initialize the OpenTelemetry Logs SDK and set up logging using a log bridge.
package main
import (
"context"
"fmt"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/sdk/log"
)
func main() {
// Create an exporter that will emit log records.
// For example, use
// go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp to send logs
// using OTLP over HTTP:
// exporter, err := otlploghttp.New(ctx)
var exporter log.Exporter
// Create a log record processor pipeline.
processor := log.NewBatchProcessor(exporter)
// Create a logger provider.
// You can pass this instance directly when creating a log bridge.
provider := log.NewLoggerProvider(
log.WithProcessor(processor),
)
// Handle shutdown properly so that nothing leaks.
defer func() {
err := provider.Shutdown(context.Background())
if err != nil {
fmt.Println(err)
}
}()
// Register it as the global logger provider so that it can be used via
// otel.Logger and accessed using otel.GetLoggerProvider.
// Most log bridges use the global logger provider by default.
// If the global logger provider is not set, then a no-op implementation
// is used, which fails to generate data.
otel.SetLoggerProvider(provider)
// Use a bridge so that you can emit logs using your preferred Go logging
// library. For example, use go.opentelemetry.io/contrib/bridges/otelslog so
// that you can use log/slog:
// slog.SetDefault(otelslog.NewLogger("my/pkg/name", otelslog.WithLoggerProvider(provider)))
}
Output:
Index ¶
- Variables
- type BatchProcessor
- type BatchProcessorOption
- type EnabledParameters
- type Exporter
- type LoggerProvider
- type LoggerProviderOption
- func WithAllowKeyDuplication() LoggerProviderOption
- func WithAttributeCountLimit(limit int) LoggerProviderOption
- func WithAttributeValueDepthLimit(limit int) LoggerProviderOption
- func WithAttributeValueLengthLimit(limit int) LoggerProviderOption
- func WithProcessor(processor Processor) LoggerProviderOption
- func WithResource(res *resource.Resource) LoggerProviderOption
- type Processor
- type Record
- func (r *Record) AddAttributes(attrs ...attribute.KeyValue)
- func (r *Record) AttributesLen() int
- func (r *Record) Body() attribute.Value
- func (r *Record) Clone() Record
- func (r *Record) DroppedAttributes() int
- func (r *Record) EventName() string
- func (r *Record) InstrumentationScope() instrumentation.Scope
- func (r *Record) ObservedTimestamp() time.Time
- func (r *Record) Resource() *resource.Resource
- func (r *Record) SetAttributes(attrs ...attribute.KeyValue)
- func (r *Record) SetBody(v attribute.Value)
- func (r *Record) SetEventName(s string)
- func (r *Record) SetObservedTimestamp(t time.Time)
- func (r *Record) SetSeverity(level log.Severity)
- func (r *Record) SetSeverityText(text string)
- func (r *Record) SetSpanID(id trace.SpanID)
- func (r *Record) SetTimestamp(t time.Time)
- func (r *Record) SetTraceFlags(flags trace.TraceFlags)
- func (r *Record) SetTraceID(id trace.TraceID)
- func (r *Record) Severity() log.Severity
- func (r *Record) SeverityText() string
- func (r *Record) SpanID() trace.SpanID
- func (r *Record) Timestamp() time.Time
- func (r *Record) TraceFlags() trace.TraceFlags
- func (r *Record) TraceID() trace.TraceID
- func (r *Record) WalkAttributes(f func(attribute.KeyValue) bool)
- type SimpleProcessor
- type SimpleProcessorOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrExporterShutdown = errors.New("exporter is shutdown")
ErrExporterShutdown is returned if Export is called after an Exporter has been Shutdown.
Functions ¶
This section is empty.
Types ¶
type BatchProcessor ¶
type BatchProcessor struct {
// contains filtered or unexported fields
}
BatchProcessor is a processor that exports batches of log records.
Use NewBatchProcessor to create a BatchProcessor. An empty BatchProcessor is shut down by default, so no records will be batched or exported.
func NewBatchProcessor ¶
func NewBatchProcessor(exporter Exporter, opts ...BatchProcessorOption) *BatchProcessor
NewBatchProcessor decorates the provided exporter so that the log records are batched before they are exported.
Calls to the exporter's Export, ForceFlush, and Shutdown methods are synchronized and never invoked concurrently.
func (*BatchProcessor) Enabled ¶
func (*BatchProcessor) Enabled(context.Context, EnabledParameters) bool
Enabled returns true, indicating this Processor will process all records.
func (*BatchProcessor) ForceFlush ¶
func (b *BatchProcessor) ForceFlush(ctx context.Context) error
ForceFlush flushes queued log records and flushes the decorated exporter.
type BatchProcessorOption ¶
type BatchProcessorOption interface {
// contains filtered or unexported methods
}
BatchProcessorOption applies a configuration to a BatchProcessor.
func WithExportBufferSize
deprecated
added in
v0.7.0
func WithExportBufferSize(_ int) BatchProcessorOption
WithExportBufferSize is retained for source compatibility and has no effect. The processor no longer maintains a separately configurable export-request buffer. WithMaxQueueSize bounds the pending-record queue.
Deprecated: This option is no longer used.
func WithExportInterval ¶
func WithExportInterval(d time.Duration) BatchProcessorOption
WithExportInterval sets the maximum duration between batched exports.
If the OTEL_BLRP_SCHEDULE_DELAY environment variable is set and this option is not passed, the value of that variable will be used.
By default, if the environment variable is not set and this option is not passed, 1s will be used. The default value is also used when the provided value is less than one.
func WithExportMaxBatchSize ¶
func WithExportMaxBatchSize(size int) BatchProcessorOption
WithExportMaxBatchSize sets the maximum batch size of every export. A batch will be split into multiple exports so that none exceed this size.
If the OTEL_BLRP_MAX_EXPORT_BATCH_SIZE environment variable is set and this option is not passed, the value of that variable will be used.
By default, if the environment variable is not set and this option is not passed, 512 or the maximum queue size, if smaller, will be used. The default value is also used when the provided value is less than one. The effective batch size will not exceed the configured maximum queue size.
func WithExportTimeout ¶
func WithExportTimeout(d time.Duration) BatchProcessorOption
WithExportTimeout sets the duration after which a batched export is canceled.
If the OTEL_BLRP_EXPORT_TIMEOUT environment variable is set and this option is not passed, the value of that variable will be used.
By default, if the environment variable is not set and this option is not passed, 30s will be used. The default value is also used when the provided value is less than one.
func WithMaxQueueSize ¶
func WithMaxQueueSize(size int) BatchProcessorOption
WithMaxQueueSize sets the maximum queue size used by the Batcher. After the size is reached, log records are dropped.
If the OTEL_BLRP_MAX_QUEUE_SIZE environment variable is set and this option is not passed, the value of that variable will be used.
By default, if the environment variable is not set and this option is not passed, 2048 will be used. The default value is also used when the provided value is less than one.
type EnabledParameters ¶ added in v0.11.0
type EnabledParameters struct {
InstrumentationScope instrumentation.Scope
Severity log.Severity
EventName string
}
EnabledParameters represents the payload for Processor.Enabled.
type Exporter ¶
type Exporter interface {
// Export transmits log records to a receiver.
//
// The deadline or cancellation of the passed context must be honored. An
// appropriate error should be returned in these situations.
//
// All retry logic must be contained in this function. The SDK does not
// implement any retry logic. All errors returned by this function are
// considered unrecoverable and will be reported to a configured error
// Handler.
//
// Implementations must not retain the records slice.
//
// Before modifying a Record, the implementation must use Record.Clone
// to create a copy that shares no state with the original.
//
// Export should return [ErrExporterShutdown] if called after Shutdown.
//
// Export should never be called concurrently with other Export calls.
// However, it may be called concurrently with other methods.
Export(ctx context.Context, records []Record) error
// Shutdown is called when the SDK shuts down. Any cleanup or release of
// resources held by the exporter should be done in this call.
//
// The deadline or cancellation of the passed context must be honored. An
// appropriate error should be returned in these situations.
//
// After Shutdown is called, calls to Shutdown or ForceFlush should perform
// no operation and return nil. Calls to Export should return
// [ErrExporterShutdown].
//
// Shutdown may be called concurrently with itself or with other methods.
Shutdown(ctx context.Context) error
// ForceFlush flushes any log records held by the Exporter.
//
// The deadline or cancellation of the passed context must be honored. An
// appropriate error should be returned in these situations.
//
// ForceFlush may be called concurrently with itself or with other methods.
ForceFlush(ctx context.Context) error
}
Exporter handles the delivery of log records to external receivers.
type LoggerProvider ¶
type LoggerProvider struct {
embedded.LoggerProvider
// contains filtered or unexported fields
}
LoggerProvider handles the creation and coordination of Loggers. All Loggers it creates are associated with the same Resource.
After LoggerProvider.Shutdown starts, calls to log.Logger.Enabled on Loggers created by the LoggerProvider return false, and calls to log.Logger.Emit perform no operation.
func NewLoggerProvider ¶
func NewLoggerProvider(opts ...LoggerProviderOption) *LoggerProvider
NewLoggerProvider returns a new, configured LoggerProvider.
By default, the returned LoggerProvider is configured with the default Resource and no Processors. Processors cannot be added after a LoggerProvider is created. This means the returned LoggerProvider, one created with no Processors, will perform no operations.
func (*LoggerProvider) ForceFlush ¶
func (p *LoggerProvider) ForceFlush(ctx context.Context) error
ForceFlush flushes all processors.
Once Shutdown starts, ForceFlush performs no operation and returns nil.
This method can be called concurrently.
func (*LoggerProvider) Logger ¶
func (p *LoggerProvider) Logger(name string, opts ...log.LoggerOption) log.Logger
Logger returns a new log.Logger with the provided name and configuration.
Calls made after LoggerProvider.Shutdown starts return a noop.Logger.
Instrumentation scope attributes with invalid keys are ignored.
This method can be called concurrently.
func (*LoggerProvider) Shutdown ¶
func (p *LoggerProvider) Shutdown(ctx context.Context) error
Shutdown shuts down the provider and all processors in the order they were registered.
The first call stops admitting new operations that invoke a processor's Enabled, OnEmit, or ForceFlush method. It waits for operations already admitted to complete before synchronously invoking each processor's Shutdown method. If ctx is canceled before the admitted operations complete, Shutdown returns ctx.Err() without invoking any processor's Shutdown method.
Concurrent or subsequent Shutdown calls return nil without invoking any processor's Shutdown method.
Shutdown must not be called directly or indirectly from a Processor method.
This method can be called concurrently.
type LoggerProviderOption ¶
type LoggerProviderOption interface {
// contains filtered or unexported methods
}
LoggerProviderOption applies a configuration option value to a LoggerProvider.
func WithAllowKeyDuplication ¶ added in v0.14.0
func WithAllowKeyDuplication() LoggerProviderOption
WithAllowKeyDuplication sets whether deduplication is skipped for log record and instrumentation scope key-value collections.
By default, the key-value collections within a log record and an instrumentation scope are deduplicated to comply with the OpenTelemetry Specification. Deduplication means that if multiple key-value pairs with the same key are present, only a single pair is retained and the others are discarded. Resource attributes are always deduplicated by go.opentelemetry.io/otel/sdk/resource.
Disabling deduplication with this option can improve performance when adding attributes to the log record.
Receivers may handle duplicate keys unpredictably. If you disable deduplication, you are responsible for ensuring that duplicate keys within a single collection are not emitted, or that the telemetry receiver can handle such duplicates.
func WithAttributeCountLimit ¶
func WithAttributeCountLimit(limit int) LoggerProviderOption
WithAttributeCountLimit sets the maximum allowed log record attribute count. Any attribute added to a log record once this limit is reached will be dropped.
Setting this to zero means no attributes will be recorded.
Setting this to a negative value means no limit is applied.
If the OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT environment variable is set and this option is not passed, the value of that variable will be used.
By default, if the environment variable is not set and this option is not passed, 128 will be used.
func WithAttributeValueDepthLimit ¶ added in v1.47.0
func WithAttributeValueDepthLimit(limit int) LoggerProviderOption
WithAttributeValueDepthLimit sets the maximum allowed depth for attribute values. Depth starts at one for the top-level value and increments when descending into an array element or map value. An array or map beyond this depth is replaced by an empty value.
This limit applies to log record and instrumentation scope attributes processed by this LoggerProvider. It does not apply to Resource attributes or log record bodies.
Setting this to zero means the default limit of 64 is used. Setting this to a negative value means no limit is applied.
There is no environment variable for this limit.
func WithAttributeValueLengthLimit ¶
func WithAttributeValueLengthLimit(limit int) LoggerProviderOption
WithAttributeValueLengthLimit sets the maximum allowed attribute value length.
This limit only applies to string, string slice, and byte slice attribute values. Strings and byte slices longer than this value will be truncated to this length.
Setting this to a negative value means no limit is applied.
If the OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT environment variable is set and this option is not passed, the value of that variable will be used.
By default, if the environment variable is not set and this option is not passed, no limit (-1) will be used.
func WithProcessor ¶
func WithProcessor(processor Processor) LoggerProviderOption
WithProcessor associates a Processor with a LoggerProvider.
By default, if this option is not used, the LoggerProvider will perform no operations; no data will be exported without a processor.
The SDK invokes the processors sequentially in the same order as they were registered.
For production, use NewBatchProcessor to batch log records before they are exported. For testing and debugging, use NewSimpleProcessor to synchronously export log records.
func WithResource ¶
func WithResource(res *resource.Resource) LoggerProviderOption
WithResource associates a Resource with a LoggerProvider. This Resource represents the entity producing telemetry and is associated with all Loggers the LoggerProvider will create.
By default, if this Option is not used, the default Resource from the go.opentelemetry.io/otel/sdk/resource package will be used.
type Processor ¶
type Processor interface {
// Enabled reports whether the Processor will process a Record for the given
// context and param.
//
// Enabled is called synchronously and should not block.
//
// The param contains a subset of the information that will be available
// in the Record passed to OnEmit, as defined by EnabledParameters.
// A field being unset in param does not imply the corresponding field
// in the Record passed to OnEmit will be unset. For example, a log bridge
// may be unable to populate all fields in EnabledParameters even though
// they are present on the final Record.
//
// The returned value is true if the Processor would process a Record for the
// provided context and param, and false otherwise.
//
// Implementations that need additional information beyond what is provided
// in param should treat the decision as indeterminate and default to
// returning true, unless they have a specific reason to return false
// (for example, to meet performance or correctness constraints).
//
// Processor implementations are expected to re-evaluate the [Record] passed
// to OnEmit. It is not expected that the caller of OnEmit will
// use the result of Enabled prior to calling OnEmit.
//
// The SDK's Logger.Enabled returns false if all the registered processors
// return false. Otherwise, it returns true.
//
Enabled(ctx context.Context, param EnabledParameters) bool
// OnEmit is called when a Record is emitted.
//
// OnEmit is called synchronously and should not block.
//
// OnEmit will be called independently of Enabled. Implementations need to
// validate the arguments themselves before processing.
//
// Implementations should not stop processing a Record solely because the
// context is canceled.
//
// Any retry or recovery logic needed by the Processor must be handled
// inside this function. The SDK does not implement any retry logic.
// Errors returned by this function are treated as unrecoverable by the SDK
// and will be reported to a configured error Handler.
//
// The SDK invokes the processors sequentially in the same order as they were
// registered with WithProcessor.
// Implementations may synchronously modify the record so that the changes
// are visible in the next registered processor.
//
// Note that Record is not concurrent-safe. Therefore, asynchronous
// processing may cause race conditions. Use Record.Clone
// to create a copy that shares no state with the original.
OnEmit(ctx context.Context, record *Record) error
// Shutdown is called when the SDK shuts down. Any cleanup or release of
// resources held by the Processor (and any underlying Exporter) should be
// done in this call.
//
// A LoggerProvider calls Shutdown at most once. Before calling it, the
// LoggerProvider waits for all Enabled, OnEmit, and ForceFlush calls it
// admitted to complete. If the LoggerProvider's Shutdown context is canceled
// while waiting, Shutdown is not called.
//
// Shutdown must include the effects of ForceFlush.
//
// The deadline or cancellation of the passed context must be honored. An
// appropriate error should be returned in these situations.
//
// After Shutdown is called, calls to OnEmit, Shutdown, or ForceFlush
// should perform no operation and return nil.
Shutdown(ctx context.Context) error
// ForceFlush exports any log records that have not yet been exported to the
// configured Exporter.
//
// The deadline or cancellation of the passed context must be honored. An
// appropriate error should be returned in these situations.
ForceFlush(ctx context.Context) error
}
Processor handles the processing of log records.
Enabled, OnEmit, and ForceFlush may be called concurrently with themselves or each other. It is the responsibility of the Processor to manage this concurrency.
A Processor must be registered only once and with a single LoggerProvider. Registering the same Processor with multiple providers or multiple times with the same provider is not supported.
A LoggerProvider stops admitting new operations that invoke Enabled, OnEmit, or ForceFlush when shutdown starts. Callers that use a Processor directly are responsible for coordinating those calls with Shutdown.
Example (ContextFilter) ¶
Use a processor that filters out records based on the provided context.
package main
import (
"context"
"go.opentelemetry.io/otel/sdk/log"
)
func main() {
// Existing processor that emits telemetry.
var processor log.Processor = log.NewBatchProcessor(nil)
// Wrap the processor so that it ignores processing log records
// when a context derived from WithIgnoreLogs is passed
// to the logging methods.
processor = &ContextFilterProcessor{Processor: processor}
// The created processor can then be registered with
// the OpenTelemetry Logs SDK using the WithProcessor option.
_ = log.NewLoggerProvider(
log.WithProcessor(processor),
)
}
type key struct{}
var ignoreLogsKey key
// ContextFilterProcessor filters out logs when a context derived from
// [WithIgnoreLogs] is passed to its methods.
type ContextFilterProcessor struct {
log.Processor
}
func (p *ContextFilterProcessor) OnEmit(ctx context.Context, record *log.Record) error {
if ignoreLogs(ctx) {
return nil
}
return p.Processor.OnEmit(ctx, record)
}
func (p *ContextFilterProcessor) Enabled(ctx context.Context, param log.EnabledParameters) bool {
return !ignoreLogs(ctx) && p.Processor.Enabled(ctx, param)
}
func ignoreLogs(ctx context.Context) bool {
_, ok := ctx.Value(ignoreLogsKey).(bool)
return ok
}
Output:
Example (EventName) ¶
Use a processor that sets EventName on log records with an "otel.event.name" string attribute. This is useful for users of logging libraries that do not support setting the event name on log records, but do support attributes.
package main
import (
"context"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/log"
)
func main() {
// Existing processor that emits telemetry.
var processor log.Processor = log.NewBatchProcessor(nil)
// Add a processor so that it sets EventName on log records.
eventNameProcessor := &EventNameProcessor{}
// The created processor can then be registered with
// the OpenTelemetry Logs SDK using the WithProcessor option.
_ = log.NewLoggerProvider(
// Order is important here. Set EventName before handing to the processor.
log.WithProcessor(eventNameProcessor),
log.WithProcessor(processor),
)
}
// EventNameProcessor is a [log.Processor] that sets the EventName
// on log records with an "otel.event.name" string attribute.
// It is useful for logging libraries that do not support
// setting the event name on log records,
// but do support attributes.
type EventNameProcessor struct{}
// Enabled returns true, indicating this Processor will process all records.
func (*EventNameProcessor) Enabled(context.Context, log.EnabledParameters) bool {
return true
}
// OnEmit sets the EventName on log records with an "otel.event.name" string
// attribute. The original attribute is not removed.
func (*EventNameProcessor) OnEmit(_ context.Context, record *log.Record) error {
record.WalkAttributes(func(kv attribute.KeyValue) bool {
if kv.Key == "otel.event.name" && kv.Value.Type() == attribute.STRING {
record.SetEventName(kv.Value.AsString())
}
return true
})
return nil
}
// Shutdown returns nil.
func (*EventNameProcessor) Shutdown(context.Context) error {
return nil
}
// ForceFlush returns nil.
func (*EventNameProcessor) ForceFlush(context.Context) error {
return nil
}
Output:
Example (Redact) ¶
Use a processor that redacts sensitive data from some attributes.
package main
import (
"context"
"strings"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/log"
)
func main() {
// Existing processor that emits telemetry.
var processor log.Processor = log.NewBatchProcessor(nil)
// Add a processor so that it redacts values from token attributes.
redactProcessor := &RedactTokensProcessor{}
// The created processor can then be registered with
// the OpenTelemetry Logs SDK using the WithProcessor option.
_ = log.NewLoggerProvider(
// Order is important here. Redact before handing to the processor.
log.WithProcessor(redactProcessor),
log.WithProcessor(processor),
)
}
// RedactTokensProcessor is a [log.Processor] decorator that redacts values
// from attributes containing "token" in the key.
type RedactTokensProcessor struct{}
// Enabled returns true, indicating this Processor will process all records.
func (*RedactTokensProcessor) Enabled(context.Context, log.EnabledParameters) bool {
return true
}
// OnEmit redacts values from attributes containing "token" in the key
// by replacing them with a "REDACTED" value.
func (*RedactTokensProcessor) OnEmit(_ context.Context, record *log.Record) error {
record.WalkAttributes(func(kv attribute.KeyValue) bool {
key := string(kv.Key)
if strings.Contains(strings.ToLower(key), "token") {
record.AddAttributes(attribute.String(key, "REDACTED"))
}
return true
})
return nil
}
// Shutdown returns nil.
func (*RedactTokensProcessor) Shutdown(context.Context) error {
return nil
}
// ForceFlush returns nil.
func (*RedactTokensProcessor) ForceFlush(context.Context) error {
return nil
}
Output:
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
Record is a log record emitted by the Logger. A log record with a non-empty event name is interpreted as an event record.
Do not create instances of Record on your own in production code. You can use go.opentelemetry.io/otel/sdk/log/logtest.RecordFactory for testing purposes.
func (*Record) AddAttributes ¶
AddAttributes adds attributes to the log record. Unless key duplication is enabled with WithAllowKeyDuplication, an attribute in attrs overwrites any attribute already added to r with the same key. Attributes with invalid keys are ignored.
func (*Record) AttributesLen ¶
AttributesLen returns the number of attributes in the log record.
func (*Record) Clone ¶
Clone returns a copy of the record with no shared state. The original record and the clone can both be modified without interfering with each other.
func (*Record) DroppedAttributes ¶
DroppedAttributes returns the number of attributes dropped due to limits being reached. Invalid attributes are ignored and not counted.
func (*Record) EventName ¶ added in v0.11.0
EventName returns the event name. A log record with a non-empty event name is interpreted as an event record.
func (*Record) InstrumentationScope ¶
func (r *Record) InstrumentationScope() instrumentation.Scope
InstrumentationScope returns the scope that the Logger was created with.
func (*Record) ObservedTimestamp ¶
ObservedTimestamp returns the time when the log record was observed.
func (*Record) SetAttributes ¶
SetAttributes sets (and overrides) attributes on the log record. Attributes with invalid keys are ignored.
func (*Record) SetEventName ¶ added in v0.11.0
SetEventName sets the event name. A log record with a non-empty event name is interpreted as an event record.
func (*Record) SetObservedTimestamp ¶
SetObservedTimestamp sets the time when the log record was observed.
func (*Record) SetSeverity ¶
SetSeverity sets the severity level of the log record.
func (*Record) SetSeverityText ¶
SetSeverityText sets the text of the severity (also known as the log level). This is the original string representation of the severity as it is known at the source.
func (*Record) SetTimestamp ¶
SetTimestamp sets the time when the log record occurred.
func (*Record) SetTraceFlags ¶
func (r *Record) SetTraceFlags(flags trace.TraceFlags)
SetTraceFlags sets the trace flags.
func (*Record) SetTraceID ¶
SetTraceID sets the trace ID.
func (*Record) SeverityText ¶
SeverityText returns the text of the severity (also known as the log level). This is the original string representation of the severity as it is known at the source.
func (*Record) TraceFlags ¶
func (r *Record) TraceFlags() trace.TraceFlags
TraceFlags returns the trace flags.
func (*Record) WalkAttributes ¶
WalkAttributes walks through all attributes held by the log record, calling f for each attribute.KeyValue in the Record. Iteration stops if f returns false.
type SimpleProcessor ¶
type SimpleProcessor struct {
// contains filtered or unexported fields
}
SimpleProcessor is a processor that synchronously exports log records.
Use NewSimpleProcessor to create a SimpleProcessor.
func NewSimpleProcessor ¶
func NewSimpleProcessor(exporter Exporter, _ ...SimpleProcessorOption) *SimpleProcessor
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 (*SimpleProcessor) Enabled ¶
func (*SimpleProcessor) Enabled(context.Context, EnabledParameters) bool
Enabled returns true, indicating this Processor will process all records.
func (*SimpleProcessor) ForceFlush ¶
func (s *SimpleProcessor) ForceFlush(ctx context.Context) error
ForceFlush flushes the exporter.
type SimpleProcessorOption ¶
type SimpleProcessorOption interface {
// contains filtered or unexported methods
}
SimpleProcessorOption applies a configuration to a SimpleProcessor.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package internal provides internal functionality for the sdk/log package.
|
Package internal provides internal functionality for the sdk/log package. |
|
attrnorm
Package attrnorm normalizes attribute values.
|
Package attrnorm normalizes attribute values. |
|
counter
Package counter provides a simple counter for generating unique IDs.
|
Package counter provides a simple counter for generating unique IDs. |
|
observ
Package observ provides observability instrumentation for the OTel Logs SDK.
|
Package observ provides observability instrumentation for the OTel Logs SDK. |
|
x
Package x documents experimental features for go.opentelemetry.io/otel/sdk/log.
|
Package x documents experimental features for go.opentelemetry.io/otel/sdk/log. |
|
logtest
module
|