Documentation ¶
Overview ¶
Package logs provides an implementation of the logging part of the OpenTelemetry API.
This package defines a log backend API. The API is not intended to be called by application developers directly. It is provided for logging library authors to build log appenders, which use this API to bridge between existing logging libraries and the OpenTelemetry log data model.
To participate in logging a LogRecord needs to be created for the operation being performed as part of a logging workflow. In its simplest form:
var logger logger.Logger func init() { logger = otel.Logger() } func operation(ctx context.Context) { logRecord := logger.NewLogRecord(..) logger.Emit(logRecord) }
A Logger is unique to the instrumentation and is used to create Logs. Instrumentation should be designed to accept a LoggerProvider from which it can create its own unique Logger. Alternatively, the registered global LoggerProvider from the github.com/hyperdxio/opentelemetry-logs-go package can be used as a default.
const ( name = "instrumentation/package/name" version = "0.1.0" ) type Instrumentation struct { logger logging.Logger } func NewInstrumentation(tp logging.LoggerProvider) *Instrumentation { if lp == nil { lp = otel.LoggerProvider() } return &Instrumentation{ logger: lp.Logger(name, logs.WithInstrumentationVersion(version)), } } func operation(ctx context.Context, inst *Instrumentation) { // ... }
Index ¶
- type LogRecord
- func (l LogRecord) Attributes() *[]attribute.KeyValue
- func (l LogRecord) Body() *string
- func (l LogRecord) InstrumentationScope() *instrumentation.Scope
- func (l LogRecord) ObservedTimestamp() time.Time
- func (l LogRecord) Resource() *resource.Resource
- func (l LogRecord) SeverityNumber() *SeverityNumber
- func (l LogRecord) SeverityText() *string
- func (l LogRecord) SpanId() *trace.SpanID
- func (l LogRecord) Timestamp() *time.Time
- func (l LogRecord) TraceFlags() *trace.TraceFlags
- func (l LogRecord) TraceId() *trace.TraceID
- type LogRecordConfig
- type Logger
- type LoggerConfig
- type LoggerOption
- type LoggerProvider
- type SeverityNumber
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LogRecord ¶
type LogRecord struct {
// contains filtered or unexported fields
}
LogRecord is an implementation of the OpenTelemetry Log API representing the individual component of a log. see https://opentelemetry.io/docs/specs/otel/logs/data-model/#log-and-event-record-definition
func NewLogRecord ¶
func NewLogRecord(config LogRecordConfig) LogRecord
NewLogRecord constructs a LogRecord using values from the provided LogRecordConfig.
func (LogRecord) Attributes ¶
func (LogRecord) InstrumentationScope ¶
func (l LogRecord) InstrumentationScope() *instrumentation.Scope
func (LogRecord) ObservedTimestamp ¶
func (LogRecord) SeverityNumber ¶
func (l LogRecord) SeverityNumber() *SeverityNumber
func (LogRecord) SeverityText ¶
func (LogRecord) TraceFlags ¶
func (l LogRecord) TraceFlags() *trace.TraceFlags
type LogRecordConfig ¶
type LogRecordConfig struct { Timestamp *time.Time ObservedTimestamp time.Time TraceId *trace.TraceID SpanId *trace.SpanID TraceFlags *trace.TraceFlags SeverityText *string SeverityNumber *SeverityNumber Body *string Resource *resource.Resource InstrumentationScope *instrumentation.Scope Attributes *[]attribute.KeyValue }
LogRecordConfig contains mutable fields usable for constructing an immutable LogRecord.
type Logger ¶
type Logger interface { // Emit emits a log record Emit(logRecord LogRecord) }
Logger is the creator of Logs
type LoggerConfig ¶
type LoggerConfig struct {
// contains filtered or unexported fields
}
LoggerConfig is a group of options for a Logger.
func NewLoggerConfig ¶
func NewLoggerConfig(options ...LoggerOption) LoggerConfig
NewLoggerConfig applies all the options to a returned LoggerConfig.
func (*LoggerConfig) InstrumentationAttributes ¶
func (t *LoggerConfig) InstrumentationAttributes() attribute.Set
InstrumentationAttributes returns the attributes associated with the library providing instrumentation.
func (*LoggerConfig) InstrumentationVersion ¶
func (t *LoggerConfig) InstrumentationVersion() string
InstrumentationVersion returns the version of the library providing instrumentation.
func (*LoggerConfig) SchemaURL ¶
func (t *LoggerConfig) SchemaURL() string
SchemaURL returns the Schema URL of the telemetry emitted by the Logger.
type LoggerOption ¶
type LoggerOption interface {
// contains filtered or unexported methods
}
LoggerOption applies an option to a LoggerConfig.
func WithInstrumentationAttributes ¶
func WithInstrumentationAttributes(attr ...attribute.KeyValue) LoggerOption
WithInstrumentationAttributes sets the instrumentation attributes.
The passed attributes will be de-duplicated.
func WithInstrumentationVersion ¶
func WithInstrumentationVersion(version string) LoggerOption
WithInstrumentationVersion sets the instrumentation version.
func WithSchemaURL ¶
func WithSchemaURL(schemaURL string) LoggerOption
WithSchemaURL sets the schema URL for the Logger.
type LoggerProvider ¶
type LoggerProvider interface { // Logger returns a unique Logger scoped to be used by instrumentation code // to log computational workflows. The scope and identity of that // instrumentation code is uniquely defined by the name and options passed. // // The passed name needs to uniquely identify instrumentation code. // Therefore, it is recommended that name is the Go package name of the // library providing instrumentation (note: not the code being // instrumented). Instrumentation libraries can have multiple versions, // therefore, the WithInstrumentationVersion option should be used to // distinguish these different codebases. Additionally, instrumentation // libraries may sometimes use traces to communicate different domains of // workflow data (i.e. using logs to communicate workflow events only). If // this is the case, the WithScopeAttributes option should be used to // uniquely identify Loggers that handle the different domains of workflow // data. // // If the same name and options are passed multiple times, the same Logger // will be returned (it is up to the implementation if this will be the // same underlying instance of that Logger or not). It is not necessary to // call this multiple times with the same name and options to get an // up-to-date Logger. All implementations will ensure any LoggerProvider // configuration changes are propagated to all provided Loggers. // // If name is empty, then an implementation defined default name will be // used instead. // // This method is safe to call concurrently. Logger(name string, options ...LoggerOption) Logger }
LoggerProvider provides Loggers that are used by instrumentation code to log computational workflows.
A LoggerProvider is the collection destination of logs provides, it represents a unique telemetry collection pipeline. How that pipeline is defined, meaning how those Logs are collected, processed, and where they are exported, depends on its implementation. Instrumentation authors do not need to define this implementation, rather just use the provided Loggers to instrument code.
func NewNoopLoggerProvider ¶
func NewNoopLoggerProvider() LoggerProvider
NewNoopLoggerProvider returns an implementation of LoggerProvider that performs no operations. The Logger created from the returned LoggerProvider also perform no operations.
type SeverityNumber ¶
type SeverityNumber int32
SeverityNumber Possible values for LogRecord.SeverityNumber.
const ( // UNSPECIFIED is the default SeverityNumber, it MUST NOT be used. UNSPECIFIED SeverityNumber = 0 TRACE SeverityNumber = 1 TRACE2 SeverityNumber = 2 TRACE3 SeverityNumber = 3 TRACE4 SeverityNumber = 4 DEBUG SeverityNumber = 5 DEBUG2 SeverityNumber = 6 DEBUG3 SeverityNumber = 7 DEBUG4 SeverityNumber = 8 INFO SeverityNumber = 9 INFO2 SeverityNumber = 10 INFO3 SeverityNumber = 11 INFO4 SeverityNumber = 12 WARN SeverityNumber = 13 WARN2 SeverityNumber = 14 WARN3 SeverityNumber = 15 WARN4 SeverityNumber = 16 ERROR SeverityNumber = 17 ERROR2 SeverityNumber = 18 ERROR3 SeverityNumber = 19 ERROR4 SeverityNumber = 20 FATAL SeverityNumber = 21 FATAL2 SeverityNumber = 22 FATAL3 SeverityNumber = 23 FATAL4 SeverityNumber = 24 )